OpenClonk
C4Network2UPnPP Class Reference
Inheritance diagram for C4Network2UPnPP:
[legend]
Collaboration diagram for C4Network2UPnPP:
[legend]

Public Member Functions

 C4Network2UPnPP ()
 
virtual ~C4Network2UPnPP ()
 
void AddMapping (C4Network2IOProtocol protocol, uint16_t intport, uint16_t extport)
 
void ClearMappings ()
 
 C4Network2UPnPP ()=default
 
void AddMapping (C4Network2IOProtocol protocol, uint16_t intport, uint16_t extport)
 
void RemoveMapping (C4Network2IOProtocol protocol, uint16_t extport)
 
void ClearNatMappings ()
 

Public Attributes

bool MustReleaseCOM {false}
 
IStaticPortMappingCollection * mappings {nullptr}
 
std::set< IStaticPortMapping * > added_mappings
 

Detailed Description

Definition at line 31 of file C4Network2UPnPLinux.cpp.

Constructor & Destructor Documentation

◆ C4Network2UPnPP() [1/2]

C4Network2UPnPP::C4Network2UPnPP ( )

Definition at line 64 of file C4Network2UPnPLinux.cpp.

65 {
66  action = std::async(&C4Network2UPnPP::Init, this);
67 }

◆ ~C4Network2UPnPP()

C4Network2UPnPP::~C4Network2UPnPP ( )
virtual

Definition at line 103 of file C4Network2UPnPLinux.cpp.

104 {
105  ClearMappings();
106  action.wait();
107  ProcessEvents(); // necessary for logging
108  if (initialized)
109  {
110  FreeUPNPUrls(&upnp_urls);
111  freeUPNPDevlist(devlist);
112  }
113 }

References ClearMappings(), and C4InteractiveThread::ProcessEvents().

Here is the call graph for this function:

◆ C4Network2UPnPP() [2/2]

C4Network2UPnPP::C4Network2UPnPP ( )
default

Member Function Documentation

◆ AddMapping() [1/2]

void C4Network2UPnPP::AddMapping ( C4Network2IOProtocol  protocol,
uint16_t  intport,
uint16_t  extport 
)

Definition at line 115 of file C4Network2UPnPLinux.cpp.

116 {
117  PortMapping mapping;
118  mapping.external_port = extport;
119  mapping.internal_port = intport;
120  mapping.protocol = (protocol == P_TCP ? "TCP" : "UDP");
121 
122  added_mappings.push_back(mapping);
123 
124  action = std::async([this, action = std::move(action), mapping]() {
125  action.wait();
126  AddPortMapping(mapping);
127  });
128 }
@ P_TCP
Definition: C4Network2IO.h:31

References P_TCP.

◆ AddMapping() [2/2]

void C4Network2UPnPP::AddMapping ( C4Network2IOProtocol  protocol,
uint16_t  intport,
uint16_t  extport 
)

◆ ClearMappings()

void C4Network2UPnPP::ClearMappings ( )

Definition at line 130 of file C4Network2UPnPLinux.cpp.

131 {
132  action = std::async([this, action = std::move(action)]() {
133  action.wait();
134 
135  for (auto mapping : added_mappings)
136  RemovePortMapping(mapping);
137 
138  added_mappings.clear();
139  });
140 }

Referenced by ~C4Network2UPnPP().

Here is the caller graph for this function:

◆ ClearNatMappings()

void C4Network2UPnPP::ClearNatMappings ( )

Definition at line 127 of file C4Network2UPnPWin32.cpp.

128 {
129  if (!mappings)
130  return;
131  for(IStaticPortMapping *mapping: added_mappings)
132  {
133  BSTR proto, client;
134  long intport, extport;
135  mapping->get_ExternalPort(&extport);
136  mapping->get_InternalPort(&intport);
137  mapping->get_InternalClient(&client);
138  mapping->get_Protocol(&proto);
139  if (SUCCEEDED(mappings->Remove(extport, proto)))
140  LogF("UPnP: Closed port %d->%s:%d (%s)", (int)extport, StdStrBuf(client).getData(), (int)intport, StdStrBuf(proto).getData());
141  ::SysFreeString(proto);
142  ::SysFreeString(client);
143  SafeRelease(mapping);
144  }
145  SafeRelease(mappings);
146 }
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
IStaticPortMappingCollection * mappings

References LogF(), and mappings.

Here is the call graph for this function:

◆ RemoveMapping()

void C4Network2UPnPP::RemoveMapping ( C4Network2IOProtocol  protocol,
uint16_t  extport 
)

Member Data Documentation

◆ added_mappings

std::set<IStaticPortMapping*> C4Network2UPnPP::added_mappings

Definition at line 58 of file C4Network2UPnPWin32.cpp.

◆ mappings

IStaticPortMappingCollection* C4Network2UPnPP::mappings {nullptr}

Definition at line 57 of file C4Network2UPnPWin32.cpp.

Referenced by ClearNatMappings().

◆ MustReleaseCOM

bool C4Network2UPnPP::MustReleaseCOM {false}

Definition at line 54 of file C4Network2UPnPWin32.cpp.


The documentation for this class was generated from the following files: