mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-08 22:57:52 +00:00
pass I2CP options to local destination. Process tunnel length
This commit is contained in:
parent
3ca560b895
commit
32a767dc91
@ -29,7 +29,7 @@ namespace client
|
|||||||
{
|
{
|
||||||
if (!m_SharedLocalDestination)
|
if (!m_SharedLocalDestination)
|
||||||
{
|
{
|
||||||
m_SharedLocalDestination = CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_DSA_SHA1); // non-public, DSA
|
m_SharedLocalDestination = CreateNewLocalDestination (); // non-public, DSA
|
||||||
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
m_Destinations[m_SharedLocalDestination->GetIdentity ().GetIdentHash ()] = m_SharedLocalDestination;
|
||||||
m_SharedLocalDestination->Start ();
|
m_SharedLocalDestination->Start ();
|
||||||
}
|
}
|
||||||
@ -149,10 +149,11 @@ namespace client
|
|||||||
return localDestination;
|
return localDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientDestination * ClientContext::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
|
ClientDestination * ClientContext::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType,
|
||||||
|
const std::map<std::string, std::string> * params)
|
||||||
{
|
{
|
||||||
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType);
|
i2p::data::PrivateKeys keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType);
|
||||||
auto localDestination = new ClientDestination (keys, isPublic);
|
auto localDestination = new ClientDestination (keys, isPublic, params);
|
||||||
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
||||||
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
|
||||||
localDestination->Start ();
|
localDestination->Start ();
|
||||||
@ -175,7 +176,8 @@ namespace client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientDestination * ClientContext::CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
ClientDestination * ClientContext::CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
|
||||||
|
const std::map<std::string, std::string> * params)
|
||||||
{
|
{
|
||||||
auto it = m_Destinations.find (keys.GetPublic ().GetIdentHash ());
|
auto it = m_Destinations.find (keys.GetPublic ().GetIdentHash ());
|
||||||
if (it != m_Destinations.end ())
|
if (it != m_Destinations.end ())
|
||||||
@ -188,7 +190,7 @@ namespace client
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto localDestination = new ClientDestination (keys, isPublic);
|
auto localDestination = new ClientDestination (keys, isPublic, params);
|
||||||
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
std::unique_lock<std::mutex> l(m_DestinationsMutex);
|
||||||
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
|
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
|
||||||
localDestination->Start ();
|
localDestination->Start ();
|
||||||
|
@ -24,8 +24,10 @@ namespace client
|
|||||||
void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
ClientDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
ClientDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||||
ClientDestination * CreateNewLocalDestination (bool isPublic = true, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1); // transient
|
ClientDestination * CreateNewLocalDestination (bool isPublic = false, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1,
|
||||||
ClientDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
|
const std::map<std::string, std::string> * params = nullptr); // transient
|
||||||
|
ClientDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true,
|
||||||
|
const std::map<std::string, std::string> * params = nullptr);
|
||||||
void DeleteLocalDestination (ClientDestination * destination);
|
void DeleteLocalDestination (ClientDestination * destination);
|
||||||
ClientDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
ClientDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||||||
ClientDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
ClientDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <cryptopp/dh.h>
|
#include <cryptopp/dh.h>
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -9,16 +10,42 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
namespace client
|
namespace client
|
||||||
{
|
{
|
||||||
ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic):
|
ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
|
||||||
|
const std::map<std::string, std::string> * params):
|
||||||
m_IsRunning (false), m_Thread (nullptr), m_Service (nullptr), m_Work (nullptr),
|
m_IsRunning (false), m_Thread (nullptr), m_Service (nullptr), m_Work (nullptr),
|
||||||
m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0),
|
m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0),
|
||||||
m_DatagramDestination (nullptr), m_PublishConfirmationTimer (nullptr)
|
m_DatagramDestination (nullptr), m_PublishConfirmationTimer (nullptr)
|
||||||
{
|
{
|
||||||
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||||||
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
dh.GenerateKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
|
||||||
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, 3, 3); // 3-hops tunnel
|
int inboundTunnelLen = DEFAULT_INBOUND_TUNNEL_LENGTH;
|
||||||
|
int outboundTunnelLen = DEFAULT_OUTBOUND_TUNNEL_LENGTH;
|
||||||
|
if (params)
|
||||||
|
{
|
||||||
|
auto it = params->find (I2CP_PARAM_INBOUND_TUNNEL_LENGTH);
|
||||||
|
if (it != params->end ())
|
||||||
|
{
|
||||||
|
int len = boost::lexical_cast<int>(it->second);
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
inboundTunnelLen = len;
|
||||||
|
LogPrint (eLogInfo, "Inbound tunnel length set to ", len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it = params->find (I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH);
|
||||||
|
if (it != params->end ())
|
||||||
|
{
|
||||||
|
int len = boost::lexical_cast<int>(it->second);
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
outboundTunnelLen = len;
|
||||||
|
LogPrint (eLogInfo, "Outbound tunnel length set to ", len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (*this, inboundTunnelLen, outboundTunnelLen);
|
||||||
if (m_IsPublic)
|
if (m_IsPublic)
|
||||||
LogPrint ("Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created");
|
LogPrint (eLogInfo, "Local address ", GetIdentHash ().ToBase32 (), ".b32.i2p created");
|
||||||
m_StreamingDestination = new i2p::stream::StreamingDestination (*this); // TODO:
|
m_StreamingDestination = new i2p::stream::StreamingDestination (*this); // TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,12 +157,22 @@ namespace client
|
|||||||
{
|
{
|
||||||
if (m_Service)
|
if (m_Service)
|
||||||
m_Service->post (std::bind (&ClientDestination::HandleGarlicMessage, this, msg));
|
m_Service->post (std::bind (&ClientDestination::HandleGarlicMessage, this, msg));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "Destination's thread is not running");
|
||||||
|
i2p::DeleteI2NPMessage (msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg)
|
void ClientDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg)
|
||||||
{
|
{
|
||||||
if (m_Service)
|
if (m_Service)
|
||||||
m_Service->post (std::bind (&ClientDestination::HandleDeliveryStatusMessage, this, msg));
|
m_Service->post (std::bind (&ClientDestination::HandleDeliveryStatusMessage, this, msg));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "Destination's thread is not running");
|
||||||
|
i2p::DeleteI2NPMessage (msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from)
|
void ClientDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from)
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "TunnelPool.h"
|
#include "TunnelPool.h"
|
||||||
#include "CryptoConst.h"
|
#include "CryptoConst.h"
|
||||||
@ -21,11 +23,17 @@ namespace client
|
|||||||
const uint8_t PROTOCOL_TYPE_RAW = 18;
|
const uint8_t PROTOCOL_TYPE_RAW = 18;
|
||||||
const int PUBLISH_CONFIRMATION_TIMEOUT = 5; // in seconds
|
const int PUBLISH_CONFIRMATION_TIMEOUT = 5; // in seconds
|
||||||
|
|
||||||
|
// I2CP
|
||||||
|
const char I2CP_PARAM_INBOUND_TUNNEL_LENGTH[] = "inbound.length";
|
||||||
|
const int DEFAULT_INBOUND_TUNNEL_LENGTH = 3;
|
||||||
|
const char I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH[] = "outbound.length";
|
||||||
|
const int DEFAULT_OUTBOUND_TUNNEL_LENGTH = 3;
|
||||||
|
|
||||||
class ClientDestination: public i2p::garlic::GarlicDestination
|
class ClientDestination: public i2p::garlic::GarlicDestination
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic, const std::map<std::string, std::string> * params = nullptr);
|
||||||
~ClientDestination ();
|
~ClientDestination ();
|
||||||
|
|
||||||
virtual void Start ();
|
virtual void Start ();
|
||||||
|
9
SAM.cpp
9
SAM.cpp
@ -219,7 +219,7 @@ namespace client
|
|||||||
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), true);
|
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_Session = m_Owner.CreateSession (id, destination == SAM_VALUE_TRANSIENT ? "" : destination);
|
m_Session = m_Owner.CreateSession (id, destination == SAM_VALUE_TRANSIENT ? "" : destination, ¶ms);
|
||||||
if (m_Session)
|
if (m_Session)
|
||||||
{
|
{
|
||||||
m_SocketType = eSAMSocketTypeSession;
|
m_SocketType = eSAMSocketTypeSession;
|
||||||
@ -621,7 +621,8 @@ namespace client
|
|||||||
Accept ();
|
Accept ();
|
||||||
}
|
}
|
||||||
|
|
||||||
SAMSession * SAMBridge::CreateSession (const std::string& id, const std::string& destination)
|
SAMSession * SAMBridge::CreateSession (const std::string& id, const std::string& destination,
|
||||||
|
const std::map<std::string, std::string> * params)
|
||||||
{
|
{
|
||||||
ClientDestination * localDestination = nullptr;
|
ClientDestination * localDestination = nullptr;
|
||||||
if (destination != "")
|
if (destination != "")
|
||||||
@ -631,10 +632,10 @@ namespace client
|
|||||||
i2p::data::PrivateKeys keys;
|
i2p::data::PrivateKeys keys;
|
||||||
keys.FromBuffer (buf, l);
|
keys.FromBuffer (buf, l);
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
localDestination = i2p::client::context.CreateNewLocalDestination (keys);
|
localDestination = i2p::client::context.CreateNewLocalDestination (keys, true, params);
|
||||||
}
|
}
|
||||||
else // transient
|
else // transient
|
||||||
localDestination = i2p::client::context.CreateNewLocalDestination ();
|
localDestination = i2p::client::context.CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_DSA_SHA1, params);
|
||||||
if (localDestination)
|
if (localDestination)
|
||||||
{
|
{
|
||||||
SAMSession session;
|
SAMSession session;
|
||||||
|
3
SAM.h
3
SAM.h
@ -139,7 +139,8 @@ namespace client
|
|||||||
void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
boost::asio::io_service& GetService () { return m_Service; };
|
boost::asio::io_service& GetService () { return m_Service; };
|
||||||
SAMSession * CreateSession (const std::string& id, const std::string& destination = ""); // empty string means transient
|
SAMSession * CreateSession (const std::string& id, const std::string& destination = "", // empty string means transient
|
||||||
|
const std::map<std::string, std::string> * params = nullptr);
|
||||||
void CloseSession (const std::string& id);
|
void CloseSession (const std::string& id);
|
||||||
SAMSession * FindSession (const std::string& id);
|
SAMSession * FindSession (const std::string& id);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user