diff options
Diffstat (limited to 'src/net.h')
| -rw-r--r-- | src/net.h | 26 |
1 files changed, 26 insertions, 0 deletions
| @@ -7,6 +7,9 @@ class CAddress; | |||
| 7 | class CInv; | 7 | class CInv; |
| 8 | class CRequestTracker; | 8 | class CRequestTracker; |
| 9 | class CNode; | 9 | class CNode; |
| 10 | // Defined in main.h, which is included after this file. Only ever used here as | ||
| 11 | // a pointer, so the forward declaration is enough. | ||
| 12 | class CBlockIndex; | ||
| 10 | 13 | ||
| 11 | 14 | ||
| 12 | 15 | ||
| @@ -533,6 +536,11 @@ public: | |||
| 533 | // Last "btfpeers" we accepted from this node, to rate-limit the exchange. | 536 | // Last "btfpeers" we accepted from this node, to rate-limit the exchange. |
| 534 | int64 nLastPexRecv; | 537 | int64 nLastPexRecv; |
| 535 | 538 | ||
| 539 | // Last getblocks we sent this peer, so we do not ask the same question | ||
| 540 | // over and over. See CNode::PushGetBlocks. | ||
| 541 | CBlockIndex* pindexLastGetBlocksBegin; | ||
| 542 | uint256 hashLastGetBlocksEnd; | ||
| 543 | |||
| 536 | // Liveness. A peer whose network path dies silently -- NAT drops an idle | 544 | // Liveness. A peer whose network path dies silently -- NAT drops an idle |
| 537 | // mapping, a relay restarts, a route changes -- never sends FIN, so the | 545 | // mapping, a relay restarts, a route changes -- never sends FIN, so the |
| 538 | // socket stays readable-never and the node simply stops hearing from it | 546 | // socket stays readable-never and the node simply stops hearing from it |
| @@ -565,6 +573,8 @@ public: | |||
| 565 | nRefCount = 0; | 573 | nRefCount = 0; |
| 566 | nReleaseTime = 0; | 574 | nReleaseTime = 0; |
| 567 | nLastPexRecv = 0; | 575 | nLastPexRecv = 0; |
| 576 | pindexLastGetBlocksBegin = NULL; | ||
| 577 | hashLastGetBlocksEnd = 0; | ||
| 568 | nTimeConnected = GetTime(); | 578 | nTimeConnected = GetTime(); |
| 569 | nLastSend = 0; | 579 | nLastSend = 0; |
| 570 | nLastRecv = 0; | 580 | nLastRecv = 0; |
| @@ -717,6 +727,22 @@ public: | |||
| 717 | 727 | ||
| 718 | 728 | ||
| 719 | 729 | ||
| 730 | // Ask this peer to fill in blocks we are missing, but only once per | ||
| 731 | // question. | ||
| 732 | // | ||
| 733 | // Every orphan block fires one of these, and an inv for a block we already | ||
| 734 | // hold as an orphan fires another. A node that is missing part of the | ||
| 735 | // chain therefore asks the same peer the same thing repeatedly: measured | ||
| 736 | // on a production node, 1287 orphan blocks out of 4117 processed, and 97 | ||
| 737 | // "already have block" from the answers coming back more than once. The | ||
| 738 | // duplicate answers create more orphans, which fire more requests. | ||
| 739 | // | ||
| 740 | // Remembering the last question asked breaks that loop. Same fix Bitcoin | ||
| 741 | // made in e2c2648c1. | ||
| 742 | // Body lives in net.cpp: it builds a CBlockLocator, which main.h defines, | ||
| 743 | // and main.h is included after this file. | ||
| 744 | void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd); | ||
| 745 | |||
| 720 | void PushMessage(const char* pszCommand) | 746 | void PushMessage(const char* pszCommand) |
| 721 | { | 747 | { |
| 722 | try | 748 | try |