mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
commit
fa4009821e
4 changed files with 50 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <mutex>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <cryptopp/dh.h>
|
#include <cryptopp/dh.h>
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
@ -6,6 +7,7 @@
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "Destination.h"
|
#include "Destination.h"
|
||||||
|
#include "ClientContext.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
@ -383,6 +385,42 @@ 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)
|
std::shared_ptr<i2p::stream::Stream> ClientDestination::CreateStream (const i2p::data::LeaseSet& remote, int port)
|
||||||
{
|
{
|
||||||
if (m_StreamingDestination)
|
if (m_StreamingDestination)
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace client
|
||||||
const int DEFAULT_INBOUND_TUNNEL_LENGTH = 3;
|
const int DEFAULT_INBOUND_TUNNEL_LENGTH = 3;
|
||||||
const char I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH[] = "outbound.length";
|
const char I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH[] = "outbound.length";
|
||||||
const int DEFAULT_OUTBOUND_TUNNEL_LENGTH = 3;
|
const int DEFAULT_OUTBOUND_TUNNEL_LENGTH = 3;
|
||||||
|
const int STREAM_REQUEST_TIMEOUT = 60; //in seconds
|
||||||
|
|
||||||
class ClientDestination: public i2p::garlic::GarlicDestination
|
class ClientDestination: public i2p::garlic::GarlicDestination
|
||||||
{
|
{
|
||||||
|
@ -64,6 +65,8 @@ namespace client
|
||||||
|
|
||||||
// streaming
|
// streaming
|
||||||
i2p::stream::StreamingDestination * GetStreamingDestination () const { return m_StreamingDestination; };
|
i2p::stream::StreamingDestination * GetStreamingDestination () const { return m_StreamingDestination; };
|
||||||
|
std::shared_ptr<i2p::stream::Stream> CreateStream (const std::string& dest, int port = 0);
|
||||||
|
std::shared_ptr<i2p::stream::Stream> CreateStream (const i2p::data::IdentHash& dest, int port = 0);
|
||||||
std::shared_ptr<i2p::stream::Stream> CreateStream (const i2p::data::LeaseSet& remote, int port = 0);
|
std::shared_ptr<i2p::stream::Stream> CreateStream (const i2p::data::LeaseSet& remote, int port = 0);
|
||||||
void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor);
|
void AcceptStreams (const i2p::stream::StreamingDestination::Acceptor& acceptor);
|
||||||
void StopAcceptingStreams ();
|
void StopAcceptingStreams ();
|
||||||
|
|
|
@ -139,6 +139,11 @@ namespace client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
I2PTunnel::I2PTunnel (ClientDestination * localDestination) :
|
||||||
|
m_LocalDestination (localDestination ? localDestination :
|
||||||
|
i2p::client::context.CreateNewLocalDestination (false, I2P_TUNNEL_DEFAULT_KEY_TYPE))
|
||||||
|
{
|
||||||
|
}
|
||||||
void I2PTunnel::AddConnection (std::shared_ptr<I2PTunnelConnection> conn)
|
void I2PTunnel::AddConnection (std::shared_ptr<I2PTunnelConnection> conn)
|
||||||
{
|
{
|
||||||
m_Connections.insert (conn);
|
m_Connections.insert (conn);
|
||||||
|
@ -155,8 +160,7 @@ namespace client
|
||||||
}
|
}
|
||||||
|
|
||||||
I2PClientTunnel::I2PClientTunnel (const std::string& destination, int port, ClientDestination * localDestination):
|
I2PClientTunnel::I2PClientTunnel (const std::string& destination, int port, ClientDestination * localDestination):
|
||||||
I2PTunnel (localDestination ? localDestination :
|
I2PTunnel (localDestination),
|
||||||
i2p::client::context.CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256)),
|
|
||||||
m_Acceptor (GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
|
m_Acceptor (GetService (), boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
|
||||||
m_Timer (GetService ()), m_Destination (destination), m_DestinationIdentHash (nullptr),
|
m_Timer (GetService ()), m_Destination (destination), m_DestinationIdentHash (nullptr),
|
||||||
m_RemoteLeaseSet (nullptr)
|
m_RemoteLeaseSet (nullptr)
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace client
|
||||||
const size_t I2P_TUNNEL_CONNECTION_BUFFER_SIZE = 8192;
|
const size_t I2P_TUNNEL_CONNECTION_BUFFER_SIZE = 8192;
|
||||||
const int I2P_TUNNEL_CONNECTION_MAX_IDLE = 3600; // in seconds
|
const int I2P_TUNNEL_CONNECTION_MAX_IDLE = 3600; // in seconds
|
||||||
const int I2P_TUNNEL_DESTINATION_REQUEST_TIMEOUT = 10; // in seconds
|
const int I2P_TUNNEL_DESTINATION_REQUEST_TIMEOUT = 10; // in seconds
|
||||||
|
const uint16_t I2P_TUNNEL_DEFAULT_KEY_TYPE = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256;
|
||||||
|
|
||||||
class I2PTunnel;
|
class I2PTunnel;
|
||||||
class I2PTunnelConnection: public std::enable_shared_from_this<I2PTunnelConnection>
|
class I2PTunnelConnection: public std::enable_shared_from_this<I2PTunnelConnection>
|
||||||
|
@ -58,8 +59,7 @@ namespace client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
I2PTunnel (ClientDestination * localDestination):
|
I2PTunnel (ClientDestination * localDestination = nullptr);
|
||||||
m_LocalDestination (localDestination) {};
|
|
||||||
virtual ~I2PTunnel () { ClearConnections (); };
|
virtual ~I2PTunnel () { ClearConnections (); };
|
||||||
|
|
||||||
void AddConnection (std::shared_ptr<I2PTunnelConnection> conn);
|
void AddConnection (std::shared_ptr<I2PTunnelConnection> conn);
|
||||||
|
|
Loading…
Add table
Reference in a new issue