mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 17:37:53 +00:00
use local destination function through ClientContext
This commit is contained in:
parent
4379f8e5ee
commit
14f4bb8656
@ -44,8 +44,8 @@ namespace client
|
||||
i2p::stream::StreamingDestination * localDestination = nullptr;
|
||||
std::string ircKeys = i2p::util::config::GetArg("-irckeys", "");
|
||||
if (ircKeys.length () > 0)
|
||||
localDestination = i2p::client::LoadLocalDestination (ircKeys, false);
|
||||
m_IrcTunnel = new i2p::stream::I2PClientTunnel (m_SocksProxy->GetService (), ircDestination,
|
||||
localDestination = i2p::client::context.LoadLocalDestination (ircKeys, false);
|
||||
m_IrcTunnel = new I2PClientTunnel (m_SocksProxy->GetService (), ircDestination,
|
||||
i2p::util::config::GetArg("-ircport", 6668), localDestination);
|
||||
m_IrcTunnel->Start ();
|
||||
LogPrint("IRC tunnel started");
|
||||
@ -53,8 +53,8 @@ namespace client
|
||||
std::string eepKeys = i2p::util::config::GetArg("-eepkeys", "");
|
||||
if (eepKeys.length () > 0) // eepkeys file is presented
|
||||
{
|
||||
auto localDestination = i2p::client::LoadLocalDestination (eepKeys, true);
|
||||
m_ServerTunnel = new i2p::stream::I2PServerTunnel (m_SocksProxy->GetService (),
|
||||
auto localDestination = i2p::client::context.LoadLocalDestination (eepKeys, true);
|
||||
m_ServerTunnel = new I2PServerTunnel (m_SocksProxy->GetService (),
|
||||
i2p::util::config::GetArg("-eephost", "127.0.0.1"), i2p::util::config::GetArg("-eepport", 80),
|
||||
localDestination);
|
||||
m_ServerTunnel->Start ();
|
||||
@ -63,7 +63,7 @@ namespace client
|
||||
int samPort = i2p::util::config::GetArg("-samport", 0);
|
||||
if (samPort)
|
||||
{
|
||||
m_SamBridge = new i2p::stream::SAMBridge (samPort);
|
||||
m_SamBridge = new SAMBridge (samPort);
|
||||
m_SamBridge->Start ();
|
||||
LogPrint("SAM bridge started");
|
||||
}
|
||||
@ -195,35 +195,5 @@ namespace client
|
||||
return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
i2p::stream::StreamingDestination * GetSharedLocalDestination ()
|
||||
{
|
||||
return context.GetSharedLocalDestination ();
|
||||
}
|
||||
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType)
|
||||
{
|
||||
return context.CreateNewLocalDestination (isPublic, sigType);
|
||||
}
|
||||
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)
|
||||
{
|
||||
return context.CreateNewLocalDestination (keys, isPublic);
|
||||
}
|
||||
|
||||
void DeleteLocalDestination (i2p::stream::StreamingDestination * destination)
|
||||
{
|
||||
context.DeleteLocalDestination (destination);
|
||||
}
|
||||
|
||||
i2p::stream::StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination)
|
||||
{
|
||||
return context.FindLocalDestination (destination);
|
||||
}
|
||||
|
||||
i2p::stream::StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic)
|
||||
{
|
||||
return context.LoadLocalDestination (filename, isPublic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ namespace client
|
||||
void Stop ();
|
||||
|
||||
i2p::stream::StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType);
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic);
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (bool isPublic = true, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1); // transient
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
|
||||
void DeleteLocalDestination (i2p::stream::StreamingDestination * destination);
|
||||
i2p::stream::StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination) const;
|
||||
i2p::stream::StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
||||
@ -41,9 +41,9 @@ namespace client
|
||||
|
||||
i2p::proxy::HTTPProxy * m_HttpProxy;
|
||||
i2p::proxy::SOCKSProxy * m_SocksProxy;
|
||||
i2p::stream::I2PClientTunnel * m_IrcTunnel;
|
||||
i2p::stream::I2PServerTunnel * m_ServerTunnel;
|
||||
i2p::stream::SAMBridge * m_SamBridge;
|
||||
I2PClientTunnel * m_IrcTunnel;
|
||||
I2PServerTunnel * m_ServerTunnel;
|
||||
SAMBridge * m_SamBridge;
|
||||
|
||||
public:
|
||||
// for HTTP
|
||||
@ -51,13 +51,6 @@ namespace client
|
||||
};
|
||||
|
||||
extern ClientContext context;
|
||||
|
||||
i2p::stream::StreamingDestination * GetSharedLocalDestination ();
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (bool isPublic = true, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1); // transient
|
||||
i2p::stream::StreamingDestination * CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true);
|
||||
void DeleteLocalDestination (i2p::stream::StreamingDestination * destination);
|
||||
i2p::stream::StreamingDestination * FindLocalDestination (const i2p::data::IdentHash& destination);
|
||||
i2p::stream::StreamingDestination * LoadLocalDestination (const std::string& filename, bool isPublic);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -517,7 +517,7 @@ namespace util
|
||||
if (m_Stream)
|
||||
{
|
||||
m_Stream->Close ();
|
||||
i2p::client::GetSharedLocalDestination ()->DeleteStream (m_Stream);
|
||||
i2p::client::context.GetSharedLocalDestination ()->DeleteStream (m_Stream);
|
||||
m_Stream = nullptr;
|
||||
}
|
||||
m_Socket->close ();
|
||||
@ -793,7 +793,7 @@ namespace util
|
||||
{
|
||||
i2p::data::IdentHash ident;
|
||||
i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), ident, 32);
|
||||
auto dest = i2p::client::FindLocalDestination (ident);
|
||||
auto dest = i2p::client::context.FindLocalDestination (ident);
|
||||
if (dest)
|
||||
{
|
||||
s << "<b>LeaseSets:</b> <i>" << dest->GetNumRemoteLeaseSets () << "</i><br>";
|
||||
@ -859,9 +859,9 @@ namespace util
|
||||
auto leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (destination);
|
||||
if (!leaseSet || !leaseSet->HasNonExpiredLeases ())
|
||||
{
|
||||
i2p::data::netdb.RequestDestination (destination, true, i2p::client::GetSharedLocalDestination ()->GetTunnelPool ());
|
||||
i2p::data::netdb.RequestDestination (destination, true, i2p::client::context.GetSharedLocalDestination ()->GetTunnelPool ());
|
||||
std::this_thread::sleep_for (std::chrono::seconds(10)); // wait for 10 seconds
|
||||
leaseSet = i2p::client::GetSharedLocalDestination ()->FindLeaseSet (destination);
|
||||
leaseSet = i2p::client::context.GetSharedLocalDestination ()->FindLeaseSet (destination);
|
||||
if (!leaseSet || !leaseSet->HasNonExpiredLeases ()) // still no LeaseSet
|
||||
{
|
||||
SendReply (leaseSet ? "<html>" + itoopieImage + "<br>Leases expired</html>" : "<html>" + itoopieImage + "LeaseSet not found</html>", 504);
|
||||
@ -869,7 +869,7 @@ namespace util
|
||||
}
|
||||
}
|
||||
if (!m_Stream)
|
||||
m_Stream = i2p::client::GetSharedLocalDestination ()->CreateNewOutgoingStream (*leaseSet);
|
||||
m_Stream = i2p::client::context.GetSharedLocalDestination ()->CreateNewOutgoingStream (*leaseSet);
|
||||
if (m_Stream)
|
||||
{
|
||||
m_Stream->Send ((uint8_t *)buf, len);
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace stream
|
||||
namespace client
|
||||
{
|
||||
I2PTunnelConnection::I2PTunnelConnection (I2PTunnel * owner,
|
||||
boost::asio::ip::tcp::socket * socket, const i2p::data::LeaseSet * leaseSet):
|
||||
@ -20,7 +20,7 @@ namespace stream
|
||||
Receive ();
|
||||
}
|
||||
|
||||
I2PTunnelConnection::I2PTunnelConnection (I2PTunnel * owner, Stream * stream,
|
||||
I2PTunnelConnection::I2PTunnelConnection (I2PTunnel * owner, i2p::stream::Stream * stream,
|
||||
boost::asio::ip::tcp::socket * socket, const boost::asio::ip::tcp::endpoint& target):
|
||||
m_Socket (socket), m_Stream (stream), m_Owner (owner)
|
||||
{
|
||||
@ -145,9 +145,9 @@ namespace stream
|
||||
}
|
||||
|
||||
I2PClientTunnel::I2PClientTunnel (boost::asio::io_service& service, const std::string& destination,
|
||||
int port, StreamingDestination * localDestination):
|
||||
int port, i2p::stream::StreamingDestination * localDestination):
|
||||
I2PTunnel (service, localDestination ? localDestination :
|
||||
i2p::client::CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256)),
|
||||
i2p::client::context.CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256)),
|
||||
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
|
||||
m_Timer (service), m_Destination (destination), m_DestinationIdentHash (nullptr),
|
||||
m_RemoteLeaseSet (nullptr)
|
||||
@ -251,7 +251,7 @@ namespace stream
|
||||
}
|
||||
|
||||
I2PServerTunnel::I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port,
|
||||
StreamingDestination * localDestination): I2PTunnel (service, localDestination),
|
||||
i2p::stream::StreamingDestination * localDestination): I2PTunnel (service, localDestination),
|
||||
m_Endpoint (boost::asio::ip::address::from_string (address), port)
|
||||
{
|
||||
}
|
||||
|
20
I2PTunnel.h
20
I2PTunnel.h
@ -10,7 +10,7 @@
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace stream
|
||||
namespace client
|
||||
{
|
||||
const size_t I2P_TUNNEL_CONNECTION_BUFFER_SIZE = 8192;
|
||||
const int I2P_TUNNEL_CONNECTION_MAX_IDLE = 3600; // in seconds
|
||||
@ -23,7 +23,7 @@ namespace stream
|
||||
|
||||
I2PTunnelConnection (I2PTunnel * owner, boost::asio::ip::tcp::socket * socket,
|
||||
const i2p::data::LeaseSet * leaseSet);
|
||||
I2PTunnelConnection (I2PTunnel * owner, Stream * stream, boost::asio::ip::tcp::socket * socket,
|
||||
I2PTunnelConnection (I2PTunnel * owner, i2p::stream::Stream * stream, boost::asio::ip::tcp::socket * socket,
|
||||
const boost::asio::ip::tcp::endpoint& target);
|
||||
~I2PTunnelConnection ();
|
||||
|
||||
@ -43,7 +43,7 @@ namespace stream
|
||||
|
||||
uint8_t m_Buffer[I2P_TUNNEL_CONNECTION_BUFFER_SIZE], m_StreamBuffer[I2P_TUNNEL_CONNECTION_BUFFER_SIZE];
|
||||
boost::asio::ip::tcp::socket * m_Socket;
|
||||
Stream * m_Stream;
|
||||
i2p::stream::Stream * m_Stream;
|
||||
I2PTunnel * m_Owner;
|
||||
};
|
||||
|
||||
@ -51,22 +51,22 @@ namespace stream
|
||||
{
|
||||
public:
|
||||
|
||||
I2PTunnel (boost::asio::io_service& service, StreamingDestination * localDestination):
|
||||
I2PTunnel (boost::asio::io_service& service, i2p::stream::StreamingDestination * localDestination):
|
||||
m_Service (service), m_LocalDestination (localDestination) {};
|
||||
virtual ~I2PTunnel () { ClearConnections (); };
|
||||
|
||||
void AddConnection (I2PTunnelConnection * conn);
|
||||
void RemoveConnection (I2PTunnelConnection * conn);
|
||||
void ClearConnections ();
|
||||
StreamingDestination * GetLocalDestination () { return m_LocalDestination; };
|
||||
void SetLocalDestination (StreamingDestination * dest) { m_LocalDestination = dest; };
|
||||
i2p::stream::StreamingDestination * GetLocalDestination () { return m_LocalDestination; };
|
||||
void SetLocalDestination (i2p::stream::StreamingDestination * dest) { m_LocalDestination = dest; };
|
||||
|
||||
boost::asio::io_service& GetService () { return m_Service; };
|
||||
|
||||
private:
|
||||
|
||||
boost::asio::io_service& m_Service;
|
||||
StreamingDestination * m_LocalDestination;
|
||||
i2p::stream::StreamingDestination * m_LocalDestination;
|
||||
std::set<I2PTunnelConnection *> m_Connections;
|
||||
};
|
||||
|
||||
@ -75,7 +75,7 @@ namespace stream
|
||||
public:
|
||||
|
||||
I2PClientTunnel (boost::asio::io_service& service, const std::string& destination, int port,
|
||||
StreamingDestination * localDestination = nullptr);
|
||||
i2p::stream::StreamingDestination * localDestination = nullptr);
|
||||
~I2PClientTunnel ();
|
||||
|
||||
void Start ();
|
||||
@ -102,7 +102,7 @@ namespace stream
|
||||
public:
|
||||
|
||||
I2PServerTunnel (boost::asio::io_service& service, const std::string& address, int port,
|
||||
StreamingDestination * localDestination);
|
||||
i2p::stream::StreamingDestination * localDestination);
|
||||
|
||||
void Start ();
|
||||
void Stop ();
|
||||
@ -110,7 +110,7 @@ namespace stream
|
||||
private:
|
||||
|
||||
void Accept ();
|
||||
void HandleAccept (Stream * stream);
|
||||
void HandleAccept (i2p::stream::Stream * stream);
|
||||
|
||||
private:
|
||||
|
||||
|
12
SAM.cpp
12
SAM.cpp
@ -11,7 +11,7 @@
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace stream
|
||||
namespace client
|
||||
{
|
||||
SAMSocket::SAMSocket (SAMBridge& owner):
|
||||
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_Timer (m_Owner.GetService ()),
|
||||
@ -25,6 +25,7 @@ namespace stream
|
||||
if (m_Stream)
|
||||
{
|
||||
m_Stream->Close ();
|
||||
if (m_Session && m_Session->localDestination)
|
||||
m_Session->localDestination->DeleteStream (m_Stream);
|
||||
}
|
||||
}
|
||||
@ -34,6 +35,7 @@ namespace stream
|
||||
if (m_Stream)
|
||||
{
|
||||
m_Stream->Close ();
|
||||
if (m_Session && m_Session->localDestination)
|
||||
m_Session->localDestination->DeleteStream (m_Stream);
|
||||
m_Stream = nullptr;
|
||||
}
|
||||
@ -332,7 +334,7 @@ namespace stream
|
||||
void SAMSocket::ProcessDestGenerate ()
|
||||
{
|
||||
LogPrint ("SAM dest generate");
|
||||
auto localDestination = i2p::client::CreateNewLocalDestination ();
|
||||
auto localDestination = i2p::client::context.CreateNewLocalDestination ();
|
||||
if (localDestination)
|
||||
{
|
||||
uint8_t buf[1024];
|
||||
@ -566,7 +568,7 @@ namespace stream
|
||||
|
||||
SAMSession * SAMBridge::CreateSession (const std::string& id, const std::string& destination)
|
||||
{
|
||||
StreamingDestination * localDestination = nullptr;
|
||||
i2p::stream::StreamingDestination * localDestination = nullptr;
|
||||
if (destination != "")
|
||||
{
|
||||
uint8_t * buf = new uint8_t[destination.length ()];
|
||||
@ -574,10 +576,10 @@ namespace stream
|
||||
i2p::data::PrivateKeys keys;
|
||||
keys.FromBuffer (buf, l);
|
||||
delete[] buf;
|
||||
localDestination = i2p::client::CreateNewLocalDestination (keys);
|
||||
localDestination = i2p::client::context.CreateNewLocalDestination (keys);
|
||||
}
|
||||
else // transient
|
||||
localDestination = i2p::client::CreateNewLocalDestination ();
|
||||
localDestination = i2p::client::context.CreateNewLocalDestination ();
|
||||
if (localDestination)
|
||||
{
|
||||
SAMSession session;
|
||||
|
6
SAM.h
6
SAM.h
@ -14,7 +14,7 @@
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
namespace stream
|
||||
namespace client
|
||||
{
|
||||
const size_t SAM_SOCKET_BUFFER_SIZE = 4096;
|
||||
const int SAM_SOCKET_CONNECTION_MAX_IDLE = 3600; // in seconds
|
||||
@ -106,13 +106,13 @@ namespace stream
|
||||
SAMSocketType m_SocketType;
|
||||
std::string m_ID; // nickname
|
||||
bool m_IsSilent;
|
||||
Stream * m_Stream;
|
||||
i2p::stream::Stream * m_Stream;
|
||||
SAMSession * m_Session;
|
||||
};
|
||||
|
||||
struct SAMSession
|
||||
{
|
||||
StreamingDestination * localDestination;
|
||||
i2p::stream::StreamingDestination * localDestination;
|
||||
std::list<SAMSocket *> sockets;
|
||||
};
|
||||
|
||||
|
@ -160,7 +160,7 @@ namespace proxy
|
||||
LogPrint("--- sock4a find lease set");
|
||||
m_ls = i2p::data::netdb.FindLeaseSet(m_dest);
|
||||
if (!m_ls || m_ls->HasNonExpiredLeases()) {
|
||||
i2p::data::netdb.RequestDestination (m_dest, true, i2p::client::GetSharedLocalDestination ()->GetTunnelPool ());
|
||||
i2p::data::netdb.RequestDestination (m_dest, true, i2p::client::context.GetSharedLocalDestination ()->GetTunnelPool ());
|
||||
m_ls_timer.expires_from_now(boost::posix_time::seconds(socks_leaseset_timeout));
|
||||
m_ls_timer.async_wait(boost::bind(&SOCKS4AHandler::LeaseSetTimeout, this, boost::asio::placeholders::error));
|
||||
} else {
|
||||
@ -224,7 +224,7 @@ namespace proxy
|
||||
void SOCKS4AHandler::SentConnectionSuccess(const boost::system::error_code & ecode)
|
||||
{
|
||||
LogPrint("--- socks4a making connection");
|
||||
m_stream = i2p::client::GetSharedLocalDestination ()->CreateNewOutgoingStream(*m_ls);
|
||||
m_stream = i2p::client::context.GetSharedLocalDestination ()->CreateNewOutgoingStream(*m_ls);
|
||||
m_state = OKAY;
|
||||
LogPrint("--- socks4a state is ", m_state);
|
||||
AsyncSockRead();
|
||||
|
Loading…
Reference in New Issue
Block a user