diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/BootstrapConnection.cpp | 9 | ||||
-rw-r--r-- | src/DirectConnection.cpp | 6 | ||||
-rw-r--r-- | src/Socket.cpp | 8 |
3 files changed, 17 insertions, 6 deletions
diff --git a/src/BootstrapConnection.cpp b/src/BootstrapConnection.cpp index d914646..f09547e 100644 --- a/src/BootstrapConnection.cpp +++ b/src/BootstrapConnection.cpp @@ -127,6 +127,15 @@ namespace sibs Log::warn("BootstrapConnection::receiveDataFromServer: No listener found for key '%s', ignoring...", pubsubKey.toString().c_str()); return; } + + for(auto existingPeer : subscribeDataIt->second.peers) + { + if(peer == existingPeer) + { + Log::debug("BootstrapConnection::receiveDataFromServer: Already connected to peer (ip: %s, port: %d)", peer->address.getAddress().c_str(), peer->address.getPort()); + return; + } + } subscribeDataIt->second.peers.push_back(peer); Log::debug("BootstrapConnection::receiveDataFromServer: Connected to peer (ip: %s, port: %d) given by bootstrap node", peer->address.getAddress().c_str(), peer->address.getPort()); } diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index 175dae3..d92c972 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -160,8 +160,6 @@ namespace sibs int socketId = socket->udtSocket; if(!server) { - UDT::epoll_add_usock(eid, socketId); - socket->eid = eid; peersMutex.lock(); peers[socketId] = peer; peer->socket = std::move(socket); @@ -184,8 +182,6 @@ namespace sibs if(server) { - UDT::epoll_add_usock(eid, socketId); - socket->eid = eid; peersMutex.lock(); peers[socketId] = peer; peer->socket = std::move(socket); @@ -195,6 +191,8 @@ namespace sibs peer->sharedKeys = 1; peersMutex.unlock(); } + UDT::epoll_add_usock(eid, socketId); + peer->socket->eid = eid; peer->routed = false; if(connectCallbackFunc) diff --git a/src/Socket.cpp b/src/Socket.cpp index a078cab..1b39c19 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -34,7 +34,11 @@ namespace sibs Socket::~Socket() { - UDT::epoll_remove_usock(eid, udtSocket); - UDT::close(udtSocket); + if(udtSocket != -1) + { + if(eid != -1) + UDT::epoll_remove_usock(eid, udtSocket); + UDT::close(udtSocket); + } } }
\ No newline at end of file |