aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-11-25 00:22:29 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 22:56:48 +0200
commit168fa4889c230de9016e1371e65da49a8d36e16c (patch)
treecee123ead84fdfd666af932ccedc66c68b2082d0 /src
parent213ab157a6e696ea76feb581977ebef2e2fad217 (diff)
Remove duplicate user add if same pubsub key, do not add user until connected
Diffstat (limited to 'src')
-rw-r--r--src/BootstrapConnection.cpp9
-rw-r--r--src/DirectConnection.cpp6
-rw-r--r--src/Socket.cpp8
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