Improve the 'network_id' configuration option:

The 'network_id' option allows an administrator to specify to which
network they intend a server to connect. Servers can leverage this
information to optimize routing and prune automatically discovered
cross-network connections.

This commit will, if merged:

- add support for the devnet keyword, which corresponds to network ID #2;
- report the network ID, if one is configured, in server_info
This commit is contained in:
Nik Bougalis
2019-12-22 22:10:50 -08:00
parent a96dc2ecea
commit 607328e1a0
5 changed files with 27 additions and 3 deletions

View File

@@ -2167,6 +2167,9 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin, bool counters)
if (human)
info [jss::hostid] = getHostId (admin);
if (auto const netid = app_.overlay().networkID())
info [jss::network_id] = static_cast<Json::UInt>(*netid);
info [jss::build_version] = BuildInfo::getVersionString ();
info [jss::server_state] = strOperatingMode (admin);

View File

@@ -253,6 +253,18 @@ public:
virtual
Json::Value
crawlShards(bool pubKey, std::uint32_t hops) = 0;
/** Returns the ID of the network this server is configured for, if any.
The ID is just a numerical identifier, with the IDs 0, 1 and 2 used to
identify the mainnet, the testnet and the devnet respectively.
@return The numerical identifier configured by the administrator of the
server. An unseated optional, otherwise.
*/
virtual
boost::optional<std::uint32_t>
networkID() const = 0;
};
struct ScoreHasLedger

View File

@@ -1328,14 +1328,17 @@ setup_Overlay (BasicConfig const& config)
if (id == "testnet")
id = "1";
if (id == "devnet")
id = "2";
setup.networkID = beast::lexicalCastThrow<std::uint32_t>(id);
}
}
catch (...)
{
Throw<std::runtime_error>(
"Configured [network_id] section is invalid: "
"must be a number or one of the strings 'main' or 'testnet'");
"Configured [network_id] section is invalid: must be a number "
"or one of the strings 'main', 'testnet' or 'devnet'.");
}
return setup;

View File

@@ -359,10 +359,15 @@ public:
return peerDisconnectsCharges_;
}
boost::optional<std::uint32_t>
networkID() const override
{
return networkID_;
}
Json::Value
crawlShards(bool pubKey, std::uint32_t hops) override;
/** Called when the last link from a peer chain is received.
@param id peer id that received the shard info.

View File

@@ -351,6 +351,7 @@ JSS ( missingCommand ); // error
JSS ( name ); // out: AmendmentTableImpl, PeerImp
JSS ( needed_state_hashes ); // out: InboundLedger
JSS ( needed_transaction_hashes ); // out: InboundLedger
JSS ( network_id ); // out: NetworkOPs
JSS ( network_ledger ); // out: NetworkOPs
JSS ( next_refresh_time ); // out: ValidatorSite
JSS ( no_ripple ); // out: AccountLines