diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/BootstrapConnection.cpp | 4 | ||||
-rw-r--r-- | src/DirectConnection.cpp | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/BootstrapConnection.cpp b/src/BootstrapConnection.cpp index 9a19943..421dfe1 100644 --- a/src/BootstrapConnection.cpp +++ b/src/BootstrapConnection.cpp @@ -85,7 +85,7 @@ namespace sibs void BootstrapConnection::receiveDataFromPeer(BoostrapConnectionListenCallbackFunc listenCallbackFunc, std::shared_ptr<DirectConnectionPeer> peer, const void *data, const usize size) { if(listenCallbackFunc) - listenCallbackFunc(data, size); + listenCallbackFunc(peer.get(), data, size); } void BootstrapConnection::listen(const PubsubKey &pubsubKey, BoostrapConnectionListenCallbackFunc callbackFunc) @@ -109,7 +109,7 @@ namespace sibs std::lock_guard<std::mutex> lock(listenerCallbackFuncMutex); auto listenCallbackFuncIt = listenCallbackFuncs.find(pubsubKey); if(listenCallbackFuncIt != listenCallbackFuncs.end() && listenCallbackFuncIt->second) - listenCallbackFuncIt->second(data->data(), data->size()); + listenCallbackFuncIt->second(nullptr, data->data(), data->size()); } std::lock_guard<std::mutex> lock(subscribedPeersMutex); diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index 540f7cb..71c7f1f 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -74,12 +74,26 @@ namespace sibs { if(reuseAddr) { + /* if(UDT::bind(socket, (sockaddr*)&addressToBind.address, sizeof(addressToBind.address)) == UDT::ERROR) { std::string errMsg = "UDT: Failed to bind, error: "; errMsg += UDT::getlasterror_desc(); throw SocketCreateException(errMsg); } + */ + Ipv4 myAddr = addressToBind; + for(int i = 0; i < 2000; ++i) + { + if(UDT::bind(socket, (sockaddr*)&myAddr.address, sizeof(myAddr.address)) == UDT::ERROR) + { + port = (u16)generateRandomNumber(2000, 32000); + myAddr.address.sin_port = htons(port); + } + else + return socket; + } + throw SocketCreateException("UDT: Failed to bind after 2000 tries"); } else { |