From 99983798a47d4b880185223783a0184eb4934932 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 12 Oct 2016 11:26:48 -0400 Subject: [PATCH] configurable netid --- Config.cpp | 1 + I2NPProtocol.cpp | 2 +- RouterContext.cpp | 6 ++++-- RouterContext.h | 5 ++++- RouterInfo.cpp | 3 ++- docs/configuration.md | 1 + 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Config.cpp b/Config.cpp index f7e591be..924f244b 100644 --- a/Config.cpp +++ b/Config.cpp @@ -49,6 +49,7 @@ namespace config { ("port", value()->default_value(0), "Port to listen for incoming connections (default: auto)") ("ipv4", value()->zero_tokens()->default_value(true), "Enable communication through ipv4") ("ipv6", value()->zero_tokens()->default_value(false), "Enable communication through ipv6") + ("netid", value()->default_value(I2PD_NET_ID), "Specify NetID. Main I2P is 2") ("daemon", value()->zero_tokens()->default_value(false), "Router will go to background after start") ("service", value()->zero_tokens()->default_value(false), "Router will use system folders like '/var/lib/i2pd'") ("notransit", value()->zero_tokens()->default_value(false), "Router will not accept transit tunnels at startup") diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index cbd4c3fc..cdc4fb9b 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -102,7 +102,7 @@ namespace i2p { RAND_bytes ((uint8_t *)&msgID, 4); htobe32buf (buf + DELIVERY_STATUS_MSGID_OFFSET, msgID); - htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, I2PD_NET_ID); + htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, i2p::context.GetNetID ()); } m->len += DELIVERY_STATUS_SIZE; m->FillI2NPMessageHeader (eI2NPDeliveryStatus); diff --git a/RouterContext.cpp b/RouterContext.cpp index 6824adb8..b4bbefb6 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -18,7 +18,8 @@ namespace i2p RouterContext::RouterContext (): m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false), - m_StartupTime (0), m_Status (eRouterStatusOK), m_Error (eRouterErrorNone) + m_StartupTime (0), m_Status (eRouterStatusOK), m_Error (eRouterErrorNone), + m_NetID (I2PD_NET_ID) { } @@ -76,7 +77,8 @@ namespace i2p } routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC - routerInfo.SetProperty ("netId", std::to_string (I2PD_NET_ID)); + i2p::config::GetOption("netid", m_NetID); + routerInfo.SetProperty ("netId", std::to_string (m_NetID)); routerInfo.SetProperty ("router.version", I2P_VERSION); routerInfo.CreateBuffer (m_Keys); m_RouterInfo.SetRouterIdentity (GetIdentity ()); diff --git a/RouterContext.h b/RouterContext.h index b89b3140..7ce310ee 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -58,7 +58,9 @@ namespace i2p void SetStatus (RouterStatus status); RouterError GetError () const { return m_Error; }; void SetError (RouterError error) { m_Status = eRouterStatusError; m_Error = error; }; - + int GetNetID () const { return m_NetID; }; + void SetNetID (int netID) { m_NetID = netID; }; + void UpdatePort (int port); // called from Daemon void UpdateAddress (const boost::asio::ip::address& host); // called from SSU or Daemon bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer); @@ -117,6 +119,7 @@ namespace i2p uint32_t m_BandwidthLimit; // allowed bandwidth RouterStatus m_Status; RouterError m_Error; + int m_NetID; std::mutex m_GarlicMutex; }; diff --git a/RouterInfo.cpp b/RouterInfo.cpp index f445ca02..b570d6c2 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -13,6 +13,7 @@ #include "Timestamp.h" #include "Log.h" #include "NetDb.h" +#include "RouterContext.h" #include "RouterInfo.h" namespace i2p @@ -286,7 +287,7 @@ namespace data if (!strcmp (key, "caps")) ExtractCaps (value); // check netId - else if (!strcmp (key, ROUTER_INFO_PROPERTY_NETID) && atoi (value) != I2PD_NET_ID) + else if (!strcmp (key, ROUTER_INFO_PROPERTY_NETID) && atoi (value) != i2p::context.GetNetID ()) { LogPrint (eLogError, "RouterInfo: Unexpected ", ROUTER_INFO_PROPERTY_NETID, "=", value); m_IsUnreachable = true; diff --git a/docs/configuration.md b/docs/configuration.md index 0a774ab9..49d8c98d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -25,6 +25,7 @@ If you are upgrading your very old router (< 2.3.0) see also [this](config_opts_ * --floodfill - Router will be floodfill. false by default * --bandwidth= - Bandwidth limit: integer in KBps or letters: L (32), O (256), P (2048), X (>9000) * --family= - Name of a family, router belongs to +* --netid= - Network ID, router belongs to. Main I2P is 2. Windows-specific options: