diff options
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index 5cf2f8c..964097b 100644 --- a/src/net.cpp +++ b/src/net.cpp | |||
| @@ -1700,6 +1700,13 @@ void ThreadMessageHandler(void* parg) | |||
| 1700 | } | 1700 | } |
| 1701 | } | 1701 | } |
| 1702 | 1702 | ||
| 1703 | // When any peer last told us a height. A wedged node -- one that still has | ||
| 1704 | // peers but has stopped hearing them -- is exactly a node where this stops | ||
| 1705 | // advancing, and that is the one thing the height comparison itself cannot | ||
| 1706 | // see: there is no height to compare. | ||
| 1707 | static int64 nLastPeerHeightSeen = 0; | ||
| 1708 | static int64 nPeerHeightFirstAsked = 0; | ||
| 1709 | |||
| 1703 | int GetPeerMedianHeight() | 1710 | int GetPeerMedianHeight() |
| 1704 | { | 1711 | { |
| 1705 | vector<int> vHeights; | 1712 | vector<int> vHeights; |
| @@ -1711,10 +1718,26 @@ int GetPeerMedianHeight() | |||
| 1711 | if (vHeights.empty()) | 1718 | if (vHeights.empty()) |
| 1712 | return -1; | 1719 | return -1; |
| 1713 | 1720 | ||
| 1721 | nLastPeerHeightSeen = GetTime(); | ||
| 1714 | sort(vHeights.begin(), vHeights.end()); | 1722 | sort(vHeights.begin(), vHeights.end()); |
| 1715 | return vHeights[vHeights.size() / 2]; | 1723 | return vHeights[vHeights.size() / 2]; |
| 1716 | } | 1724 | } |
| 1717 | 1725 | ||
| 1726 | // Seconds since any peer last reported a height. | ||
| 1727 | // | ||
| 1728 | // Before ever hearing one, measure from the first time somebody asked rather | ||
| 1729 | // than from the epoch -- otherwise a node refuses jobs the instant it starts, | ||
| 1730 | // before it has had a chance to complete a single handshake. | ||
| 1731 | int64 GetPeerHeightAgeSecs() | ||
| 1732 | { | ||
| 1733 | int64 nNow = GetTime(); | ||
| 1734 | if (nPeerHeightFirstAsked == 0) | ||
| 1735 | nPeerHeightFirstAsked = nNow; | ||
| 1736 | if (nLastPeerHeightSeen == 0) | ||
| 1737 | return nNow - nPeerHeightFirstAsked; | ||
| 1738 | return nNow - nLastPeerHeightSeen; | ||
| 1739 | } | ||
| 1740 | |||
| 1718 | 1741 | ||
| 1719 | // Say out loud when we are behind the network. | 1742 | // Say out loud when we are behind the network. |
| 1720 | // | 1743 | // |