Fabcoin Core  0.16.2
P2P Digital Currency
Peer.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
23 #pragma once
24 
25 #include "Common.h"
26 
27 namespace dev
28 {
29 
30 namespace p2p
31 {
32 
52 class Peer: public Node
53 {
54  friend class Session;
55  friend class Host;
56 
57  friend class RLPXHandshake;
58 
59 public:
61  Peer(Node const& _node): Node(_node) {}
62 
63  bool isOffline() const { return !m_session.lock(); }
64 
65  virtual bool operator<(Peer const& _p) const;
66 
68  int rating() const { return m_rating; }
69 
71  bool shouldReconnect() const;
72 
74  int failedAttempts() const { return m_failedAttempts; }
75 
78 
81 
82 protected:
84  unsigned fallbackSeconds() const;
85 
86  int m_score = 0;
87  int m_rating = 0;
88 
90 
93  unsigned m_failedAttempts = 0;
95 
97  std::weak_ptr<Session> m_session;
98 };
99 using Peers = std::vector<Peer>;
100 
101 }
102 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
bool isOffline() const
Definition: Peer.h:63
std::chrono::system_clock::time_point m_lastConnected
Network Availability.
Definition: Peer.h:91
The Host class Capabilities should be registered prior to startNetwork, since m_capabilities is not t...
Definition: Host.h:129
Peer(Node const &_node)
Construct Peer from Node.
Definition: Peer.h:61
std::weak_ptr< Session > m_session
Used by isOffline() and (todo) for peer to emit session information.
Definition: Peer.h:97
unsigned m_failedAttempts
Definition: Peer.h:93
int rating() const
WIP: Returns current peer rating.
Definition: Peer.h:68
DisconnectReason
Definition: Common.h:106
std::vector< Peer > Peers
Definition: Peer.h:99
int failedAttempts() const
Number of times connection has been attempted to peer.
Definition: Peer.h:74
DisconnectReason lastDisconnect() const
Reason peer was previously disconnected.
Definition: Peer.h:77
int m_score
All time cumulative.
Definition: Peer.h:86
virtual bool operator<(Peer const &_p) const
Definition: Peer.cpp:63
int m_rating
Trending.
Definition: Peer.h:87
std::chrono::system_clock::time_point m_lastAttempted
Definition: Peer.h:92
DisconnectReason m_lastDisconnect
Reason for disconnect that happened last.
Definition: Peer.h:94
clock::time_point time_point
Definition: bench.h:49
Representation of connectivity state and all other pertinent Peer metadata.
Definition: Peer.h:52
bool shouldReconnect() const
Return true if connection attempt should be made to this peer or false if.
Definition: Peer.cpp:34
void noteSessionGood()
Peer session is noted as useful.
Definition: Peer.h:80
unsigned fallbackSeconds() const
Returns number of seconds to wait until attempting connection, based on attempted connection history...
Definition: Peer.cpp:39
The Session class.
Definition: Session.h:90
Setup inbound or outbound connection for communication over RLPXFrameCoder.
Definition: RLPxHandshake.h:51