aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sibs/BootstrapConnection.hpp3
-rw-r--r--src/BootstrapConnection.cpp4
-rw-r--r--src/DirectConnection.cpp14
3 files changed, 18 insertions, 3 deletions
diff --git a/include/sibs/BootstrapConnection.hpp b/include/sibs/BootstrapConnection.hpp
index e77222d..dd90b7d 100644
--- a/include/sibs/BootstrapConnection.hpp
+++ b/include/sibs/BootstrapConnection.hpp
@@ -19,7 +19,8 @@ namespace sibs
PubsubKeyAlreadyListeningException(const std::string &errMsg) : std::runtime_error(errMsg) {}
};
- using BoostrapConnectionListenCallbackFunc = std::function<void(const void *data, const usize size)>;
+ // @peer is nullptr is data was sent by local user
+ using BoostrapConnectionListenCallbackFunc = std::function<void(const DirectConnectionPeer *peer, const void *data, const usize size)>;
class BootstrapConnection
{
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
{