Skip to content

Commit f026ab6

Browse files
committed
Merge pull request #6059
739d615 chainparams: use SeedSpec6's rather than CAddress's for fixed seeds (Cory Fields)
2 parents da38dc6 + 739d615 commit f026ab6

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
@@ -142,6 +142,27 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
142142
return nBestScore >= 0;
143143
}
144144

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

0 commit comments

Comments
 (0)