mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-14 23:29:02 +00:00
p2p/peer: expose conn flags through getter functions
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
4635dac0b5
commit
23cda63d5a
1 changed files with 25 additions and 1 deletions
26
p2p/peer.go
26
p2p/peer.go
|
|
@ -220,11 +220,35 @@ func (p *Peer) String() string {
|
|||
return fmt.Sprintf("Peer %x %v", id[:8], p.RemoteAddr())
|
||||
}
|
||||
|
||||
// Inbound returns true if the peer is an inbound connection
|
||||
// Inbound returns true if the peer is an inbound (not dialed) connection.
|
||||
func (p *Peer) Inbound() bool {
|
||||
return p.rw.is(inboundConn)
|
||||
}
|
||||
|
||||
// Trusted returns true if the peer is configured as trusted.
|
||||
// Trusted peers are accepted in above the MaxInboundConns limit.
|
||||
// The peer can be either inbound or dialed.
|
||||
func (p *Peer) Trusted() bool {
|
||||
return p.rw.is(trustedConn)
|
||||
}
|
||||
|
||||
// DynDialed returns true if the peer was dialed successfully (passed handshake) and
|
||||
// it is not configured as static.
|
||||
func (p *Peer) DynDialed() bool {
|
||||
return p.rw.is(dynDialedConn)
|
||||
}
|
||||
|
||||
// StaticDialed returns true if the peer was dialed successfully (passed handshake) and
|
||||
// it is configured as static.
|
||||
func (p *Peer) StaticDialed() bool {
|
||||
return p.rw.is(staticDialedConn)
|
||||
}
|
||||
|
||||
// Lifetime returns the time since peer creation.
|
||||
func (p *Peer) Lifetime() mclock.AbsTime {
|
||||
return mclock.Now() - p.created
|
||||
}
|
||||
|
||||
func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer {
|
||||
protomap := matchProtocols(protocols, conn.caps, conn)
|
||||
p := &Peer{
|
||||
|
|
|
|||
Loading…
Reference in a new issue