mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
Merge pull request #6 from orignal/master
Merge pull request #6 from orignal/master
This commit is contained in:
commit
72fcff35b6
@ -236,8 +236,8 @@ namespace garlic
|
|||||||
auto it = m_Sessions.find (destination->GetIdentHash ());
|
auto it = m_Sessions.find (destination->GetIdentHash ());
|
||||||
if (it != m_Sessions.end ())
|
if (it != m_Sessions.end ())
|
||||||
{
|
{
|
||||||
m_Sessions.erase (it);
|
|
||||||
delete it->second;
|
delete it->second;
|
||||||
|
m_Sessions.erase (it);
|
||||||
}
|
}
|
||||||
GarlicRoutingSession * session = new GarlicRoutingSession (destination, 0); // not follow-on messages expected
|
GarlicRoutingSession * session = new GarlicRoutingSession (destination, 0); // not follow-on messages expected
|
||||||
m_Sessions[destination->GetIdentHash ()] = session;
|
m_Sessions[destination->GetIdentHash ()] = session;
|
||||||
|
11
NetDb.cpp
11
NetDb.cpp
@ -412,8 +412,8 @@ namespace data
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// no more requests for detination possible. delete it
|
// no more requests for detination possible. delete it
|
||||||
m_RequestedDestinations.erase (it);
|
|
||||||
delete it->second;
|
delete it->second;
|
||||||
|
m_RequestedDestinations.erase (it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -474,8 +474,8 @@ namespace data
|
|||||||
auto it = m_RequestedDestinations.find (dest);
|
auto it = m_RequestedDestinations.find (dest);
|
||||||
if (it != m_RequestedDestinations.end ())
|
if (it != m_RequestedDestinations.end ())
|
||||||
{
|
{
|
||||||
m_RequestedDestinations.erase (it);
|
|
||||||
delete it->second;
|
delete it->second;
|
||||||
|
m_RequestedDestinations.erase (it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,12 +499,15 @@ namespace data
|
|||||||
{
|
{
|
||||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||||
uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1), i = 0;
|
uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1), i = 0;
|
||||||
|
RouterInfo * last = nullptr;
|
||||||
for (auto it: m_RouterInfos)
|
for (auto it: m_RouterInfos)
|
||||||
{
|
{
|
||||||
if (i >= ind) return it.second;
|
if (!it.second->IsUnreachable ())
|
||||||
|
last = it.second;
|
||||||
|
if (i >= ind) break;
|
||||||
else i++;
|
else i++;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::PostI2NPMsg (I2NPMessage * msg)
|
void NetDb::PostI2NPMsg (I2NPMessage * msg)
|
||||||
|
27
SSU.cpp
27
SSU.cpp
@ -7,11 +7,26 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
namespace ssu
|
namespace ssu
|
||||||
{
|
{
|
||||||
|
|
||||||
|
SSUSession::SSUSession (): m_State (eSessionStateUnknown)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSUSession::ProcessNextMessage (uint8_t * buf, std::size_t len)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
SSUServer::SSUServer (boost::asio::io_service& service, int port):
|
SSUServer::SSUServer (boost::asio::io_service& service, int port):
|
||||||
m_Socket (service, boost::asio::ip::udp::v4 (), port)
|
m_Socket (service, boost::asio::ip::udp::v4 (), port)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SSUServer::~SSUServer ()
|
||||||
|
{
|
||||||
|
for (auto it: m_Sessions)
|
||||||
|
delete it.second;
|
||||||
|
}
|
||||||
|
|
||||||
void SSUServer::Start ()
|
void SSUServer::Start ()
|
||||||
{
|
{
|
||||||
Receive ();
|
Receive ();
|
||||||
@ -33,7 +48,17 @@ namespace ssu
|
|||||||
if (!ecode)
|
if (!ecode)
|
||||||
{
|
{
|
||||||
LogPrint ("SSU received ", bytes_transferred, " bytes");
|
LogPrint ("SSU received ", bytes_transferred, " bytes");
|
||||||
// Handle
|
SSUSession * session = nullptr;
|
||||||
|
auto it = m_Sessions.find (m_SenderEndpoint);
|
||||||
|
if (it != m_Sessions.end ())
|
||||||
|
session = it->second;
|
||||||
|
if (session)
|
||||||
|
{
|
||||||
|
session = new SSUSession ();
|
||||||
|
m_Sessions[m_SenderEndpoint] = session;
|
||||||
|
LogPrint ("New SSU session from ", m_SenderEndpoint.address ().to_string (), ":", m_SenderEndpoint.port (), " created");
|
||||||
|
}
|
||||||
|
session->ProcessNextMessage (m_ReceiveBuffer, bytes_transferred);
|
||||||
Receive ();
|
Receive ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
37
SSU.h
37
SSU.h
@ -2,6 +2,7 @@
|
|||||||
#define SSU_H__
|
#define SSU_H__
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <map>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
@ -10,11 +11,46 @@ namespace ssu
|
|||||||
{
|
{
|
||||||
const int SSU_MTU = 1484;
|
const int SSU_MTU = 1484;
|
||||||
|
|
||||||
|
// payload types (4 bits)
|
||||||
|
const uint8_t PAYLOAD_TYPE_SESSION_REQUEST = 0;
|
||||||
|
const uint8_t PAYLOAD_TYPE_SESSION_CREATED = 1;
|
||||||
|
const uint8_t PAYLOAD_TYPE_SESSION_CONFIRMED = 2;
|
||||||
|
const uint8_t PAYLOAD_TYPE_RELAY_REQUEST = 3;
|
||||||
|
const uint8_t PAYLOAD_TYPE_RELAY_RESPONSE = 4;
|
||||||
|
const uint8_t PAYLOAD_TYPE_RELAY_INTRO = 5;
|
||||||
|
const uint8_t PAYLOAD_TYPE_DATA = 6;
|
||||||
|
const uint8_t PAYLOAD_TYPE_TEST = 7;
|
||||||
|
|
||||||
|
enum SessionState
|
||||||
|
{
|
||||||
|
eSessionStateUnknown,
|
||||||
|
eSessionStateRequestSent,
|
||||||
|
eSessionStateRequestReceived,
|
||||||
|
eSessionStateCreatedSent,
|
||||||
|
eSessionStateCreatedReceived,
|
||||||
|
eSessionStateConfirmedSent,
|
||||||
|
eSessionStateConfirmedReceived,
|
||||||
|
eSessionStateEstablised
|
||||||
|
};
|
||||||
|
|
||||||
|
class SSUSession
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
SSUSession ();
|
||||||
|
void ProcessNextMessage (uint8_t * buf, std::size_t len);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
SessionState m_State;
|
||||||
|
};
|
||||||
|
|
||||||
class SSUServer
|
class SSUServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SSUServer (boost::asio::io_service& service, int port);
|
SSUServer (boost::asio::io_service& service, int port);
|
||||||
|
~SSUServer ();
|
||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
@ -28,6 +64,7 @@ namespace ssu
|
|||||||
boost::asio::ip::udp::socket m_Socket;
|
boost::asio::ip::udp::socket m_Socket;
|
||||||
boost::asio::ip::udp::endpoint m_SenderEndpoint;
|
boost::asio::ip::udp::endpoint m_SenderEndpoint;
|
||||||
uint8_t m_ReceiveBuffer[SSU_MTU];
|
uint8_t m_ReceiveBuffer[SSU_MTU];
|
||||||
|
std::map<boost::asio::ip::udp::endpoint, SSUSession *> m_Sessions;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,16 +395,15 @@ namespace tunnel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//OutboundTunnel * outboundTunnel = GetNextOutboundTunnel ();
|
|
||||||
LogPrint ("Creating two hops outbound tunnel...");
|
LogPrint ("Creating two hops outbound tunnel...");
|
||||||
CreateTunnel<OutboundTunnel> (
|
CreateTunnel<OutboundTunnel> (
|
||||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
{
|
{
|
||||||
i2p::data::netdb.GetRandomNTCPRouter (),
|
i2p::data::netdb.GetRandomNTCPRouter (), // first hop must be NTCP
|
||||||
i2p::data::netdb.GetRandomNTCPRouter ()
|
i2p::data::netdb.GetRandomRouter ()
|
||||||
},
|
},
|
||||||
inboundTunnel->GetTunnelConfig ())/*,
|
inboundTunnel->GetTunnelConfig ()));
|
||||||
outboundTunnel*/);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user