MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / RelaySocket

Method RelaySocket

MonaCore/sources/RelayServer.cpp:46–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45
46RelaySocket::RelaySocket(const SocketManager& manager,UInt16 port) : UDPSocket(manager),port(port) {
47
48 // executed in a parallel thread!
49 onError = [this](const Exception& ex) { DEBUG("Relay socket ", this->port, ", ", ex.error()); };
50
51 // executed in a parallel thread!
52 onPacket = [this](PoolBuffer& pBuffer, const SocketAddress& address) {
53 lock_guard<mutex> lock(_mutex);
54 auto it = _relayByAddress.find(address);
55 if(it==_relayByAddress.end()) {
56 DEBUG("Unknown relay ", address.toString()," address")
57 return;
58 }
59
60 Relay& relay(*it->second);
61 if(relay.receive())
62 INFO("Turn starting from ",relay.address1.toString()," to ",relay.address2.toString()," on ",this->port," relayed port")
63
64 SocketAddress destinator(relay.address1 == address ? relay.address2 : relay.address1);
65
66 DUMP("RELAY",pBuffer->data(), pBuffer->size(), "Relayed from ", address.toString(), " to ",destinator.toString())
67 Exception ex;
68 send(ex, pBuffer->data(), pBuffer->size(), destinator);
69 if (ex)
70 WARN("Relay packet (size=", pBuffer->size(), ") from ", address.toString(), " to ", destinator.toString()," on ",this->port,", ",ex.error())
71 else
72 DEBUG("Relay packet (size=", pBuffer->size(), ") from ", address.toString(), " to ", destinator.toString()," on ",this->port)
73 };
74
75 OnError::subscribe(onError);
76 OnPacket::subscribe(onPacket);
77}
78
79RelaySocket::~RelaySocket() {
80 OnPacket::unsubscribe(onPacket);

Callers

nothing calls this directly

Calls 6

errorMethod · 0.80
findMethod · 0.45
endMethod · 0.45
receiveMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected