Skip to content

Commit

Permalink
Polish interfaces around PeerLogicValidation
Browse files Browse the repository at this point in the history
* Make PeerLogicValidation final to prevent deriving from it [1]
* Prevent deletions of NetEventsInterface and CValidationInterface
  objects via a base class pointer

[1] silences the following compiler warning (from Clang 7.0.0):

/usr/include/c++/v1/memory:2285:5: error: delete called on non-final 'PeerLogicValidation' that has
      virtual functions but non-virtual destructor [-Werror,-Wdelete-non-virtual-dtor]
    delete __ptr;
    ^
/usr/include/c++/v1/memory:2598:7: note: in instantiation of member function
      'std::__1::default_delete<PeerLogicValidation>::operator()' requested here
      __ptr_.second()(__tmp);
      ^
init.cpp:201:15: note: in instantiation of member function 'std::__1::unique_ptr<PeerLogicValidation,
      std::__1::default_delete<PeerLogicValidation> >::reset' requested here
    peerLogic.reset();
                  ^
  • Loading branch information
vasild committed Mar 14, 2018
1 parent 6acd870 commit 2b3ea39
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ class NetEventsInterface
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;

protected:
/**
* Protected destructor so that instances can only be deleted by derived classes.
* If that restriction is no longer desired, this should be made public and virtual.
*/
~NetEventsInterface() = default;
};

enum
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45;
/** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */
static constexpr int64_t MINIMUM_CONNECT_TIME = 30;

class PeerLogicValidation : public CValidationInterface, public NetEventsInterface {
class PeerLogicValidation final : public CValidationInterface, public NetEventsInterface {
private:
CConnman* const connman;

Expand Down
5 changes: 5 additions & 0 deletions src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ void SyncWithValidationInterfaceQueue();

class CValidationInterface {
protected:
/**
* Protected destructor so that instances can only be deleted by derived classes.
* If that restriction is no longer desired, this should be made public and virtual.
*/
~CValidationInterface() = default;
/**
* Notifies listeners of updated block chain tip
*
Expand Down

0 comments on commit 2b3ea39

Please sign in to comment.