forked from premiere/premiere-libtorrent
make upnp lease duration configurable on the fly
This commit is contained in:
parent
a9968916ca
commit
c537f6277f
|
@ -1,3 +1,4 @@
|
|||
* allow UPnP lease duration to be changed after device discovery
|
||||
* fix IPv6 address change detection on Windows
|
||||
|
||||
1.2.6 released
|
||||
|
|
|
@ -212,6 +212,8 @@ private:
|
|||
void next(rootdevice& d, port_mapping_t i);
|
||||
void update_map(rootdevice& d, port_mapping_t i);
|
||||
|
||||
int lease_duration(rootdevice const& d) const;
|
||||
|
||||
void connect(rootdevice& d);
|
||||
|
||||
void on_upnp_xml(error_code const& e
|
||||
|
@ -288,8 +290,8 @@ private:
|
|||
std::string path;
|
||||
address external_ip;
|
||||
|
||||
// default lease duration for a port map.
|
||||
int lease_duration = 3600;
|
||||
// set to false if the router doesn't support lease durations
|
||||
bool use_lease_duration = true;
|
||||
|
||||
// true if the device supports specifying a
|
||||
// specific external port, false if it doesn't
|
||||
|
|
19
src/upnp.cpp
19
src/upnp.cpp
|
@ -576,7 +576,6 @@ void upnp::on_reply(udp::socket& s, error_code const& ec)
|
|||
|
||||
rootdevice d;
|
||||
d.url = url;
|
||||
d.lease_duration = m_settings.get_int(settings_pack::upnp_lease_duration);
|
||||
|
||||
auto i = m_devices.find(d);
|
||||
|
||||
|
@ -724,6 +723,13 @@ void upnp::post(upnp::rootdevice const& d, char const* soap
|
|||
#endif
|
||||
}
|
||||
|
||||
int upnp::lease_duration(rootdevice const& d) const
|
||||
{
|
||||
return d.use_lease_duration
|
||||
? m_settings.get_int(settings_pack::upnp_lease_duration)
|
||||
: 0;
|
||||
}
|
||||
|
||||
void upnp::create_port_mapping(http_connection& c, rootdevice& d
|
||||
, port_mapping_t const i)
|
||||
{
|
||||
|
@ -765,7 +771,7 @@ void upnp::create_port_mapping(http_connection& c, rootdevice& d
|
|||
, local_endpoint.c_str()
|
||||
, m_settings.get_bool(settings_pack::anonymous_mode)
|
||||
? "" : m_settings.get_str(settings_pack::user_agent).c_str()
|
||||
, d.lease_duration, soap_action);
|
||||
, lease_duration(d), soap_action);
|
||||
|
||||
post(d, soap, soap_action);
|
||||
}
|
||||
|
@ -1418,7 +1424,7 @@ void upnp::on_upnp_map_response(error_code const& e
|
|||
if (s.error_code == 725)
|
||||
{
|
||||
// The gateway only supports permanent leases
|
||||
d.lease_duration = 0;
|
||||
d.use_lease_duration = false;
|
||||
m.act = portmap_action::add;
|
||||
++m.failcount;
|
||||
update_map(d, mapping);
|
||||
|
@ -1456,11 +1462,12 @@ void upnp::on_upnp_map_response(error_code const& e
|
|||
{
|
||||
m_callback.on_port_mapping(mapping, d.external_ip, m.external_port, m.protocol, error_code()
|
||||
, portmap_transport::upnp);
|
||||
if (d.lease_duration > 0)
|
||||
if (d.use_lease_duration)
|
||||
{
|
||||
time_point const now = aux::time_now();
|
||||
m.expires = now
|
||||
+ seconds(d.lease_duration * 3 / 4);
|
||||
m.expires = now + seconds(
|
||||
m_settings.get_int(settings_pack::upnp_lease_duration) * 3 / 4);
|
||||
|
||||
time_point next_expire = m_refresh_timer.expires_at();
|
||||
if (next_expire < now || next_expire > m.expires)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue