Back to Site
Loading...
Searching...
No Matches
port_mapping.h
Go to the documentation of this file.
1#pragma once
2
15#include <cstdint>
16#include <string>
17#include <functional>
18
19namespace librats {
20
22enum class PortMapProtocol : uint8_t {
23 TCP,
24 UDP
25};
26
28enum class PortMapTransport : uint8_t {
29 UPnP,
30 NatPMP
31};
32
34inline const char* to_string(PortMapProtocol p) {
35 return p == PortMapProtocol::TCP ? "TCP" : "UDP";
36}
37
39inline const char* to_string(PortMapTransport t) {
40 return t == PortMapTransport::UPnP ? "UPnP" : "NAT-PMP";
41}
42
53 bool success = false;
54 uint16_t internal_port = 0;
55 uint16_t external_port = 0;
56 std::string external_ip;
57 std::string error;
58};
59
64using PortMapCallback = std::function<void(const PortMapResult&)>;
65
73 bool enabled = true;
74 bool enable_upnp = true;
75 bool enable_natpmp = true;
76 uint32_t lease_duration_seconds = 3600;
77};
78
79} // namespace librats
Definition node.h:65
std::function< void(const PortMapResult &)> PortMapCallback
Callback invoked whenever a mapping is established, refreshed, removed or fails.
PortMapTransport
Which NAT traversal backend produced a result.
PortMapProtocol
Transport protocol of a port mapping.
const char * to_string(PortMapProtocol p)
Human readable protocol name ("TCP"/"UDP").
Result of a port mapping attempt.
uint16_t internal_port
Local (LAN) port that was mapped.
uint16_t external_port
Public (WAN) port assigned by the router.
std::string error
Human readable error when !success.
PortMapTransport transport
Backend that produced this result.
bool success
Whether the mapping is currently active.
std::string external_ip
Discovered public IP (may be empty)
PortMapProtocol protocol
Protocol of the mapping.
Configuration for automatic port forwarding (see PortMappingService).
bool enable_upnp
Use the UPnP IGD backend.
bool enable_natpmp
Use the NAT-PMP backend.
bool enabled
Master switch for automatic port forwarding.
uint32_t lease_duration_seconds
Requested lease duration.