Display External IP sooner in log

Discuss suggestions and ideas for the forums, site, software.
MrGreg

Display External IP sooner in log

Post by MrGreg »

Hi Sledge,

I have been fighting an ongoing issue with my Socks5 proxy provider. The issue occurs when using a host name instead of a hard coded IP address. Sometimes the connection is actively refused by the proxy server. In this case I have no idea what IP qB is trying to connect to. This is in no way a problem with qB. However it sure would be nice to display the External IP in the qB log when a failure occurs. I have noticed that the External IP is not displayed until DHT kicks in or a torrent is added. I would also like to see the access denied message removed if possible when I do successfully connect. I have not looked at the code but I should think that both of these changes could be easily implemented. BTW I am using the 3.2.0 alpha build that you made splitting anonymous/force proxy. Thanks again for doing that build. I am including 2 screen shots. The first one is a failed connect and the second is a successful connect. Thanks for your support...
Attachments
Success.jpg
Failure.jpg
Last edited by MrGreg on Mon Sep 22, 2014 11:13 am, edited 1 time in total.
sledgehammer_999
Administrator
Administrator
Posts: 2443
Joined: Sun Jan 23, 2011 1:17 pm

Re: Display External IP sooner in log

Post by sledgehammer_999 »

I cannot query for the external ip at will.
Libtorrent informs me via a message when it receives that from a peer or tracker.
The log is a log, you shouldn't remove entries from it.
MrGreg

Re: Display External IP sooner in log

Post by MrGreg »

OK but I would think that libtorrent should be including the IP address in the error message. In both the cases of success or failure the interface is 0.0.0.0. Should this not be the IP address that failed like is shown in the success lines for listening UDP and TCP?
ciaobaby

Re: Display External IP sooner in log

Post by ciaobaby »

libtorrent/qbittorrent 'talks' to your local IP as issued by your router (192.168.n.n). The OS networking system and router OS handles everything beyond that as it routes packets that are for destinations that are outside of the local network scope.
ANY device on your local machine can ONLY 'know' what the second hop (your external IP) is when return packages arrive back and can be read.

This situation changes ONLY IF you are DIRECTLY connected to the Internet via a modem that is plugged directly into your machine.
MrGreg

Re: Display External IP sooner in log

Post by MrGreg »

ciaobaby, Thanks for your explanation. It makes perfect sense. In the case of using a proxy with a host name, it must be resolved by DNS. Do you know if libtorrent resolves the host name to an IP address before trying to connect to the proxy? If so then it should be able to be reported in the qB logs. If I hard code an IP address in my qB Proxy settings, then it is certainly known by qB and libtorrent. In this case the IP address that fails to connect is still not reported in the log. Thanks for your help in the matter...
sledgehammer_999
Administrator
Administrator
Posts: 2443
Joined: Sun Jan 23, 2011 1:17 pm

Re: Display External IP sooner in log

Post by sledgehammer_999 »

[quote="MrGreg"]
ciaobaby, Thanks for your explanation. It makes perfect sense. In the case of using a proxy with a host name, it must be resolved by DNS. Do you know if libtorrent resolves the host name to an IP address before trying to connect to the proxy? If so then it should be able to be reported in the qB logs. If I hard code an IP address in my qB Proxy settings, then it is certainly known by qB and libtorrent. In this case the IP address that fails to connect is still not reported in the log. Thanks for your help in the matter...
[/quote]

Is this relevant to you? -> https://code.google.com/p/libtorrent/is ... ail?id=613
MrGreg

Re: Display External IP sooner in log

Post by MrGreg »

I have not seen this happen using my provider but this makes sense. When researching how to setup the proxy for my provider in their forum, a user asked if there was a way to force all torrent jobs to use the same IP. They were told yes if you hard code the IP address in the proxy settings. The user was using uTorrent. This infers that every torrent job that is added to the client, can potentially use a different IP address when using a proxy domain name. So the uTorrent  code must re-resolve the proxy for each torrent that is added. These proxy providers can have hundreds of IP's associated with their domain. I have no clue what libtorrent does here but I suspect your assumption in Issue 613 is correct. With this being said, I am still not sure if libtorrent resolves the proxy to an IP on initial connection or if it uses the domain name and waits on a return packet to get the external IP as ciaobaby suggests.

***** UPDATE ***** Sledge I have reproduced this problem. Please check my post http://qbforums.shiki.hu/index.php/topic,2561.0.html
Last edited by MrGreg on Tue Sep 23, 2014 7:33 am, edited 1 time in total.
ciaobaby

Re: Display External IP sooner in log

Post by ciaobaby »

If I hard code an IP address in my qB Proxy settings, then it is certainly known by qB and libtorrent
You are misunderstanding how proxy servers work,  it does not 'bypass' your network interface or your router as a VPN would, a proxy operates as an intermediary between your external IP and the remote host, in effect the proxy inbound IP is  "injected" into the routing plan as the 'third hop' on the way to the destination, so libtorrent is still "talking" to your local network, just with an extra bit of information added in to the request.
MrGreg

Re: Display External IP sooner in log

Post by MrGreg »

ciaobaby, Thanks again for your explanation. However I do understand the difference between a VPN and proxy server. libtorrent must send an authentication packet to the proxy server with a username and password. So how is the packet routed? Does libtorrent resolve the host name/domain name to an IP address before sending the authentication packet or is it resolved when a return packet is received as you suggest? Thanks...
AsaRossoff

Re: Display External IP sooner in log

Post by AsaRossoff »

[quote="MrGreg"]
ciaobaby, Thanks again for your explanation. However I do understand the difference between a VPN and proxy server. libtorrent must send an authentication packet to the proxy server with a username and password. So how is the packet routed? Does libtorrent resolve the host name/domain name to an IP address before sending the authentication packet or is it resolved when a return packet is received as you suggest? Thanks...
[/quote]

Hi MrGreg!
The short answer to "Does libtorrent resolve the host name/domain name to an IP address before sending" is YES.  It is impossible to contact the proxy server otherwise.

I'll give some general info -- I don't know what the trouble your having is, I don't use a proxy, and I'm not a developer for either libtorrent or qBittorent.

See if the following explanations help in any way.  Sorry if you already know all this:
External IP: Your own IP address on the internet.

If you have a router, your "external IP" is usually actually the router's IP on the internet side.  So, your computer will not know what that is unless it is told by a server on the internet.  This is like a phone number to reach your network.  When you establish a connection to another server (e.g. a proxy server) your computer only needs to know the proxy server's IP address, not it's own internet IP address.  Your computer sends packets of data to the proxy server from some port on your your computer (usually randomly chosen) and send it to a specified port on the proxy server (where connections are expected).  The proxy server should respond by sending data back to you using your internet address and your own originating port; if you have a router, your router will have remembered your port and will know to direct that data to your specific computer on your private network.  I skipped a few details and variations (e.h. the router will often send from a different port than your computer did, but this is generally inconsequential).  I hope that gives you the idea of how the two computer find each other.

The proxy server knows your external IP (i.e. internet IP) already, because you contacted it first, and every packet of data transmitted includes your internet IP/external IP (added by your router when a router is in use).

Bittorrent needs to know it's external IP to report to trackers who will redistribute to other peers, or to advertise it over DHT or peer exchange, so that other peers will be able to know how to initiate a connection to you without you contacting them first.  (Although in practice, at least many trackers ignore what they are told and use the IP they see as the "return address" in the TCP/IP or UDP packets sent to them when you "announce" to them your presence).


In short, I would not expect knowledge of external IP to be related to proxy issues.

In order to communicate with a proxy server, your computer should:
(1) Do a DNS request to discover one of the IP addresses associated with the domain name for the proxy server (if you specify it by name instead of IP).
(2) Connect to that IP via your router (assuming a router).
(3) The router will pass along your own internet IP and make sure return traffic reaches your computer on the private network.
(4) Continue to use that connection unless it is interrupted by the proxy server or network issue.
(5) If it was interrupted, I would expect it to periodically try to initiate a new connection, going back to step 1.
Last edited by AsaRossoff on Tue Sep 23, 2014 6:21 am, edited 1 time in total.
MrGreg

Re: Display External IP sooner in log

Post by MrGreg »

