Browse Source

don't specify RI for inbound NTCP connections

pull/105/head
orignal 10 years ago
parent
commit
8d75d51803
  1. 6
      HTTPServer.cpp
  2. 24
      NTCPSession.cpp
  3. 13
      NTCPSession.h
  4. 4
      Transports.cpp

6
HTTPServer.cpp

@ -701,12 +701,12 @@ namespace util @@ -701,12 +701,12 @@ namespace util
s << "NTCP<br>";
for (auto it: i2p::transport::transports.GetNTCPSessions ())
{
// RouterInfo of incoming connection doesn't have address
bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress ();
if (it.second->IsEstablished ())
{
// incoming connection doesn't have remote RI
bool outgoing = it.second->GetRemoteRouterInfo ();
if (outgoing) s << "-->";
s << it.second->GetRemoteRouterInfo ().GetIdentHashAbbreviation () << ": "
s << it.second->GetRemoteRouterIdentity ().GetIdentHash ().ToBase64 ().substr (0, 4) << ": "
<< it.second->GetSocket ().remote_endpoint().address ().to_string ();
if (!outgoing) s << "-->";
s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]";

24
NTCPSession.cpp

@ -18,7 +18,7 @@ namespace i2p @@ -18,7 +18,7 @@ namespace i2p
{
namespace transport
{
NTCPSession::NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo& in_RemoteRouterInfo):
NTCPSession::NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo * in_RemoteRouterInfo):
m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false),
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0),
m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0)
@ -81,7 +81,8 @@ namespace transport @@ -81,7 +81,8 @@ namespace transport
for (auto it :m_DelayedMessages)
{
// try to send them again
transports.SendMessage (m_RemoteRouterInfo.GetIdentHash (), it);
if (m_RemoteRouterInfo)
transports.SendMessage (m_RemoteRouterInfo->GetIdentHash (), it);
numDelayed++;
}
m_DelayedMessages.clear ();
@ -117,9 +118,14 @@ namespace transport @@ -117,9 +118,14 @@ namespace transport
void NTCPSession::ClientLogin ()
{
if (!m_RemoteRouterInfo)
{
LogPrint ("Remote router info is not set");
Terminate ();
}
if (!m_DHKeysPair)
m_DHKeysPair = transports.GetNextDHKeysPair ();
m_RemoteRouterIdentity = m_RemoteRouterInfo. GetRouterIdentity ();
m_RemoteRouterIdentity = m_RemoteRouterInfo->GetRouterIdentity ();
// send Phase1
const uint8_t * x = m_DHKeysPair->publicKey;
memcpy (m_Establisher->phase1.pubKey, x, 256);
@ -237,7 +243,7 @@ namespace transport @@ -237,7 +243,7 @@ namespace transport
LogPrint ("Phase 2 read error: ", ecode.message (), ". Wrong ident assumed");
if (ecode != boost::asio::error::operation_aborted)
{
GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid
m_RemoteRouterInfo->SetUnreachable (true); // this RouterInfo is not valid
transports.ReuseDHKeysPair (m_DHKeysPair);
m_DHKeysPair = nullptr;
Terminate ();
@ -282,7 +288,7 @@ namespace transport @@ -282,7 +288,7 @@ namespace transport
SignedData s;
memcpy (s.x, m_Establisher->phase1.pubKey, 256);
memcpy (s.y, m_Establisher->phase2.pubKey, 256);
memcpy (s.ident, m_RemoteRouterInfo.GetIdentHash (), 32);
memcpy (s.ident, m_RemoteRouterIdentity.GetIdentHash (), 32);
s.tsA = tsA;
s.tsB = m_Establisher->phase2.encrypted.timestamp;
i2p::context.Sign ((uint8_t *)&s, sizeof (s), m_Establisher->phase3.signature);
@ -382,7 +388,7 @@ namespace transport @@ -382,7 +388,7 @@ namespace transport
LogPrint ("Phase 4 read error: ", ecode.message ());
if (ecode != boost::asio::error::operation_aborted)
{
GetRemoteRouterInfo ().SetUnreachable (true); // this router doesn't like us
m_RemoteRouterInfo->SetUnreachable (true); // this router doesn't like us
Terminate ();
}
}
@ -594,8 +600,7 @@ namespace transport @@ -594,8 +600,7 @@ namespace transport
NTCPClient::NTCPClient (boost::asio::io_service& service, const boost::asio::ip::address& address,
int port, i2p::data::RouterInfo& in_RouterInfo):
NTCPSession (service, in_RouterInfo),
m_Endpoint (address, port)
NTCPSession (service, &in_RouterInfo), m_Endpoint (address, port)
{
Connect ();
}
@ -614,7 +619,8 @@ namespace transport @@ -614,7 +619,8 @@ namespace transport
LogPrint ("Connect error: ", ecode.message ());
if (ecode != boost::asio::error::operation_aborted)
{
GetRemoteRouterInfo ().SetUnreachable (true);
if (GetRemoteRouterInfo ())
GetRemoteRouterInfo ()->SetUnreachable (true);
Terminate ();
}
}

13
NTCPSession.h

@ -71,12 +71,13 @@ namespace transport @@ -71,12 +71,13 @@ namespace transport
{
public:
NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo& in_RemoteRouterInfo);
NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo * in_RemoteRouterInfo = nullptr);
virtual ~NTCPSession ();
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
bool IsEstablished () const { return m_IsEstablished; };
i2p::data::RouterInfo& GetRemoteRouterInfo () { return m_RemoteRouterInfo; };
i2p::data::RouterInfo * GetRemoteRouterInfo () { return m_RemoteRouterInfo; };
const i2p::data::IdentityEx& GetRemoteRouterIdentity () { return m_RemoteRouterIdentity; };
void ClientLogin ();
void ServerLogin ();
@ -134,7 +135,7 @@ namespace transport @@ -134,7 +135,7 @@ namespace transport
i2p::crypto::CBCEncryption m_Encryption;
CryptoPP::Adler32 m_Adler;
i2p::data::RouterInfo& m_RemoteRouterInfo;
i2p::data::RouterInfo * m_RemoteRouterInfo;
i2p::data::IdentityEx m_RemoteRouterIdentity;
struct Establisher
@ -176,15 +177,11 @@ namespace transport @@ -176,15 +177,11 @@ namespace transport
public:
NTCPServerConnection (boost::asio::io_service& service):
NTCPSession (service, m_DummyRemoteRouterInfo) {};
NTCPSession (service) {};
protected:
virtual void Connected ();
private:
i2p::data::RouterInfo m_DummyRemoteRouterInfo;
};
}
}

4
Transports.cpp

@ -184,13 +184,13 @@ namespace transport @@ -184,13 +184,13 @@ namespace transport
void Transports::AddNTCPSession (NTCPSession * session)
{
if (session)
m_NTCPSessions[session->GetRemoteRouterInfo ().GetIdentHash ()] = session;
m_NTCPSessions[session->GetRemoteRouterIdentity ().GetIdentHash ()] = session;
}
void Transports::RemoveNTCPSession (NTCPSession * session)
{
if (session)
m_NTCPSessions.erase (session->GetRemoteRouterInfo ().GetIdentHash ());
m_NTCPSessions.erase (session->GetRemoteRouterIdentity ().GetIdentHash ());
}
void Transports::HandleAccept (NTCPServerConnection * conn, const boost::system::error_code& error)

Loading…
Cancel
Save