diff options
Diffstat (limited to 'src/net.h')
| -rw-r--r-- | src/net.h | 42 |
1 files changed, 41 insertions, 1 deletions
| @@ -69,6 +69,21 @@ static const int BTF_HANDSHAKE_GRACE_SECS = 60; | |||
| 69 | // stay well under BTF_RECV_TIMEOUT_SECS. | 69 | // stay well under BTF_RECV_TIMEOUT_SECS. |
| 70 | static const int BTF_PING_INTERVAL_SECS = 10 * 60; | 70 | static const int BTF_PING_INTERVAL_SECS = 10 * 60; |
| 71 | 71 | ||
| 72 | // How long a node must stay behind the network before it says so, and how | ||
| 73 | // often it repeats itself. Five minutes is two and a half block intervals -- | ||
| 74 | // long enough that ordinary relay lag never trips it. | ||
| 75 | static const int BTF_BEHIND_GRACE_SECS = 5 * 60; | ||
| 76 | static const int BTF_BEHIND_WARN_INTERVAL_SECS = 5 * 60; | ||
| 77 | |||
| 78 | // Defined in main.cpp. Declared here because CNode announces it in the version | ||
| 79 | // message, and net.h is included before main.h. | ||
| 80 | extern int nBestHeight; | ||
| 81 | |||
| 82 | // Median height announced by the peers we are connected to, or -1 while nobody | ||
| 83 | // has told us anything. Median rather than maximum so one peer claiming an | ||
| 84 | // absurd height cannot move it. | ||
| 85 | int GetPeerMedianHeight(); | ||
| 86 | |||
| 72 | // Descriptors to hand a peer: ours first, then peers that answered us. | 87 | // Descriptors to hand a peer: ours first, then peers that answered us. |
| 73 | void BtfPexCollect(std::vector<std::string>& vDescOut); | 88 | void BtfPexCollect(std::vector<std::string>& vDescOut); |
| 74 | // Verify descriptors a peer sent and remember the good ones. Returns how many. | 89 | // Verify descriptors a peer sent and remember the good ones. Returns how many. |
| @@ -528,6 +543,11 @@ public: | |||
| 528 | int64 nLastRecv; | 543 | int64 nLastRecv; |
| 529 | int64 nLastSendEmpty; | 544 | int64 nLastSendEmpty; |
| 530 | 545 | ||
| 546 | // Height this peer announced in its version message, or -1 if it sent a | ||
| 547 | // version message that predates the field. Knowing how far along everyone | ||
| 548 | // else is, is the only way a node can tell "in sync" from "not hearing". | ||
| 549 | int nStartingHeight; | ||
| 550 | |||
| 531 | 551 | ||
| 532 | CNode(SOCKET hSocketIn, CAddress addrIn, bool fInboundIn=false) | 552 | CNode(SOCKET hSocketIn, CAddress addrIn, bool fInboundIn=false) |
| 533 | { | 553 | { |
| @@ -549,12 +569,16 @@ public: | |||
| 549 | nLastSend = 0; | 569 | nLastSend = 0; |
| 550 | nLastRecv = 0; | 570 | nLastRecv = 0; |
| 551 | nLastSendEmpty = GetTime(); | 571 | nLastSendEmpty = GetTime(); |
| 572 | nStartingHeight = -1; | ||
| 552 | vfSubscribe.assign(256, false); | 573 | vfSubscribe.assign(256, false); |
| 553 | 574 | ||
| 554 | // Push a version message | 575 | // Push a version message |
| 555 | /// when NTP implemented, change to just nTime = GetAdjustedTime() | 576 | /// when NTP implemented, change to just nTime = GetAdjustedTime() |
| 556 | int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); | 577 | int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); |
| 557 | PushMessage("version", VERSION, nLocalServices, nTime, addr); | 578 | // nBestHeight goes last so a node that predates it stops reading after |
| 579 | // addr and treats the rest as trailing bytes, which cost it a log line | ||
| 580 | // and nothing else. | ||
| 581 | PushMessage("version", VERSION, nLocalServices, nTime, addr, nBestHeight); | ||
| 558 | } | 582 | } |
| 559 | 583 | ||
| 560 | ~CNode() | 584 | ~CNode() |
| @@ -771,6 +795,22 @@ public: | |||
| 771 | } | 795 | } |
| 772 | } | 796 | } |
| 773 | 797 | ||
| 798 | template<typename T1, typename T2, typename T3, typename T4, typename T5> | ||
| 799 | void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5) | ||
| 800 | { | ||
| 801 | try | ||
| 802 | { | ||
| 803 | BeginMessage(pszCommand); | ||
| 804 | vSend << a1 << a2 << a3 << a4 << a5; | ||
| 805 | EndMessage(); | ||
| 806 | } | ||
| 807 | catch (...) | ||
| 808 | { | ||
| 809 | AbortMessage(); | ||
| 810 | throw; | ||
| 811 | } | ||
| 812 | } | ||
| 813 | |||
| 774 | 814 | ||
| 775 | void PushRequest(const char* pszCommand, | 815 | void PushRequest(const char* pszCommand, |
| 776 | void (*fn)(void*, CDataStream&), void* param1) | 816 | void (*fn)(void*, CDataStream&), void* param1) |