Hi AsaRossoff, Thanks for your explanation! I suspected that was the case. The domain name/host name cannot be used to contact my proxy server. libtorrent must first resolve the domain name/host name to an IP via DNS before initial contact with the proxy server for authentication.

As for my problem, it unrelated to qB/libtorrent. My proxy provider "Private Internet Access" is having issues with some of their IP addresses. The IP's are up and can be pinged but the proxy server refuses the connection. You will see the problem in failure.jpg in my first post. To make matters worse, IP's that were working stop working and ones that were not working start working again. This issue has been going on for 3 or 4 months without resolve. Their admin team is either not capable of solving the problem or does not care to. I am so disappointed in this service.

The whole point of this post was to try and get the External IP of my proxy server displayed in the log when this condition occurs. I have now determined with help from Sledge, ciaobaby and yourself that libtorrent must know the External IP upon initial contact. The question now is why is it not being reported in the log. I suspect that libtorrent is not passing the IP back to qB.
Last edited by MrGreg on Tue Sep 23, 2014 7:04 am, edited 1 time in total.
AsaRossoff

Re: Display External IP sooner in log

Post by AsaRossoff »

MrGreg, it looks like you're on Windows.  It is most likely that libtorrent allows Windows' networking layer to perform the DNS resolution.
Windows caches DNS results for a while, and upstream DNS servers may also.

Therefore, you should be able to determine the current IP in use by opening a command prompt and entering:
tracert my.proxy.server.com
Then hit Ctrl-C or Ctrl-Break to terminate the trace.  All you need is the first line which will indicate the IP Address your computer is using for that domain name at present.

Alternatively, type:
    c:\windows\system32\ipconfig /displaydns
to list all cached DNS entries.

You can force your computer to reset it's DNS cache at the command prompt, too; type:
    c:\windows\system32\ipconfig /flushdns

Then you may be able to get a new  IP by any attempt to access the proxy server's domain name again.  However, libtorrent will still likely be using the last IP address it looked up.  You may have to restart qBittorrent or possibly get away with modifying the proxy settings to reapply them (dunno about the latter).


EDIT:
P.S.
You can use the "dig" utiltity to access DNS records more directly and find out all the IP addresses available for your proxy server.
Windows does not come with dig. so you can use an online web service to do the lookup, e.g. http://www.onlinedig.com/go-dig/
Last edited by AsaRossoff on Tue Sep 23, 2014 7:44 am, edited 1 time in total.
MrGreg

Re: Display External IP sooner in log

Post by MrGreg »

Hi AsaRossoff,

Thanks for the tips. Tracert does seem to do the job. ipconfig /displaydns does not as it gives many IP addresses associated with my proxy server. Thanks for the ipconfig /flushdns command as well. I did not know that was possible and could come in handy. Thanks for the dig link. I have been using nslookup which does the same thing.

So back to the main question at hand. I think you are correct in saying libtorrent uses the Windows networking layer to perform the DNS resolution. So are we still in agreement that libtorrent knows the External IP of the proxy server before an authentication packet is sent? If so then all I am saying is that it should be reported in the error message that occurs when the server actively refuses the connection. Furthermore the External IP should be reported in all error messages pertaining to the proxy server. Do you agree? Time for bed it is 4:10 AM here...
ciaobaby

Re: Display External IP sooner in log

Post by ciaobaby »

Bittorrent needs to know it's external IP to report to trackers who will redistribute to other peers, or to advertise it over DHT or peer exchange,
No it does not, all it needs to 'know' is how to 'talk' to the operating system networking components
If so then all I am saying is that it should be reported in the error message that occurs when the server actively refuses the connection
Libtorrent does NOT control the error messages, if the remote end does NOT include the IP or hostname in the status message then libtorrent/qBittorrent have NO mechanism for identifying the IP that created the error, simply because the packets that are carrying the status message came from 192.168.n.n
MrGreg

Re: Display External IP sooner in log

Post by MrGreg »

ciaobaby, I see what you are saying in than libtorrent does not control the return error message. However the return must be coming back from a specific IP address or the packet could not be routed back to libtorrent. How can the return packets carrying the status message be coming from my 192.168.n.n address as you state? I will fire up wireshark when I return home from work to confirm what you are saying.
Post Reply