aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/BootstrapConnection.cpp11
-rw-r--r--src/DirectConnection.cpp5
2 files changed, 9 insertions, 7 deletions
diff --git a/src/BootstrapConnection.cpp b/src/BootstrapConnection.cpp
index df0a947..fc2e4ab 100644
--- a/src/BootstrapConnection.cpp
+++ b/src/BootstrapConnection.cpp
@@ -8,7 +8,8 @@ namespace chrono = std::chrono;
namespace sibs
{
- BootstrapConnection::BootstrapConnection(const Ipv4 &bootstrapAddress) :
+ BootstrapConnection::BootstrapConnection(const Ipv4 &bootstrapAddress, const ConnectionOptions &options) :
+ connections(0, options),
alive(true),
putThreadCount(0)
{
@@ -54,22 +55,22 @@ namespace sibs
}
}
- std::future<std::unique_ptr<BootstrapConnection>> BootstrapConnection::connect(const Ipv4 &bootstrapAddress)
+ std::future<std::unique_ptr<BootstrapConnection>> BootstrapConnection::connect(const Ipv4 &bootstrapAddress, const ConnectionOptions &options)
{
std::promise<std::unique_ptr<BootstrapConnection>> connectionPromise;
std::future<std::unique_ptr<BootstrapConnection>> connectionFuture = connectionPromise.get_future();
- std::thread([bootstrapAddress](std::promise<std::unique_ptr<BootstrapConnection>> connectionPromise)
+ std::thread([bootstrapAddress](std::promise<std::unique_ptr<BootstrapConnection>> connectionPromise, const ConnectionOptions options)
{
try
{
- BootstrapConnection *connection = new BootstrapConnection(bootstrapAddress);
+ BootstrapConnection *connection = new BootstrapConnection(bootstrapAddress, options);
connectionPromise.set_value(std::unique_ptr<BootstrapConnection>(connection));
}
catch(...)
{
connectionPromise.set_exception(std::current_exception());
}
- }, std::move(connectionPromise)).detach();
+ }, std::move(connectionPromise), options).detach();
return connectionFuture;
}
diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp
index ab58a48..6869d05 100644
--- a/src/DirectConnection.cpp
+++ b/src/DirectConnection.cpp
@@ -41,10 +41,11 @@ namespace sibs
return !(*this == other);
}
- DirectConnections::DirectConnections(u16 _port) :
+ DirectConnections::DirectConnections(u16 _port, const ConnectionOptions &_options) :
port(_port == 0 ? (u16)generateRandomNumber(2000, 32000) : _port),
alive(true),
removeDisconnectedPeerCallback(nullptr),
+ options(_options),
upnpDevList(nullptr)
{
UDT::startup();
@@ -300,7 +301,7 @@ namespace sibs
int socketId = socket->udtSocket;
Log::debug("DirectConnections: Connecting to %s peer (ip: %s, port: %d, rendezvous: %s)", server ? "server" : "client", address.getAddress().c_str(), address.getPort(), rendezvous ? "yes" : "no");
- if(UDT::connect(socketId, (sockaddr*)&address.address, sizeof(address.address)) == UDT::ERROR)
+ if((!server && !options.useP2p) || UDT::connect(socketId, (sockaddr*)&address.address, sizeof(address.address)) == UDT::ERROR)
{
if(!server)
{