diff --git a/p2p/message.go b/p2p/message.go index 10b55a939c..ac9a0f390a 100644 --- a/p2p/message.go +++ b/p2p/message.go @@ -70,10 +70,12 @@ func (msg Msg) Discard() error { return err } +// MsgReader provides reading of encoded message type MsgReader interface { ReadMsg() (Msg, error) } +// MsgWriter provides reading of encoded message type MsgWriter interface { // WriteMsg sends a message. It will block until the message's // Payload has been consumed by the other end. diff --git a/p2p/metrics.go b/p2p/metrics.go index 30bd56bd4d..b2456b92a1 100644 --- a/p2p/metrics.go +++ b/p2p/metrics.go @@ -30,12 +30,17 @@ import ( ) const ( - MetricsInboundTraffic = "p2p/ingress" // Name for the registered inbound traffic meter - MetricsOutboundTraffic = "p2p/egress" // Name for the registered outbound traffic meter - MetricsOutboundConnects = "p2p/dials" // Name for the registered outbound connects meter - MetricsInboundConnects = "p2p/serves" // Name for the registered inbound connects meter + // MetricsInboundTraffic is the name for the registered inbound traffic meter + MetricsInboundTraffic = "p2p/ingress" + // MetricsOutboundTraffic is the name for the registered outbound traffic meter + MetricsOutboundTraffic = "p2p/egress" + // MetricsOutboundConnects is the name for the registered outbound connects meter + MetricsOutboundConnects = "p2p/dials" + // MetricsInboundConnects is the name for the registered inbound connects meter + MetricsInboundConnects = "p2p/serves" - MeteredPeerLimit = 1024 // This amount of peers are individually metered + // MeteredPeerLimit is the amount of peers are individually metered + MeteredPeerLimit = 1024 ) var ( @@ -45,8 +50,10 @@ var ( egressTrafficMeter = metrics.NewRegisteredMeter(MetricsOutboundTraffic, nil) // Meter metering the cumulative egress traffic activePeerGauge = metrics.NewRegisteredGauge("p2p/peers", nil) // Gauge tracking the current peer count - PeerIngressRegistry = metrics.NewPrefixedChildRegistry(metrics.EphemeralRegistry, MetricsInboundTraffic+"/") // Registry containing the peer ingress - PeerEgressRegistry = metrics.NewPrefixedChildRegistry(metrics.EphemeralRegistry, MetricsOutboundTraffic+"/") // Registry containing the peer egress + // PeerIngressRegistry is a registry containing the peer ingress + PeerIngressRegistry = metrics.NewPrefixedChildRegistry(metrics.EphemeralRegistry, MetricsInboundTraffic+"/") + // PeerEgressRegistry is a registry containing the peer egress + PeerEgressRegistry = metrics.NewPrefixedChildRegistry(metrics.EphemeralRegistry, MetricsOutboundTraffic+"/") meteredPeerFeed event.Feed // Event feed for peer metrics meteredPeerCount int32 // Actually stored peer connection count diff --git a/p2p/peer.go b/p2p/peer.go index 9a9788bc17..d89fb5a50a 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -35,6 +35,7 @@ import ( ) var ( + // ErrShuttingDown is the shutting down error ErrShuttingDown = errors.New("shutting down") ) @@ -193,6 +194,7 @@ func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer { return p } +// Log will return the logger func (p *Peer) Log() log.Logger { return p.log } diff --git a/p2p/peer_error.go b/p2p/peer_error.go index ab61bfef06..9b21966317 100644 --- a/p2p/peer_error.go +++ b/p2p/peer_error.go @@ -54,21 +54,35 @@ func (pe *peerError) Error() string { var errProtocolReturned = errors.New("protocol returned") +// DiscReason is the code for a disconnect reason type DiscReason uint const ( + // DiscRequested is disconnect requested DiscRequested DiscReason = iota + // DiscNetworkError is a network error DiscNetworkError + // DiscProtocolError is a breach of protocol DiscProtocolError + // DiscUselessPeer is a useless peer DiscUselessPeer + // DiscTooManyPeers is too many peers DiscTooManyPeers + // DiscAlreadyConnected is already connected DiscAlreadyConnected + // DiscIncompatibleVersion is an incompatible p2p protocol version DiscIncompatibleVersion + // DiscInvalidIdentity is invalid node entity DiscInvalidIdentity + // DiscQuitting is client quitting DiscQuitting + // DiscUnexpectedIdentity is an unexpected identity DiscUnexpectedIdentity + // DiscSelf is connected to self DiscSelf + // DiscReadTimeout is read timeout DiscReadTimeout + // DiscSubprotocolError is subprotocol error DiscSubprotocolError = 0x10 ) diff --git a/p2p/server.go b/p2p/server.go index 9b9effaf6c..f955cfde34 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -363,7 +363,7 @@ func (srv *Server) RemoveTrustedPeer(node *enode.Node) { } } -// SubscribePeers subscribes the given channel to peer events +// SubscribeEvents subscribes to peer events and returns the event subscription func (srv *Server) SubscribeEvents(ch chan *PeerEvent) event.Subscription { return srv.peerFeed.Subscribe(ch) }