Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addrv2 BIP155 support #101

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class CNode {
if (nVersion >= 209 && !vRecv.empty())
vRecv >> nStartingHeight;

if (nVersion >= 70016) {
BeginMessage("sendaddrv2");
EndMessage();
}
if (nVersion >= 209) {
BeginMessage("verack");
EndMessage();
Expand All @@ -130,10 +134,15 @@ class CNode {
GotVersion();
return false;
}

if (strCommand == "addr" && vAddr) {

bool addrv2 = strCommand == "addrv2";

if ((strCommand == "addr" || addrv2) && vAddr) {
if (addrv2)
vRecv.nVersion |= ADDRV2_FORMAT;
vector<CAddress> vAddrNew;
vRecv >> vAddrNew;
vRecv.nVersion &= ~ADDRV2_FORMAT;
// printf("%s: got %i addresses\n", ToString(you).c_str(), (int)vAddrNew.size());
int64 now = time(NULL);
vector<CAddress>::iterator it = vAddrNew.begin();
Expand Down
19 changes: 10 additions & 9 deletions db.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class CAddrStat {
weight = weight * f + (1.0-f);
}

IMPLEMENT_SERIALIZE (
IMPLEMENT_SERIALIZE {
READWRITE(weight);
READWRITE(count);
READWRITE(reliability);
)
}

friend class CAddrInfo;
};
Expand Down Expand Up @@ -101,7 +101,8 @@ class CAddrInfo {
}

bool IsGood() const {
if (ip.GetPort() != GetDefaultPort()) return false;
if (ip.GetPort() != GetDefaultPort() && !ip.IsI2P())
return false;
if (!(services & NODE_NETWORK)) return false;
if (!ip.IsRoutable()) return false;
if (clientVersion && clientVersion < REQUIRE_VERSION) return false;
Expand Down Expand Up @@ -138,7 +139,7 @@ class CAddrInfo {

friend class CAddrDb;

IMPLEMENT_SERIALIZE (
IMPLEMENT_SERIALIZE {
unsigned char version = 4;
READWRITE(version);
READWRITE(ip);
Expand Down Expand Up @@ -168,7 +169,7 @@ class CAddrInfo {
if (version >= 4)
READWRITE(ourLastSuccess);
}
)
}
};

class CAddrDbStats {
Expand Down Expand Up @@ -263,9 +264,9 @@ class CAddrDb {
// banned
// acquires a shared lock (this does not suffice for read mode, but we assume that only happens at startup, single-threaded)
// this way, dumping does not interfere with GetIPs_, which is called from the DNS thread
IMPLEMENT_SERIALIZE (({
int nVersion = 0;
READWRITE(nVersion);
IMPLEMENT_SERIALIZE {
int version = 0;
READWRITE(version);
SHARED_CRITICAL_BLOCK(cs) {
if (fWrite) {
CAddrDb *db = const_cast<CAddrDb*>(this);
Expand Down Expand Up @@ -303,7 +304,7 @@ class CAddrDb {
}
READWRITE(banned);
}
});)
}

void Add(const CAddress &addr, bool fForce = false) {
CRITICAL_BLOCK(cs)
Expand Down
29 changes: 15 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ extern "C" void* ThreadDumper(void*) {
FILE *f = fopen("dnsseed.dat.new","w+");
if (f) {
{
CAutoFile cf(f);
CAutoFile cf(f, SER_DISK, PROTOCOL_VERSION | ADDRV2_FORMAT);
cf << db;
}
rename("dnsseed.dat.new", "dnsseed.dat");
Expand Down Expand Up @@ -418,24 +418,25 @@ extern "C" void* ThreadStats(void*) {
return nullptr;
}

static const string mainnet_seeds[] = {"dnsseed.bluematt.me", "bitseed.xf2.org", "dnsseed.bitcoin.dashjr.org", "seed.bitcoin.sipa.be", ""};
static const string testnet_seeds[] = {"testnet-seed.alexykot.me",
"testnet-seed.bitcoin.petertodd.org",
"testnet-seed.bluematt.me",
"testnet-seed.bitcoin.schildbach.de",
static const string mainnet_seeds[] = {"dnsseed.bluematt.me:8333", "bitseed.xf2.org:8333", "dnsseed.bitcoin.dashjr.org:8333", "seed.bitcoin.sipa.be:8333",
"rp7k2go3s5lyj3fnj6zn62ktarlrsft2ohlsxkyd7v3e3idqyptvread.onion:8333",
"qd6jlsevsexww3wefpqs7iglxb3f63y4e6ydulfzrvwflpicmdqa.b32.i2p:0",
"[fcc7:be49:ccd1:dc91:3125:f0da:457d:8ce]:8333",
""};
static const string testnet_seeds[] = {"testnet-seed.alexykot.me:18333",
"testnet-seed.bitcoin.petertodd.org:18333",
"testnet-seed.bluematt.me:18333",
"testnet-seed.bitcoin.schildbach.de:18333",
""};
static const string *seeds = mainnet_seeds;

extern "C" void* ThreadSeeder(void*) {
if (!fTestNet){
db.Add(CService("kjy2eqzk4zwi5zd3.onion", 8333), true);
}
do {
for (int i=0; seeds[i] != ""; i++) {
vector<CNetAddr> ips;
LookupHost(seeds[i].c_str(), ips);
for (vector<CNetAddr>::iterator it = ips.begin(); it != ips.end(); it++) {
db.Add(CService(*it, GetDefaultPort()), true);
vector<CService> ips;
Lookup(seeds[i].c_str(), ips, GetDefaultPort());
for (vector<CService>::iterator it = ips.begin(); it != ips.end(); it++) {
db.Add(*it, true);
}
}
Sleep(1800000);
Expand Down Expand Up @@ -502,7 +503,7 @@ int main(int argc, char **argv) {
FILE *f = fopen("dnsseed.dat","r");
if (f) {
printf("Loading dnsseed.dat...");
CAutoFile cf(f);
CAutoFile cf(f, SER_DISK, PROTOCOL_VERSION | ADDRV2_FORMAT);
cf >> db;
if (opts.fWipeBan)
db.banned.clear();
Expand Down
Loading