Skip to content

Commit

Permalink
Merge #1579: [Net] Use SeedSpec6's rather than CAddress's for fixed s…
Browse files Browse the repository at this point in the history
…eeds

df48b12 chainparams: use SeedSpec6's rather than CAddress's for fixed seeds (Cory Fields)

Pull request description:

  Part of #1374's goal of updating our network code

  > This negates the need for CAddress here at all

ACKs for top commit:
  random-zebra:
    utACK df48b12
  furszy:
    utACK df48b12

Tree-SHA512: 86c2fb22118ab8d2a0b00bf44e76ac2230ece9395153ddc64203ca4a9585cfad0e9077dcaf5d69ca86c356a0f390a83c2f11cec8a0683c53aaf69f4cadc81dfe
  • Loading branch information
furszy committed May 8, 2020
2 parents 78a2923 + df48b12 commit e941230
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
43 changes: 12 additions & 31 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "libzerocoin/Params.h"
#include "chainparams.h"

#include "chainparamsseeds.h"
#include "consensus/merkle.h"
#include "random.h"
#include "util.h"
#include "utilstrencodings.h"

#include <assert.h>

#include <boost/assign/list_of.hpp>
#include <limits>

#include "chainparamsseeds.h"
#include <assert.h>

std::string CDNSSeedData::getHost(uint64_t requiredServiceBits) const {
//use default host for non-filter-capable seeds or if we use the default service bits (NODE_NETWORK)
Expand Down Expand Up @@ -68,29 +65,13 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
/**
* 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?
// + Is surrounded by blocks with reasonable timestamps
// (no blocks before with a timestamp after, none after with
// timestamp before)
// + Contains no strange transactions
/**
* What makes a good checkpoint block?
* + Is surrounded by blocks with reasonable timestamps
* (no blocks before with a timestamp after, none after with
* timestamp before)
* + Contains no strange transactions
*/
static Checkpoints::MapCheckpoints mapCheckpoints =
boost::assign::map_list_of
(259201, uint256S("1c9121bf9329a6234bfd1ea2d91515f19cd96990725265253f4b164283ade5dd"))
Expand Down Expand Up @@ -242,7 +223,7 @@ class CMainParams : public CChainParams
// BIP44 coin type is from https://github.com/satoshilabs/slips/blob/master/slip-0044.md
base58Prefixes[EXT_COIN_TYPE] = boost::assign::list_of(0x80)(0x00)(0x00)(0x77).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));
}

const Checkpoints::CCheckpointData& Checkpoints() const
Expand Down Expand Up @@ -360,7 +341,7 @@ class CTestNetParams : public CMainParams
// Testnet pivx BIP44 coin type is '1' (All coin's testnet default)
base58Prefixes[EXT_COIN_TYPE] = boost::assign::list_of(0x80)(0x00)(0x00)(0x01).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));
}

const Checkpoints::CCheckpointData& Checkpoints() const
Expand Down
4 changes: 2 additions & 2 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CChainParams
std::string NetworkIDString() const { return strNetworkID; }
const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
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;

CBaseChainParams::Network NetworkID() const { return networkID; }
Expand All @@ -89,7 +89,7 @@ class CChainParams
int nDefaultPort;
std::vector<CDNSSeedData> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
std::vector<CAddress> vFixedSeeds;
std::vector<SeedSpec6> vFixedSeeds;
};

/**
Expand Down
22 changes: 21 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ bool GetLocal(CService& addr, const CNetAddr* paddrPeer)
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
// Otherwise, return the unroutable 0.0.0.0 but filled in with
// the normal parameters, since the IP may be changed to a useful
Expand Down Expand Up @@ -1371,7 +1391,7 @@ void ThreadOpenConnections()
static bool done = false;
if (!done) {
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;
}
}
Expand Down

0 comments on commit e941230

Please sign in to comment.