From fe9bfe8766982d88274ef3969124ebbfc189f98b Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Sat, 9 Jun 2018 06:08:40 +0200 Subject: Add debug, fix multithreading issue --- src/BootstrapConnection.cpp | 5 +---- src/BootstrapNode.cpp | 1 + src/DirectConnection.cpp | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src') 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 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 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 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()); } -- cgit v1.2.3