mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
net: Deserialize hardcoded seeds from BIP155 blob
Switch from IPv6 slot-based format to more compact and flexible BIP155 format.
This commit is contained in:
parent
9b29d5df7f
commit
b2ee8b207d
@ -134,7 +134,7 @@ public:
|
||||
|
||||
bech32_hrp = "bc";
|
||||
|
||||
vFixedSeeds = std::vector<SeedSpec6>(std::begin(pnSeed6_main), std::end(pnSeed6_main));
|
||||
vFixedSeeds = std::vector<uint8_t>(std::begin(chainparams_seed_main), std::end(chainparams_seed_main));
|
||||
|
||||
fDefaultConsistencyChecks = false;
|
||||
fRequireStandard = true;
|
||||
@ -239,7 +239,7 @@ public:
|
||||
|
||||
bech32_hrp = "tb";
|
||||
|
||||
vFixedSeeds = std::vector<SeedSpec6>(std::begin(pnSeed6_test), std::end(pnSeed6_test));
|
||||
vFixedSeeds = std::vector<uint8_t>(std::begin(chainparams_seed_test), std::end(chainparams_seed_test));
|
||||
|
||||
fDefaultConsistencyChecks = false;
|
||||
fRequireStandard = false;
|
||||
|
@ -14,11 +14,6 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
struct SeedSpec6 {
|
||||
uint8_t addr[16];
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
typedef std::map<int, uint256> MapCheckpoints;
|
||||
|
||||
struct CCheckpointData {
|
||||
@ -108,7 +103,7 @@ public:
|
||||
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
|
||||
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
|
||||
const std::string& Bech32HRP() const { return bech32_hrp; }
|
||||
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
|
||||
const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
|
||||
const CCheckpointData& Checkpoints() const { return checkpointData; }
|
||||
|
||||
//! Get allowed assumeutxo configuration.
|
||||
@ -130,7 +125,7 @@ protected:
|
||||
std::string bech32_hrp;
|
||||
std::string strNetworkID;
|
||||
CBlock genesis;
|
||||
std::vector<SeedSpec6> vFixedSeeds;
|
||||
std::vector<uint8_t> vFixedSeeds;
|
||||
bool fDefaultConsistencyChecks;
|
||||
bool fRequireStandard;
|
||||
bool m_is_test_chain;
|
||||
|
File diff suppressed because it is too large
Load Diff
17
src/net.cpp
17
src/net.cpp
@ -141,8 +141,8 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
|
||||
return nBestScore >= 0;
|
||||
}
|
||||
|
||||
//! Convert the pnSeed6 array into usable address objects.
|
||||
static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn)
|
||||
//! Convert the serialized seeds into usable address objects.
|
||||
static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
|
||||
{
|
||||
// It'll only connect to one or two seed nodes because once it connects,
|
||||
// it'll get a pile of addresses with newer timestamps.
|
||||
@ -150,13 +150,14 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn
|
||||
// weeks ago.
|
||||
const int64_t nOneWeek = 7*24*60*60;
|
||||
std::vector<CAddress> vSeedsOut;
|
||||
vSeedsOut.reserve(vSeedsIn.size());
|
||||
FastRandomContext rng;
|
||||
for (const auto& seed_in : vSeedsIn) {
|
||||
struct in6_addr ip;
|
||||
memcpy(&ip, seed_in.addr, sizeof(ip));
|
||||
CAddress addr(CService(ip, seed_in.port), GetDesirableServiceFlags(NODE_NONE));
|
||||
CDataStream s(vSeedsIn, SER_NETWORK, PROTOCOL_VERSION | ADDRV2_FORMAT);
|
||||
while (!s.eof()) {
|
||||
CService endpoint;
|
||||
s >> endpoint;
|
||||
CAddress addr{endpoint, GetDesirableServiceFlags(NODE_NONE)};
|
||||
addr.nTime = GetTime() - rng.randrange(nOneWeek) - nOneWeek;
|
||||
LogPrint(BCLog::NET, "Added hardcoded seed: %s\n", addr.ToString());
|
||||
vSeedsOut.push_back(addr);
|
||||
}
|
||||
return vSeedsOut;
|
||||
@ -1840,7 +1841,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
if (add_fixed_seeds_now) {
|
||||
CNetAddr local;
|
||||
local.SetInternal("fixedseeds");
|
||||
addrman.Add(convertSeed6(Params().FixedSeeds()), local);
|
||||
addrman.Add(ConvertSeeds(Params().FixedSeeds()), local);
|
||||
add_fixed_seeds = false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user