Browse Source

pass I2CP options to local destination. Process tunnel length

pull/113/head
orignal 10 years ago
parent
commit
32a767dc91
  1. 12
      ClientContext.cpp
  2. 6
      ClientContext.h
  3. 43
      Destination.cpp
  4. 10
      Destination.h
  5. 9
      SAM.cpp
  6. 3
      SAM.h

12
ClientContext.cpp

@ -29,7 +29,7 @@ namespace client @@ -29,7 +29,7 @@ namespace client
{
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_SharedLocalDestination->Start ();
}
@ -149,10 +149,11 @@ namespace client @@ -149,10 +149,11 @@ namespace client
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);
auto localDestination = new ClientDestination (keys, isPublic);
auto localDestination = new ClientDestination (keys, isPublic, params);
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[localDestination->GetIdentHash ()] = localDestination;
localDestination->Start ();
@ -175,7 +176,8 @@ namespace client @@ -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 ());
if (it != m_Destinations.end ())
@ -188,7 +190,7 @@ namespace client @@ -188,7 +190,7 @@ namespace client
}
return nullptr;
}
auto localDestination = new ClientDestination (keys, isPublic);
auto localDestination = new ClientDestination (keys, isPublic, params);
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations[keys.GetPublic ().GetIdentHash ()] = localDestination;
localDestination->Start ();

6
ClientContext.h

@ -24,8 +24,10 @@ namespace client @@ -24,8 +24,10 @@ namespace client
void Stop ();
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 (const i2p::data::PrivateKeys& keys, bool isPublic = true);
ClientDestination * CreateNewLocalDestination (bool isPublic = false, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1,
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);
ClientDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
ClientDestination * LoadLocalDestination (const std::string& filename, bool isPublic);

43
Destination.cpp

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
#include <algorithm>
#include <boost/lexical_cast.hpp>
#include <cryptopp/dh.h>
#include "Log.h"
#include "util.h"
@ -9,16 +10,42 @@ namespace i2p @@ -9,16 +10,42 @@ namespace i2p
{
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_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0),
m_DatagramDestination (nullptr), m_PublishConfirmationTimer (nullptr)
{
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
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)
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:
}
@ -130,12 +157,22 @@ namespace client @@ -130,12 +157,22 @@ namespace client
{
if (m_Service)
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)
{
if (m_Service)
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)

10
Destination.h

@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
#include <thread>
#include <mutex>
#include <memory>
#include <map>
#include <string>
#include "Identity.h"
#include "TunnelPool.h"
#include "CryptoConst.h"
@ -21,11 +23,17 @@ namespace client @@ -21,11 +23,17 @@ namespace client
const uint8_t PROTOCOL_TYPE_RAW = 18;
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
{
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 ();
virtual void Start ();

9
SAM.cpp

@ -219,7 +219,7 @@ namespace client @@ -219,7 +219,7 @@ namespace client
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), true);
return;
}
m_Session = m_Owner.CreateSession (id, destination == SAM_VALUE_TRANSIENT ? "" : destination);
m_Session = m_Owner.CreateSession (id, destination == SAM_VALUE_TRANSIENT ? "" : destination, &params);
if (m_Session)
{
m_SocketType = eSAMSocketTypeSession;
@ -621,7 +621,8 @@ namespace client @@ -621,7 +621,8 @@ namespace client
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;
if (destination != "")
@ -631,10 +632,10 @@ namespace client @@ -631,10 +632,10 @@ namespace client
i2p::data::PrivateKeys keys;
keys.FromBuffer (buf, l);
delete[] buf;
localDestination = i2p::client::context.CreateNewLocalDestination (keys);
localDestination = i2p::client::context.CreateNewLocalDestination (keys, true, params);
}
else // transient
localDestination = i2p::client::context.CreateNewLocalDestination ();
localDestination = i2p::client::context.CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_DSA_SHA1, params);
if (localDestination)
{
SAMSession session;

3
SAM.h

@ -139,7 +139,8 @@ namespace client @@ -139,7 +139,8 @@ namespace client
void Stop ();
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);
SAMSession * FindSession (const std::string& id);

Loading…
Cancel
Save