Browse Source

incoming ipv6 connections

pull/106/head
orignal 10 years ago
parent
commit
f2434d66fc
  1. 5
      HTTPServer.cpp
  2. 2
      NTCPSession.cpp
  3. 1
      README.md
  4. 30
      RouterContext.cpp
  5. 2
      RouterContext.h
  6. 33
      Transports.cpp
  7. 3
      Transports.h

5
HTTPServer.cpp

@ -644,7 +644,10 @@ namespace util
switch (address.transportStyle) switch (address.transportStyle)
{ {
case i2p::data::RouterInfo::eTransportNTCP: case i2p::data::RouterInfo::eTransportNTCP:
s << "NTCP&nbsp;&nbsp;"; if (address.host.is_v6 ())
s << "NTCP6&nbsp;&nbsp;";
else
s << "NTCP&nbsp;&nbsp;";
break; break;
case i2p::data::RouterInfo::eTransportSSU: case i2p::data::RouterInfo::eTransportSSU:
s << "SSU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; s << "SSU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

2
NTCPSession.cpp

@ -623,6 +623,8 @@ namespace transport
else else
{ {
LogPrint ("Connected"); LogPrint ("Connected");
if (GetSocket ().local_endpoint ().protocol () == boost::asio::ip::tcp::v6()) // ipv6
context.UpdateV6Address (GetSocket ().local_endpoint ().address ().to_string ());
ClientLogin (); ClientLogin ();
} }
} }

1
README.md

@ -51,6 +51,7 @@ Options
* --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no. * --daemon= - Enable or disable daemon mode. 1 for yes, 0 for no.
* --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd). * --service= - 1 if uses system folders (/var/run/i2pd.pid, /var/log/i2pd.log, /var/lib/i2pd).
* --unreachable= - 1 if router is declared as unreachable and works through introducers. * --unreachable= - 1 if router is declared as unreachable and works through introducers.
* --v6= - 1 if supports communication through ipv6, off by default
* --httpproxyport= - The port to listen on (HTTP Proxy) * --httpproxyport= - The port to listen on (HTTP Proxy)
* --socksproxyport= - The port to listen on (SOCKS Proxy) * --socksproxyport= - The port to listen on (SOCKS Proxy)
* --ircport= - The local port of IRC tunnel to listen on. 6668 by default * --ircport= - The local port of IRC tunnel to listen on. 6668 by default

30
RouterContext.cpp

@ -139,6 +139,36 @@ namespace i2p
m_RouterInfo.DisableV6 (); m_RouterInfo.DisableV6 ();
} }
void RouterContext::UpdateV6Address (const std::string& host)
{
bool updated = false, found = false;
int port = 0;
auto newAddress = boost::asio::ip::address::from_string (host);
auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr : addresses)
{
if (addr.host.is_v6 ())
{
if (addr.host != newAddress)
{
addr.host = newAddress;
updated = true;
}
found = true;
}
else
port = addr.port;
}
if (!found)
{
// create new address
m_RouterInfo.AddNTCPAddress (host.c_str (), port);
updated = true;
}
if (updated)
UpdateRouterInfo ();
}
bool RouterContext::Load () bool RouterContext::Load ()
{ {
std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in); std::ifstream fk (i2p::util::filesystem::GetFullPath (ROUTER_KEYS).c_str (), std::ifstream::binary | std::ofstream::in);

2
RouterContext.h

@ -2,6 +2,7 @@
#define ROUTER_CONTEXT_H__ #define ROUTER_CONTEXT_H__
#include <inttypes.h> #include <inttypes.h>
#include <string>
#include <cryptopp/dsa.h> #include <cryptopp/dsa.h>
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include "Identity.h" #include "Identity.h"
@ -34,6 +35,7 @@ namespace i2p
void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; }; void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; };
bool SupportsV6 () const { return m_RouterInfo.IsV6 (); }; bool SupportsV6 () const { return m_RouterInfo.IsV6 (); };
void SetSupportsV6 (bool supportsV6); void SetSupportsV6 (bool supportsV6);
void UpdateV6Address (const std::string& host); // called from NTCP session
// implements LocalDestination // implements LocalDestination
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };

33
Transports.cpp

@ -96,7 +96,7 @@ namespace transport
Transports transports; Transports transports;
Transports::Transports (): Transports::Transports ():
m_Thread (nullptr), m_Work (m_Service), m_NTCPAcceptor (nullptr), m_Thread (nullptr), m_Work (m_Service), m_NTCPAcceptor (nullptr), m_NTCPV6Acceptor (nullptr),
m_SSUServer (nullptr), m_DHKeysPairSupplier (5) // 5 pre-generated keys m_SSUServer (nullptr), m_DHKeysPairSupplier (5) // 5 pre-generated keys
{ {
} }
@ -124,6 +124,17 @@ namespace transport
auto conn = new NTCPServerConnection (m_Service); auto conn = new NTCPServerConnection (m_Service);
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this, m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
conn, boost::asio::placeholders::error)); conn, boost::asio::placeholders::error));
if (context.SupportsV6 ())
{
m_NTCPV6Acceptor = new boost::asio::ip::tcp::acceptor (m_Service,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v6(), address.port));
LogPrint ("Start listening V6 TCP port ", address.port);
auto conn = new NTCPServerConnection (m_Service);
m_NTCPV6Acceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAcceptV6,
this, conn, boost::asio::placeholders::error));
}
} }
else if (address.transportStyle == RouterInfo::eTransportSSU) else if (address.transportStyle == RouterInfo::eTransportSSU)
{ {
@ -154,6 +165,8 @@ namespace transport
m_NTCPSessions.clear (); m_NTCPSessions.clear ();
delete m_NTCPAcceptor; delete m_NTCPAcceptor;
m_NTCPAcceptor = nullptr; m_NTCPAcceptor = nullptr;
delete m_NTCPV6Acceptor;
m_NTCPV6Acceptor = nullptr;
m_DHKeysPairSupplier.Stop (); m_DHKeysPairSupplier.Stop ();
m_IsRunning = false; m_IsRunning = false;
@ -211,6 +224,24 @@ namespace transport
} }
} }
void Transports::HandleAcceptV6 (NTCPServerConnection * conn, const boost::system::error_code& error)
{
if (!error)
{
LogPrint ("Connected from ", conn->GetSocket ().remote_endpoint().address ().to_string ());
conn->ServerLogin ();
}
else
delete conn;
if (error != boost::asio::error::operation_aborted)
{
conn = new NTCPServerConnection (m_Service);
m_NTCPV6Acceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAcceptV6, this,
conn, boost::asio::placeholders::error));
}
}
NTCPSession * Transports::GetNextNTCPSession () NTCPSession * Transports::GetNextNTCPSession ()
{ {
for (auto session: m_NTCPSessions) for (auto session: m_NTCPSessions)

3
Transports.h

@ -76,6 +76,7 @@ namespace transport
void Run (); void Run ();
void HandleAccept (NTCPServerConnection * conn, const boost::system::error_code& error); void HandleAccept (NTCPServerConnection * conn, const boost::system::error_code& error);
void HandleAcceptV6 (NTCPServerConnection * conn, const boost::system::error_code& error);
void HandleResendTimer (const boost::system::error_code& ecode, boost::asio::deadline_timer * timer, void HandleResendTimer (const boost::system::error_code& ecode, boost::asio::deadline_timer * timer,
const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
@ -89,7 +90,7 @@ namespace transport
std::thread * m_Thread; std::thread * m_Thread;
boost::asio::io_service m_Service; boost::asio::io_service m_Service;
boost::asio::io_service::work m_Work; boost::asio::io_service::work m_Work;
boost::asio::ip::tcp::acceptor * m_NTCPAcceptor; boost::asio::ip::tcp::acceptor * m_NTCPAcceptor, * m_NTCPV6Acceptor;
std::map<i2p::data::IdentHash, NTCPSession *> m_NTCPSessions; std::map<i2p::data::IdentHash, NTCPSession *> m_NTCPSessions;
SSUServer * m_SSUServer; SSUServer * m_SSUServer;

Loading…
Cancel
Save