Permalink
Browse files

Add network-magic user-configuration options.

 -initiatecashconnections
    When using the BitcoinCash network, initiate connections only Cash
nodes understand. (default: false)
 -flexiblehandshake
    Allow connections from the legacy network when using the BitcoinCash
network, or vice-versa. (default: true)

Additionally a little fix that moves the sending of the version message
out of the constructor and into the one place that creates outgoing
connections.
  • Loading branch information...
zander committed Jul 30, 2017
1 parent d893b7e commit aaa6ba45bfeb10d82e0564267c8ac1d18d2eabcf
Showing with 14 additions and 5 deletions.
  1. +2 −0 src/allowed_args.cpp
  2. +8 −0 src/main.cpp
  3. +4 −5 src/net.cpp
View
@@ -292,6 +292,8 @@ static void addConnectionOptions(AllowedArgs& allowedArgs)
.addArg("whitelistrelay", optionalBool, strprintf(_("Accept relayed transactions received from whitelisted peers even when not relaying transactions (default: %d)"), DEFAULT_WHITELISTRELAY))
.addArg("whitelistforcerelay", optionalBool, strprintf(_("Force relay of transactions from whitelisted peers even they violate local relay policy (default: %d)"), DEFAULT_WHITELISTFORCERELAY))
.addArg("maxuploadtarget=<n>", requiredInt, strprintf(_("Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d)"), DEFAULT_MAX_UPLOAD_TARGET))
.addArg("initiatecashconnections", optionalBool, "When using the BitcoinCash network, initiate connections only Cash nodes understand. (default: false)")
.addArg("flexiblehandshake", optionalBool, "Allow connections from the legacy network when using the BitcoinCash network, or vice-versa. (default: true)")
;
}
View
@@ -5470,6 +5470,14 @@ bool ProcessMessages(CNode* pfrom)
}
pfrom->isCashNode = true;
}
if (GetBoolArg("-flexiblehandshake", true) == false) {
// ignore clients that are not using our our net magic headers.
if (pfrom->isCashNode != (Application::uahfChainState() != Application::UAHFDisabled)) {
fOk = false;
break;
}
}
}
else {
if (memcmp(msg.hdr.pchMessageStart, pfrom->magic(), MESSAGE_START_SIZE) != 0) {
View
@@ -409,8 +409,11 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
// Add node
CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false);
pnode->AddRef();
if (GetBoolArg("-initiatecashconnections", false) && Application::uahfChainState() >= Application::UAHFRulesActive)
pnode->isCashNode = true;
pnode->PushVersion();
pnode->AddRef();
{
LOCK(cs_vNodes);
vNodes.push_back(pnode);
@@ -2498,10 +2501,6 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
else
logDebug(Log::Net) << "Added connection peer" << id;
// Be shy and don't send version until we hear
if (hSocket != INVALID_SOCKET && !fInbound)
PushVersion();
GetNodeSignals().InitializeNode(GetId(), this);
}

0 comments on commit aaa6ba4

Please sign in to comment.