opentracker is probably the most famous BitTorrent tracker around. There are several public tackers that anyone can use (PublicBitTorrent, OpenBitTorrent) but you may want to run a tracker yourself. If you’re computer is on a home network behind a NAT router this can cause a problem if you want to allow your local machines share torrents with other users external to your private network.
When a local BitTorrent client connects to your local opentracker server the ip address seen by the tracker will be the private ip address of your router like 10.1.1.1 or 192.168.1.1. When other external clients connect to the tracker that local ip address won’t do them any good. Those external clients need to know your public ip address.
We can modify opentracker to store your public ip address whenever it detects your private ip address. Start by adding two new configuration values to your opentracker.conf file.
tracker.private_ip 192.168.1.1 tracker.public_ip 35.8.10.15
Now edit opentracker.c and add global definitions for the public and private ip address.
/* Globals */ time_t g_now_seconds; char * g_redirecturl; char * g_publicip; char * g_privateip; // other code not shown...
Next edit opentracker.c and look for the parse_configfile function. Add the conditions to read in the new private_ip and public_ip values.
/* Scan for commands */
if(!byte_diff(p,15,"tracker.rootdir" ) && isspace(p[15])) {
set_config_option( &g_serverdir, p+16 );
} else if(!byte_diff(p,17,"tracker.public_ip" ) && isspace(p[17])) {
set_config_option( &g_publicip, p+18 );
} else if(!byte_diff(p,18,"tracker.private_ip" ) && isspace(p[18])) {
set_config_option( &g_privateip, p+19 );
}
// other code not shown...
Now edit ot_http.c and add an extern reference to the public and private ip variables.
#define OT_MAXMULTISCRAPE_COUNT 64 extern char *g_redirecturl; extern char *g_publicip; extern char *g_privateip; // other code now shown...
Next edit ot_http.c and look for the http_handle_announce function. This is where we’ll add the code to look for the private ip address and replace it with the public one.
ws->peer_id = NULL;
ws->hash = NULL;
OT_SETIP( &ws->peer, cookie->ip );
// Check if this is a local peer
ot_ip6 tmpprivateip;
scan_ip6( g_privateip, tmpprivateip );
if( memcmp( tmpprivateip, cookie->ip, sizeof(ot_ip6) ) == 0 )
{
ot_ip6 tmppublicip;
scan_ip6( g_publicip, tmppublicip );
char _debug[512];
int off = snprintf( _debug, sizeof(_debug), "Found private ip, setting public ip:" );
off += fmt_ip6c( _debug+off, tmppublicip );
off += snprintf( _debug+off, sizeof(_debug)-off, "\n" );
write( 2, _debug, off );
// Override the local ip address
OT_SETIP( &ws->peer, tmppublicip );
}
// other code not shown...
Compile opentracker normally and you should be able to see the debug message when a local client connects to your tracker. Warning: This modification works for me (on my machine). It has not been throughly tested.



