diff options
author | dec05eba <0xdec05eba@gmail.com> | 2018-06-09 06:08:40 +0200 |
---|---|---|
committer | dec05eba <0xdec05eba@gmail.com> | 2018-06-09 06:08:42 +0200 |
commit | fe9bfe8766982d88274ef3969124ebbfc189f98b (patch) | |
tree | a54c344e1604bf40049c71b7f4842a2f9fa5b7f8 /src | |
parent | e36509911c34a376c04498d47016002b1badbead (diff) |
Add debug, fix multithreading issue
Diffstat (limited to 'src')
-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()); } |