y500 / libtorrent

Automatically exported from code.google.com/p/libtorrent
0 stars 0 forks source link

Gateway is not updated when listening on a given network interface #244

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
It is possible to listen on a particular network interface using 
session::listen_on() method. However, this does not change the gateway that 
libtorrent is using and I could not find any API to change the gateway.

For example, I have the following setup with
qbittorrent locked to the wlan0 interface:

    $ route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.3.0     0.0.0.0         255.255.255.0   U     2      0        0 wlan0
    192.168.2.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
    169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
    0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
    0.0.0.0         192.168.3.1     0.0.0.0         UG    0      0        0 wlan0

One would think since libtorrent is limited to the wlan0 interface, it
would also use 192.168.3.1 as its default gateway. It does not, and
still tries to connect on 192.168.2.1. This means that with the above
routing table, libtorrent actually stalls all torrent activity.
Deleting the eth0 default gateway causes all internet traffic to go
through the wlan0 interface, including libtorrent.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
v0.15.7

Please provide any additional information below.

Original issue reported on code.google.com by dch...@gmail.com on 21 Sep 2011 at 4:01

GoogleCodeExporter commented 8 years ago
What do you mean by "libtorrent stalls all torrent activity"? does libtorrent 
freeze somehow?

I wonder if you expect your OS to work in a way that it typically doesn't. 
Binding a socket to a specific interface, doesn't affect the routing of 
outbound packets from that socket. The first stop in routing is the local 
routing table . Keep in mind that an interface isn't necessarily 
point-to-point, which means there's no one given default route per interface. 
As you can see in your example, the wlan0 interface doesn't have a gateway.

What operating systems do is that for any packet destined to any address 
outside of the IP ranges in your routing table, they are sent to the default 
route. i.e. in your case, any packet destined for any other address than: 
192.168.0.0-192.168.255.255, the packet is going out on the default route. If 
you want wlan0 to be used for "internet" traffic, you have to make it the 
default route.

as far as I know, all operating systems work this way. I've heard rumors that 
there are patches floating around for BSD that allows multiple routing tables 
that would be able to do what I think you want to do.

Original comment by arvid.no...@gmail.com on 21 Sep 2011 at 7:16