[PATCH] Bug in Preferences when checking if port is open

Ask for help and report issues with the Mac OS X version of Transmission
Post Reply
bodgit
Posts: 2
Joined: Sun Nov 07, 2010 2:45 pm

[PATCH] Bug in Preferences when checking if port is open

Post by bodgit »

Hi,

I just used Transmission to grab a torrent and I noticed that in Preferences the default port of 51413 was marked as closed. I knew Transmission had support for NAT-PMP and as I wrote the NAT-PMP implementation running on my firewall I'm fairly familiar with the protocol itself so I went poking about to see what might be wrong.

Transmission is successfully setting up a port forwarding rule, but the public port being assigned isn't the same as the private port (this is partly due to my NAT-PMP implementation). I'm assuming Transmission is correctly using the actual assigned public port (the torrent I was grabbing was not "popular" enough to have anyone connect to me) but the Preferences pane is always submitting the private port to the http://portcheck.transmissionbt.com/ service rather than use the public port.

The following crude patch seems to fix things for me (I can't seem to attach the patch as a .diff, .patch or .txt attachment), however I don't think its correct in the case of the Transmission client not being behind a NAT gateway but hopefully it illustrates the problem and someone more clued up with the source can apply a more correct fix:

Index: libtransmission/transmission.h
===================================================================
--- libtransmission/transmission.h (revision 11389)
+++ libtransmission/transmission.h (working copy)
@@ -579,6 +579,8 @@

tr_bool tr_sessionGetPeerPortRandomOnStart( tr_session * session );

+tr_port tr_sessionGetPublicPort( const tr_session * session );
+
typedef enum
{
TR_PORT_ERROR,
Index: libtransmission/session.c
===================================================================
--- libtransmission/session.c (revision 11389)
+++ libtransmission/session.c (working copy)
@@ -1035,6 +1035,12 @@
return tr_sharedTraversalStatus( session->shared );
}

+tr_port
+tr_sessionGetPublicPort( const tr_session * session )
+{
+ return tr_isSession( session ) ? session->public_peer_port : 0;
+}
+
/***
****
***/
Index: macosx/PrefsController.m
===================================================================
--- macosx/PrefsController.m (revision 11389)
+++ macosx/PrefsController.m (working copy)
@@ -359,7 +359,7 @@
- (void) updatePortStatus
{
const tr_port_forwarding fwd = tr_sessionGetPortForwarding(fHandle);
- const int port = tr_sessionGetPeerPort(fHandle);
+ const int port = tr_sessionGetPublicPort(fHandle);
BOOL natStatusChanged = (fNatStatus != fwd);
BOOL peerPortChanged = (fPeerPort != port);

Cheers

Matt
Robby
Posts: 54
Joined: Sun May 06, 2007 9:16 pm

Re: [PATCH] Bug in Preferences when checking if port is open

Post by Robby »

Are you going to post this patch on Transmission's Trac as well? :)
Post Reply