aMule Forum

English => Feature requests => Topic started by: FreeToGo on September 20, 2008, 05:13:20 PM

Title: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: FreeToGo on September 20, 2008, 05:13:20 PM
It takes me ages to finally see that amule works with upnp. But unlike other applications, amule doesn't support
random port. It is needed because we never know which port is still available.

Is there any chances that this little feature(random TCP/UDP port) could be added? 
Title: [Solved] Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: FreeToGo on September 22, 2008, 01:53:10 PM
Below is the patch needed to trigger amule to  assign random port whenever upnp are enabled. I need this feature because my router always lock  those ports that amule used previously.  I don't know any clever way to release those port so that amule could reuse it.

Code: [Select]
jc@ubuntu:~/Desktop/temp/amule/amule-cvs$ diff -u src/amule.cpp.old src/amule.cpp
--- src/amule.cpp.old 2008-09-15 04:22:55.000000000 +0800
+++ src/amule.cpp 2008-09-22 19:43:45.000000000 +0800
@@ -871,7 +871,19 @@
 {
  bool ok = true;
  static bool firstTime = true;
-
+#ifdef ENABLE_UPNP
+ if (thePrefs::GetUPnPEnabled()) {
+ uint16 randport = 0;
+ while ( randport < 1024 ) {
+ randport = (uint16)rand();
+ }
+ uint16 udpport = randport +5;
+ uint16 ecport = randport + 6;
+ thePrefs::SetUDPPort( udpport );
+ thePrefs::SetECPort( ecport );
+ thePrefs::SetPort( randport );
+ }
+#endif
  if (!firstTime) {
  // TODO: Destroy previously created sockets
  }
jc@ubuntu:~/Desktop/temp/amule/amule-cvs$
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: Kry on September 22, 2008, 03:06:43 PM
Randomizing ports is bad, very bad. It means every time you restart your client people won't be able to contacts you anymore if they have you in their queues as a source, and also that you lost your places in other people's queues even if you restarted with enough time to be kept in them (less than a statistic median of 10 minutes). It also mean you will be published to the servers as a different user, and you can even be marked as a hash stealer by some zealous leecher protection features on some mods.
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: FreeToGo on September 22, 2008, 07:25:33 PM
Randomizing ports is bad,

Thank u for your information.  How about to implement a try  and  catch mechanism so that
if old port cannot be open, amule will try connect again using a random port.



 
 
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: wuischke on September 22, 2008, 07:57:44 PM
Shouldn't we instead try to focus on the cause of the problem? Could you explain better how your router locks the ports?
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: FreeToGo on September 23, 2008, 05:09:55 AM
Here is my scenario.

 I am currently connecting my hp notebook to d-link router through wifi and upnp.  Very often, due to the act of Gods, the wireless connection will be disconnected and then reconnected again automatically every two hours or so. Most of the applications will survive and be back to normal in no time except amule. Amule will either become disconnected or reconnected with a low-id. If I restart amule, it will remain connected with a low-id.   I must manually change the TCP and UDP port numbers before amule could  get a high id again.

 
 
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: wuischke on September 23, 2008, 10:20:56 AM
OK, so we have two problems:

1. Your wireless connection drops and is not reconnected immediately.
2. aMule has a problem to open the ports using UPnP when there's already a lease on the ports.

Helping you to resolve your wireless problems is out of scope here (Have you asked at your distribution's forums?), but we can see what we can do about the second problem. I see the following options:


I'll speak to phoenix to see what he thinks about this, his knowledge about this topic is better than mine.
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: phoenix on September 26, 2008, 02:45:24 AM
Hi folks,

Sorry for beeing away, I am having some personal problems, but I will try to address this issue.

FreeToGo,

I need you to enable UPnP debug logging in aMule preferences, then send me a log big enough as to contain the problem.

Do you have an idea of what happens to the state of your router when you connect/disconnect? Is it loosing the port forward setting? This information would help.

One other thing, when the connection comes back, do you get the same IP as before?

Cheers!
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: skolnick on September 26, 2008, 03:42:11 AM
I think the problem is that the router is rebooting, then when it comes up, the port forwarding via UPnP has been lost, therefore it gets lowID.

Regards.
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: phoenix on September 26, 2008, 02:04:46 PM
If that is the case, there's not much we can do. It is not reasonable to keep recreating the translations every time because one router is misbehaving.

What could be done, is to make aMule much more UPnP smart and make it check whether the port forward rules are still on the router every, say, 1 hour. But that might be tricky, and we might run into compatibility problems among routers.

Anyway, lets not get ahead of ourselves, lets see the logs first.
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: Stu Redman on September 26, 2008, 04:46:40 PM
Even without UPnP aMule doesn't react sane if the Internet connection breaks down for a while. Just caught it yesterday sitting there dumb and disconnected even though the router was working fine again and automatic reconnect was enabled.
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: Kry on September 26, 2008, 09:11:50 PM
It has a retry limit. If you wamt it to retry more, add more retries.
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: FreeToGo on October 01, 2008, 01:43:08 PM
Hi ,

Here is the log.


Hi folks,

Sorry for beeing away, I am having some personal problems, but I will try to address this issue.

FreeToGo,

I need you to enable UPnP debug logging in aMule preferences, then send me a log big enough as to contain the problem.

Do you have an idea of what happens to the state of your router when you connect/disconnect? Is it loosing the port forward setting? This information would help.

One other thing, when the connection comes back, do you get the same IP as before?

Cheers!
Title: Re: Shall amule support "random TCP/UDP port" so as to work with upnp?
Post by: phoenix on October 01, 2008, 05:00:50 PM
Is this a log from one single session? Just to make sure, it seems heavily edited.