diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2012-04-11 12:38:03 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2012-04-12 12:11:56 -0400 |
commit | 93e447b631440aee505a7c884a59c0885f9d968c (patch) | |
tree | f181ad15e894d774e2a0a505bf3b8dbcc9594a63 /src | |
parent | 940e22fd81af29dee6c07e413de1b446a21712b0 (diff) |
BIP 0031: pong message
Add a pong message that is sent in reply to a ping. It echoes back a nonce
field that is now added to the ping message. Send a nonce of zero in ping
messages.
Original author: Mike Hearn @ Google
Modified Mike's change to introduce a mild form of protocol documentation in
version.h.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 28 | ||||
-rw-r--r-- | src/version.h | 3 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index b9c9db7a62..fbe9232ac0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2652,6 +2652,23 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "ping") { + if (pfrom->nVersion > BIP0031_VERSION) + { + uint64 nonce = 0; + vRecv >> nonce; + // Echo the message back with the nonce. This allows for two useful features: + // + // 1) A remote node can quickly check if the connection is operational + // 2) Remote nodes can measure the latency of the network thread. If this node + // is overloaded it won't respond to pings quickly and the remote node can + // avoid sending us more work, like chain download requests. + // + // The nonce stops the remote getting confused between different pings: without + // it, if the remote node sends a ping once per second and this node takes 5 + // seconds to respond to each, the 5th ping the remote sends would appear to + // return very quickly. + pfrom->PushMessage("pong", nonce); + } } @@ -2814,9 +2831,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pto->nVersion == 0) return true; - // Keep-alive ping - if (pto->nLastSend && GetTime() - pto->nLastSend > 30 * 60 && pto->vSend.empty()) - pto->PushMessage("ping"); + // Keep-alive ping. We send a nonce of zero because we don't use it anywhere + // right now. + if (pto->nLastSend && GetTime() - pto->nLastSend > 30 * 60 && pto->vSend.empty()) { + if (pto->nVersion > BIP0031_VERSION) + pto->PushMessage("ping", 0); + else + pto->PushMessage("ping"); + } // Resend wallet transactions that haven't gotten in a block yet ResendWalletTransactions(); diff --git a/src/version.h b/src/version.h index c93b28fb7d..e0e216aad4 100644 --- a/src/version.h +++ b/src/version.h @@ -11,4 +11,7 @@ extern const std::string CLIENT_BUILD; extern const std::string CLIENT_DATE; extern const int CLIENT_VERSION; +// BIP 0031, pong message, is enabled for all versions AFTER this one +const int BIP0031_VERSION = 60000; + #endif |