From 402a3fce0552abffe2ab2808b9657cd73885771f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Nov 2018 04:51:46 +0100 Subject: Remove server node from getPeers func --- src/DirectConnection.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index b548a02..a00eeea 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -102,12 +102,12 @@ namespace sibs void DirectConnections::connectServer(const Ipv4 &address, PubSubConnectCallback connectCallbackFunc, PubSubReceiveDataCallback receiveDataCallbackFunc) { - connect(address, false, true, connectCallbackFunc, receiveDataCallbackFunc, true); + connect(address, false, true, connectCallbackFunc, receiveDataCallbackFunc, true, true); } void DirectConnections::connect(const Ipv4 &address, PubSubConnectCallback connectCallbackFunc, PubSubReceiveDataCallback receiveDataCallbackFunc) { - connect(address, true, true, connectCallbackFunc, receiveDataCallbackFunc, true); + connect(address, true, true, connectCallbackFunc, receiveDataCallbackFunc, true, false); } static bool isReady(const std::shared_future &connectionResultFuture) @@ -115,7 +115,7 @@ namespace sibs return connectionResultFuture.wait_for(std::chrono::seconds(0)) == std::future_status::ready; } - void DirectConnections::connect(const Ipv4 &address, bool rendezvous, bool reuseAddr, PubSubConnectCallback connectCallbackFunc, PubSubReceiveDataCallback receiveDataCallbackFunc, bool bind) + void DirectConnections::connect(const Ipv4 &address, bool rendezvous, bool reuseAddr, PubSubConnectCallback connectCallbackFunc, PubSubReceiveDataCallback receiveDataCallbackFunc, bool bind, bool server) { connectionResultsMutex.lock(); auto it = connectionResults.find(address); @@ -141,7 +141,7 @@ namespace sibs } else { - connectionResults[address] = std::async(std::launch::async, [this, address, rendezvous, reuseAddr, connectCallbackFunc, receiveDataCallbackFunc, bind]() + connectionResults[address] = std::async(std::launch::async, [this, address, rendezvous, reuseAddr, connectCallbackFunc, receiveDataCallbackFunc, bind, server]() { std::shared_ptr peer = std::make_shared(); std::unique_ptr socket; @@ -172,6 +172,7 @@ namespace sibs peer->socket = std::move(socket); peer->address = address; peer->receiveDataCallbackFunc = receiveDataCallbackFunc; + peer->type = (server ? PeerType::SERVER : PeerType::CLIENT); peersMutex.unlock(); if(connectCallbackFunc) @@ -240,7 +241,8 @@ namespace sibs std::lock_guard lock(peersMutex); for(auto &it : peers) { - result.push_back(it.second); + if(it.second->type == PeerType::CLIENT) + result.push_back(it.second); } return result; } -- cgit v1.2.3