|
|
|
@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
|
|
|
|
|
#include <algorithm> |
|
|
|
|
#include <mutex> |
|
|
|
|
#include <boost/lexical_cast.hpp> |
|
|
|
|
#include <cryptopp/dh.h> |
|
|
|
|
#include "Log.h" |
|
|
|
@ -6,6 +7,7 @@
@@ -6,6 +7,7 @@
|
|
|
|
|
#include "Timestamp.h" |
|
|
|
|
#include "NetDb.h" |
|
|
|
|
#include "Destination.h" |
|
|
|
|
#include "ClientContext.h" |
|
|
|
|
|
|
|
|
|
namespace i2p |
|
|
|
|
{ |
|
|
|
@ -383,12 +385,48 @@ namespace client
@@ -383,12 +385,48 @@ namespace client
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::shared_ptr<i2p::stream::Stream> ClientDestination::CreateStream (const std::string& dest, int port) { |
|
|
|
|
i2p::data::IdentHash identHash; |
|
|
|
|
if (i2p::client::context.GetAddressBook ().GetIdentHash (dest, identHash)) |
|
|
|
|
return CreateStream (identHash, port); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogWarning, "Remote destination ", dest, " not found"); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::shared_ptr<i2p::stream::Stream> ClientDestination::CreateStream (const i2p::data::IdentHash& dest, int port) { |
|
|
|
|
const i2p::data::LeaseSet * leaseSet = FindLeaseSet (dest); |
|
|
|
|
if (!leaseSet) |
|
|
|
|
{ |
|
|
|
|
bool found = false; |
|
|
|
|
std::condition_variable newDataReceived; |
|
|
|
|
std::mutex newDataReceivedMutex; |
|
|
|
|
std::unique_lock<std::mutex> l(newDataReceivedMutex); |
|
|
|
|
RequestDestination (dest, |
|
|
|
|
[&newDataReceived, &found](bool success) |
|
|
|
|
{ |
|
|
|
|
found = success; |
|
|
|
|
newDataReceived.notify_all (); |
|
|
|
|
}); |
|
|
|
|
if (newDataReceived.wait_for (l, std::chrono::seconds (STREAM_REQUEST_TIMEOUT)) == std::cv_status::timeout) |
|
|
|
|
LogPrint (eLogError, "Subscription LeseseSet request timeout expired"); |
|
|
|
|
if (found) |
|
|
|
|
leaseSet = FindLeaseSet (dest); |
|
|
|
|
} |
|
|
|
|
if (leaseSet) |
|
|
|
|
return CreateStream (*leaseSet, port); |
|
|
|
|
else |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::shared_ptr<i2p::stream::Stream> ClientDestination::CreateStream (const i2p::data::LeaseSet& remote, int port) |
|
|
|
|
{ |
|
|
|
|
if (m_StreamingDestination) |
|
|
|
|
return m_StreamingDestination->CreateNewOutgoingStream (remote, port); |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ClientDestination::AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor) |
|
|
|
|
{ |
|
|
|
|