Skip to content

Commit 739d615

Browse files
committed
chainparams: use SeedSpec6's rather than CAddress's for fixed seeds
This negates the need for CAddress here at all
1 parent 1623f6e commit 739d615

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

src/chainparams.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "chainparams.h"
77

8-
#include "random.h"
98
#include "util.h"
109
#include "utilstrencodings.h"
1110

@@ -15,35 +14,11 @@
1514

1615
using namespace std;
1716

18-
struct SeedSpec6 {
19-
uint8_t addr[16];
20-
uint16_t port;
21-
};
22-
2317
#include "chainparamsseeds.h"
2418

2519
/**
2620
* Main network
2721
*/
28-
29-
//! Convert the pnSeeds6 array into usable address objects.
30-
static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data, unsigned int count)
31-
{
32-
// It'll only connect to one or two seed nodes because once it connects,
33-
// it'll get a pile of addresses with newer timestamps.
34-
// Seed nodes are given a random 'last seen time' of between one and two
35-
// weeks ago.
36-
const int64_t nOneWeek = 7*24*60*60;
37-
for (unsigned int i = 0; i < count; i++)
38-
{
39-
struct in6_addr ip;
40-
memcpy(&ip, data[i].addr, sizeof(ip));
41-
CAddress addr(CService(ip, data[i].port));
42-
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
43-
vSeedsOut.push_back(addr);
44-
}
45-
}
46-
4722
/**
4823
* What makes a good checkpoint block?
4924
* + Is surrounded by blocks with reasonable timestamps
@@ -164,7 +139,7 @@ class CMainParams : public CChainParams {
164139
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();
165140
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
166141

167-
convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main));
142+
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
168143

169144
fRequireRPCPassword = true;
170145
fMiningRequiresPeers = true;
@@ -220,7 +195,7 @@ class CTestNetParams : public CMainParams {
220195
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
221196
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
222197

223-
convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test));
198+
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
224199

225200
fRequireRPCPassword = true;
226201
fMiningRequiresPeers = true;

src/chainparams.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ struct CDNSSeedData {
1919
CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
2020
};
2121

22+
struct SeedSpec6 {
23+
uint8_t addr[16];
24+
uint16_t port;
25+
};
26+
27+
2228
/**
2329
* CChainParams defines various tweakable parameters of a given instance of the
2430
* Bitcoin system. There are three: the main network on which people trade goods
@@ -67,7 +73,7 @@ class CChainParams
6773
std::string NetworkIDString() const { return strNetworkID; }
6874
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
6975
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
70-
const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
76+
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
7177
virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
7278
protected:
7379
CChainParams() {}
@@ -83,7 +89,7 @@ class CChainParams
8389
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
8490
std::string strNetworkID;
8591
CBlock genesis;
86-
std::vector<CAddress> vFixedSeeds;
92+
std::vector<SeedSpec6> vFixedSeeds;
8793
bool fRequireRPCPassword;
8894
bool fMiningRequiresPeers;
8995
bool fDefaultConsistencyChecks;

src/net.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
141141
return nBestScore >= 0;
142142
}
143143

144+
//! Convert the pnSeeds6 array into usable address objects.
145+
static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn)
146+
{
147+
// It'll only connect to one or two seed nodes because once it connects,
148+
// it'll get a pile of addresses with newer timestamps.
149+
// Seed nodes are given a random 'last seen time' of between one and two
150+
// weeks ago.
151+
const int64_t nOneWeek = 7*24*60*60;
152+
std::vector<CAddress> vSeedsOut;
153+
vSeedsOut.reserve(vSeedsIn.size());
154+
for (std::vector<SeedSpec6>::const_iterator i(vSeedsIn.begin()); i != vSeedsIn.end(); ++i)
155+
{
156+
struct in6_addr ip;
157+
memcpy(&ip, i->addr, sizeof(ip));
158+
CAddress addr(CService(ip, i->port));
159+
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
160+
vSeedsOut.push_back(addr);
161+
}
162+
return vSeedsOut;
163+
}
164+
144165
// get best local address for a particular peer as a CAddress
145166
// Otherwise, return the unroutable 0.0.0.0 but filled in with
146167
// the normal parameters, since the IP may be changed to a useful
@@ -1192,7 +1213,7 @@ void ThreadOpenConnections()
11921213
static bool done = false;
11931214
if (!done) {
11941215
LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
1195-
addrman.Add(Params().FixedSeeds(), CNetAddr("127.0.0.1"));
1216+
addrman.Add(convertSeed6(Params().FixedSeeds()), CNetAddr("127.0.0.1"));
11961217
done = true;
11971218
}
11981219
}

0 commit comments

Comments
 (0)