Hacking opentracker to run on your home server

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.

Updated audiostreamer-meta project

I’ve updated the audiostream-meta project hosted on Google Code to include all the updates I’ve made to the original AudioStreamer example from Matt Gallagher. In addition to parsing audio stream metadata the latest code will play AAC and AAC+ V1 (thanks to Brian Stormont) streams. The stream bitrate is also detected and displayed, along with the metadata, on the sample view.

audiostreamer-meta

Stream.ly Radio 1.5

The next version of Streamly Radio has been submitted to Apple for review. I’m excited about this release. I feel like this next version really cleans up the interface and adds some great features. You’ll now be able to search the radio directory and Live365 members can enter their username & password in the Settings app so they can play even more Live365 stations. The Live365 login feature came about from a four year old [!] blog post by a guy named Jim Russell. Thanks Jim!

I’ve removed the Twitter/Song.ly integration from this new release. That feature has always felt half-baked to me anyway. It’s easy to get excited about integrating everything (Twitter, Facebook, etc., etc.) into an iPhone app, but Stream.ly is about streaming radio, so that’s where I want to focus future development.

Background iPhone streaming radio with Safari

Since the iPhone only allows one program to be running at a time users of streaming radio applications can’t read their email or look at Twitter while listening to music. The new iPhone OS 3.0 has added a feature that helps make this possible, although it’s not perfect.

If you open a compatible streaming radio link in Safari on the iPhone it will open a QuickTime player that will play the stream. Since Safari is allowed to run in the background, you can press the home button and start up other applications while the stream is still playing in Safari. The downside is that you can’t do anything else in Safari while the stream is playing.

Try it. Click on the Indie 103.1 playlist URL or the Houndstooth Radio stream URL from your iPhone.

I’ll add a feature to Stream.ly in the next update to do this automatically from the application. I’ll also update the Stream.ly website so you can browse the station directory from Safari on the phone and listen to a station without needing the application itself. The application adds a lot of nice features though. :)

UPDATE: It’s still in a “beta” stage, but you can now browse around the Stream.ly Radio web directory and play stations in Safari from this URL. iPhone only for now.