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

ignore messages sent before version handshake is complete #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CNode {
int ban;
int64 doneAfter;
CAddress you;
bool fGotVersion;
bool fGotVerAck;

int GetTimeout() {
if (you.IsTor())
Expand Down Expand Up @@ -99,6 +101,10 @@ class CNode {
bool ProcessMessage(string strCommand, CDataStream& vRecv) {
// printf("%s: RECV %s\n", ToString(you).c_str(), strCommand.c_str());
if (strCommand == "version") {
if (fGotVersion) {
// printf("%s: sent duplicate version\n", ToString(you).c_str());
return false;
}
int64 nTime;
CAddress addrMe;
CAddress addrFrom;
Expand All @@ -111,6 +117,7 @@ class CNode {
vRecv >> strSubVer;
if (nVersion >= 209 && !vRecv.empty())
vRecv >> nStartingHeight;
fGotVersion = true;

if (nVersion >= 209) {
BeginMessage("verack");
Expand All @@ -123,13 +130,28 @@ class CNode {
}
return false;
}

if (!fGotVersion) {
// printf("%s: sent %s before version\n", ToString(you).c_str(), strCommand.c_str());
return false;
}

if (strCommand == "verack") {
if (fGotVerAck) {
// printf("%s: sent duplicate verack\n", ToString(you).c_str());
return false;
}
fGotVerAck = true;
this->vRecv.SetVersion(min(nVersion, PROTOCOL_VERSION));
GotVersion();
return false;
}


if (nVersion >= 209 && !fGotVerAck) {
// printf("%s: sent %s before verack\n", ToString(you).c_str(), strCommand.c_str());
return false;
}

if (strCommand == "addr" && vAddr) {
vector<CAddress> vAddrNew;
vRecv >> vAddrNew;
Expand Down Expand Up @@ -211,6 +233,8 @@ class CNode {
vSend.SetVersion(209);
vRecv.SetVersion(209);
}
fGotVersion = false;
fGotVerAck = false;
}
bool Run() {
bool res = true;
Expand Down