Skip to content

Commit

Permalink
Okay, we have tiered MIN_PEERS now. Hacky way to solve not starting w…
Browse files Browse the repository at this point in the history
…ith enough peers and 29th of Nov 0:00 UTC
  • Loading branch information
EmberCoin committed Oct 26, 2017
1 parent 11da068 commit 2162465
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2963,8 +2963,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CAddress addrFrom;
uint64_t nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
{

int64_t currTime = GetTime();
int MinPeerVersion = MIN_PEER_PROTO_VERSION_BEFORE;
if (currTime >= MIN_PEER_PROTO_VERSION_WHEN) {
MinPeerVersion = MIN_PEER_PROTO_VERSION;
}

if (pfrom->nVersion < MinPeerVersion) {
// disconnect from peers older than this proto version
LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion);
pfrom->fDisconnect = true;
Expand Down
16 changes: 15 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ using namespace std;
using namespace boost;

static const int MAX_OUTBOUND_CONNECTIONS = 4098;
bool run_once = true;
bool did_run = false;

bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);

Expand Down Expand Up @@ -863,7 +865,7 @@ void ThreadSocketHandler()
}

//
// Inactivity checking
// Inactivity checking, and version checking
//
int64_t nTime = GetTime();
if (nTime - pnode->nTimeConnected > 60)
Expand All @@ -889,12 +891,24 @@ void ThreadSocketHandler()
pnode->fDisconnect = true;
}
}
// 5 minutes after the MIN_PEER changeover, get rid of old peers
if (run_once && nTime >= (MIN_PEER_PROTO_VERSION_WHEN+(60*5))) {
did_run = true;
if (pnode->nVersion < MIN_PEER_PROTO_VERSION) {
pnode->fDisconnect = true;
}
}
}

{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodesCopy)
pnode->Release();
}

if (did_run) {
run_once = false; // outside of loop nodes, if we got rid of min_peers then don't run after that.
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const std::string CLIENT_NAME("Ember");
#define GIT_ARCHIVE 1
#ifdef GIT_ARCHIVE
# define GIT_COMMIT_ID "v1.1.5.0" // More informative with version number at this time.
# define GIT_COMMIT_DATE "Oct 15, 2017"
# define GIT_COMMIT_DATE "Oct 26, 2017"
#endif

#define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \
Expand Down
7 changes: 5 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ static const int PROTOCOL_VERSION = 77780;
// intial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 210;

// disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 77779;
// disconnect from peers older than this proto version,
// Authoritative value is now _BEFORE, then a switch happens to MIN_PEER_PROTO_VERSION by epoch time specified by _WHEN
static const int MIN_PEER_PROTO_VERSION = 77778;
static const int MIN_PEER_PROTO_VERSION_BEFORE = 77776;
static const int MIN_PEER_PROTO_VERSION_WHEN = 1509235200; // Sunday, October 29, 2017 12:00:00 AM UTC

// nTime field added to CAddress, starting with this version;
// if possible, avoid requesting addresses nodes older than this
Expand Down

0 comments on commit 2162465

Please sign in to comment.