Browse Source

Merge pull request #6059

739d615 chainparams: use SeedSpec6's rather than CAddress's for fixed seeds (Cory Fields)
0.13
Wladimir J. van der Laan 10 years ago
parent
commit
f026ab606d
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 29
      src/chainparams.cpp
  2. 10
      src/chainparams.h
  3. 23
      src/net.cpp

29
src/chainparams.cpp

@ -5,7 +5,6 @@
#include "chainparams.h" #include "chainparams.h"
#include "random.h"
#include "util.h" #include "util.h"
#include "utilstrencodings.h" #include "utilstrencodings.h"
@ -15,35 +14,11 @@
using namespace std; using namespace std;
struct SeedSpec6 {
uint8_t addr[16];
uint16_t port;
};
#include "chainparamsseeds.h" #include "chainparamsseeds.h"
/** /**
* Main network * Main network
*/ */
//! Convert the pnSeeds6 array into usable address objects.
static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data, unsigned int count)
{
// It'll only connect to one or two seed nodes because once it connects,
// it'll get a pile of addresses with newer timestamps.
// Seed nodes are given a random 'last seen time' of between one and two
// weeks ago.
const int64_t nOneWeek = 7*24*60*60;
for (unsigned int i = 0; i < count; i++)
{
struct in6_addr ip;
memcpy(&ip, data[i].addr, sizeof(ip));
CAddress addr(CService(ip, data[i].port));
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
vSeedsOut.push_back(addr);
}
}
/** /**
* What makes a good checkpoint block? * What makes a good checkpoint block?
* + Is surrounded by blocks with reasonable timestamps * + Is surrounded by blocks with reasonable timestamps
@ -164,7 +139,7 @@ public:
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >(); base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >(); base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main)); vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
fRequireRPCPassword = true; fRequireRPCPassword = true;
fMiningRequiresPeers = true; fMiningRequiresPeers = true;
@ -220,7 +195,7 @@ public:
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >(); base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >(); base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test)); vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
fRequireRPCPassword = true; fRequireRPCPassword = true;
fMiningRequiresPeers = true; fMiningRequiresPeers = true;

10
src/chainparams.h

@ -19,6 +19,12 @@ struct CDNSSeedData {
CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {} CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
}; };
struct SeedSpec6 {
uint8_t addr[16];
uint16_t port;
};
/** /**
* CChainParams defines various tweakable parameters of a given instance of the * CChainParams defines various tweakable parameters of a given instance of the
* Bitcoin system. There are three: the main network on which people trade goods * Bitcoin system. There are three: the main network on which people trade goods
@ -67,7 +73,7 @@ public:
std::string NetworkIDString() const { return strNetworkID; } std::string NetworkIDString() const { return strNetworkID; }
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; } const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; } const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0; virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
protected: protected:
CChainParams() {} CChainParams() {}
@ -83,7 +89,7 @@ protected:
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES]; std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
std::string strNetworkID; std::string strNetworkID;
CBlock genesis; CBlock genesis;
std::vector<CAddress> vFixedSeeds; std::vector<SeedSpec6> vFixedSeeds;
bool fRequireRPCPassword; bool fRequireRPCPassword;
bool fMiningRequiresPeers; bool fMiningRequiresPeers;
bool fDefaultConsistencyChecks; bool fDefaultConsistencyChecks;

23
src/net.cpp

@ -142,6 +142,27 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
return nBestScore >= 0; return nBestScore >= 0;
} }
//! Convert the pnSeeds6 array into usable address objects.
static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &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.
// Seed nodes are given a random 'last seen time' of between one and two
// weeks ago.
const int64_t nOneWeek = 7*24*60*60;
std::vector<CAddress> vSeedsOut;
vSeedsOut.reserve(vSeedsIn.size());
for (std::vector<SeedSpec6>::const_iterator i(vSeedsIn.begin()); i != vSeedsIn.end(); ++i)
{
struct in6_addr ip;
memcpy(&ip, i->addr, sizeof(ip));
CAddress addr(CService(ip, i->port));
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
vSeedsOut.push_back(addr);
}
return vSeedsOut;
}
// get best local address for a particular peer as a CAddress // get best local address for a particular peer as a CAddress
// Otherwise, return the unroutable 0.0.0.0 but filled in with // Otherwise, return the unroutable 0.0.0.0 but filled in with
// the normal parameters, since the IP may be changed to a useful // the normal parameters, since the IP may be changed to a useful
@ -1195,7 +1216,7 @@ void ThreadOpenConnections()
static bool done = false; static bool done = false;
if (!done) { if (!done) {
LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n"); LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
addrman.Add(Params().FixedSeeds(), CNetAddr("127.0.0.1")); addrman.Add(convertSeed6(Params().FixedSeeds()), CNetAddr("127.0.0.1"));
done = true; done = true;
} }
} }

Loading…
Cancel
Save