Skip to content

Commit

Permalink
Refactor: Move NetEventsInterface class below CNode declaration so it…
Browse files Browse the repository at this point in the history
… can get access to the cs_sendProcessing field and detect missing cs_sendProcessing locks properly.
  • Loading branch information
furszy committed Jun 14, 2021
1 parent af1d679 commit 74f7d5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,19 +413,6 @@ struct CombinerAll {
}
};

/**
* Interface for message handling
*/
class NetEventsInterface
{
public:
virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
virtual bool SendMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
virtual void InitializeNode(CNode* pnode) = 0;
virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
};


enum {
LOCAL_NONE, // unknown
LOCAL_IF, // address a local interface listens on
Expand Down Expand Up @@ -839,6 +826,18 @@ class CExplicitNetCleanup
static void callCleanup();
};

/**
* Interface for message handling
*/
class NetEventsInterface
{
public:
virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
virtual bool SendMessages(CNode* pnode, std::atomic<bool>& interrupt) EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_sendProcessing) = 0;
virtual void InitializeNode(CNode* pnode) = 0;
virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
};

/** Return a timestamp in the future (in microseconds) for exponentially distributed events. */
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds);

Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PeerLogicValidation : public CValidationInterface, public NetEventsInterfa
* @param[in] interrupt Interrupt condition for processing threads
* @return True if there is more work to be done
*/
bool SendMessages(CNode* pto, std::atomic<bool>& interrupt) override;
bool SendMessages(CNode* pto, std::atomic<bool>& interrupt) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
};

struct CNodeStateStats {
Expand Down

0 comments on commit 74f7d5f

Please sign in to comment.