diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-06-09 06:08:40 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 22:56:48 +0200 |
commit | 28eb36734e8315b4c11f6c51629071c3df4ade10 (patch) | |
tree | 6ff65e1b179644c7c2da107f2fa265d231435319 | |
parent | 5d42dd6a18e3b8b6eb46739b8a1d15997e229de2 (diff) |
Add debug, fix multithreading issue
-rw-r--r-- | src/BootstrapConnection.cpp | 5 | ||||
-rw-r--r-- | src/BootstrapNode.cpp | 1 | ||||
-rw-r--r-- | src/DirectConnection.cpp | 1 |
3 files changed, 3 insertions, 4 deletions
diff --git a/src/BootstrapConnection.cpp b/src/BootstrapConnection.cpp index 2920440..27c64bb 100644 --- a/src/BootstrapConnection.cpp +++ b/src/BootstrapConnection.cpp @@ -60,7 +60,6 @@ namespace sibs newPeerAddress.address.sin_addr.s_addr = ipv4Address; newPeerAddress.address.sin_port = port; memset(newPeerAddress.address.sin_zero, 0, sizeof(newPeerAddress.address.sin_zero)); - // TODO: Move connection to thread and add callback function, just like @receiveData and @send connections.connect(newPeerAddress, [this, pubsubKey](std::shared_ptr<DirectConnectionPeer> newPeer, PubSubResult result, const std::string &resultStr) { if(result == PubSubResult::OK) @@ -104,14 +103,12 @@ namespace sibs listenCallbackFuncIt->second(data->data(), data->size()); } - subscribedPeersMutex.lock(); + std::lock_guard<std::mutex> lock(subscribedPeersMutex); auto peersIt = subscribedPeers.find(pubsubKey); if(peersIt == subscribedPeers.end()) { - subscribedPeersMutex.unlock(); return; } - subscribedPeersMutex.unlock(); for(auto &peer : peersIt->second) { diff --git a/src/BootstrapNode.cpp b/src/BootstrapNode.cpp index 71ff0c9..f7fe738 100644 --- a/src/BootstrapNode.cpp +++ b/src/BootstrapNode.cpp @@ -69,6 +69,7 @@ namespace sibs void BootstrapNode::peerSubscribe(std::shared_ptr<DirectConnectionPeer> newPeer, const void *data, const usize size) { + Log::debug("BootstrapNode: Received peer subscribe from (ip: %s, port: %d)", newPeer->address.getAddress().c_str(), newPeer->address.getPort()); sibs::SafeDeserializer deserializer((const u8*)data, size); PubsubKey pubsubKey; deserializer.extract(pubsubKey.data.data(), PUBSUB_KEY_LENGTH); diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index d10c990..6872c27 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -186,6 +186,7 @@ namespace sibs peersMutex.unlock(); try { + Log::debug("DirectConnection: Received data from peer: (ip: %s, port: %d)", peer->address.getAddress().c_str(), peer->address.getPort()); if(peer->receiveDataCallbackFunc) peer->receiveDataCallbackFunc(peer, data.data(), data.size()); } |