Commit 99e0d54d authored by Ivan Vilata-i-Balaguer's avatar Ivan Vilata-i-Balaguer
Browse files

Reuse a random description for UPnP mappings.

To ease tracking our own mappings.
parent c1552f08
#pragma once
#include <boost/format.hpp>
#include <upnp.h>
#include <util/random.h>
#include <util/signal.h>
#include <async_sleep.h>
#include <defer.h>
......@@ -15,6 +18,7 @@ public:
, uint16_t internal_port)
: _external_port(external_port)
, _internal_port(internal_port)
, _random_id(util::random::number<uint32_t>())
{
TRACK_SPAWN(exec, ([
this,
......@@ -59,6 +63,8 @@ private:
auto success_wait_time = lease_duration - seconds(10);
auto failure_wait_time = minutes(1);
auto mapping_desc = (boost::format("Ouinet-%08x") % _random_id).str();
while (true)
{
auto r_igds = upnp::igd::discover(exec, yield);
......@@ -80,7 +86,7 @@ private:
auto r = igd.add_port_mapping( upnp::igd::udp
, _external_port
, _internal_port
, "Ouinet"
, mapping_desc
, lease_duration
, yield);
if (cancel) return;
......@@ -120,6 +126,11 @@ private:
Cancel _lifetime_cancel;
uint16_t _external_port;
uint16_t _internal_port;
// The desciption for mappings includes a random value
// to ease tracking those added by this UPnP client.
// Probably not the most secure option but simple enough
// without having to check our own address (which is probaly unreliable).
uint32_t _random_id;
bool _mapping_is_active = false;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment