Angel Leon
2016-05-31 00:48:05 UTC
I'm trying to add the new `x.pe=` parameters to magnet uris, in there I'd
like to put all the interfaces on which my libtorrent client might be
listening on (may them be IPv4 or IPv6)
In session I see the `listen_port()` method, documented as follows:
*// ``listen_port()`` returns the port we ended up listening on. If the*
*// port specified in settings_pack::listen_interfaces failed, libtorrent*
*// will try to bind to the next port, and so on. If it fails*
*// settings_pack::max_retry_port_bind times, it will bind to port 0*
*// (meaning the OS picks the port). *
*// The only way to know which port it ended up binding to is to ask for it
by calling ``listen_port()``*.
However, when I look at portmap alerts, I see that it attempts to port map
on 3 different interfaces (2 are IPv6, one is IPv4, one of the IPv6 fails,
this is on android)
but at the end, what seems to be a successful portmap response, has a port
number different than the one being returned by session::listen_port.
So if I use the port from session, I'm probably not sending the right port
on the magnet, it perhaps might work if I send the magnet to a peer on the
local network, but someone outside will never be able to take advantage of
those x.pe= parameters to try and establish a connection to my mapped port,
because I have the port of the wrong interface.
So my question is the following, is there a way to find out which are my
listening tcp::endpoint's/udp::endpoint's once the session has started?
I wish I had something like this:
void session::get_tcp_endpoints(std::vector<tcp::endpoint>& endpoints);
void session::get_udp_endpoints(std::vector<udp::endpoint>& endpoints);
and then I could iterate through those and find which ports they're using,
or does that not make much sense in the way sockets are created?
or perhaps endpoints are different for each torrent handle and I shouldn't
be looking at session?
like to put all the interfaces on which my libtorrent client might be
listening on (may them be IPv4 or IPv6)
In session I see the `listen_port()` method, documented as follows:
*// ``listen_port()`` returns the port we ended up listening on. If the*
*// port specified in settings_pack::listen_interfaces failed, libtorrent*
*// will try to bind to the next port, and so on. If it fails*
*// settings_pack::max_retry_port_bind times, it will bind to port 0*
*// (meaning the OS picks the port). *
*// The only way to know which port it ended up binding to is to ask for it
by calling ``listen_port()``*.
However, when I look at portmap alerts, I see that it attempts to port map
on 3 different interfaces (2 are IPv6, one is IPv4, one of the IPv6 fails,
this is on android)
but at the end, what seems to be a successful portmap response, has a port
number different than the one being returned by session::listen_port.
So if I use the port from session, I'm probably not sending the right port
on the magnet, it perhaps might work if I send the magnet to a peer on the
local network, but someone outside will never be able to take advantage of
those x.pe= parameters to try and establish a connection to my mapped port,
because I have the port of the wrong interface.
So my question is the following, is there a way to find out which are my
listening tcp::endpoint's/udp::endpoint's once the session has started?
I wish I had something like this:
void session::get_tcp_endpoints(std::vector<tcp::endpoint>& endpoints);
void session::get_udp_endpoints(std::vector<udp::endpoint>& endpoints);
and then I could iterate through those and find which ports they're using,
or does that not make much sense in the way sockets are created?
or perhaps endpoints are different for each torrent handle and I shouldn't
be looking at session?