aboutsummaryrefslogtreecommitdiffstats
path: root/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'p2p')
-rw-r--r--p2p/metrics.go11
-rw-r--r--p2p/protocols/protocol_test.go2
-rw-r--r--p2p/rlpx.go2
-rw-r--r--p2p/server.go2
4 files changed, 8 insertions, 9 deletions
diff --git a/p2p/metrics.go b/p2p/metrics.go
index 6a7c0bad3..d7873f39a 100644
--- a/p2p/metrics.go
+++ b/p2p/metrics.go
@@ -74,7 +74,7 @@ const (
type MeteredPeerEvent struct {
Type MeteredPeerEventType // Type of peer event
IP net.IP // IP address of the peer
- ID string // NodeID of the peer
+ ID enode.ID // NodeID of the peer
Elapsed time.Duration // Time elapsed between the connection and the handshake/disconnection
Ingress uint64 // Ingress count at the moment of the event
Egress uint64 // Egress count at the moment of the event
@@ -93,7 +93,7 @@ type meteredConn struct {
connected time.Time // Connection time of the peer
ip net.IP // IP address of the peer
- id string // NodeID of the peer
+ id enode.ID // NodeID of the peer
// trafficMetered denotes if the peer is registered in the traffic registries.
// Its value is true if the metered peer count doesn't reach the limit in the
@@ -160,8 +160,7 @@ func (c *meteredConn) Write(b []byte) (n int, err error) {
// handshakeDone is called when a peer handshake is done. Registers the peer to
// the ingress and the egress traffic registries using the peer's IP and node ID,
// also emits connect event.
-func (c *meteredConn) handshakeDone(nodeID enode.ID) {
- id := nodeID.String()
+func (c *meteredConn) handshakeDone(id enode.ID) {
if atomic.AddInt32(&meteredPeerCount, 1) >= MeteredPeerLimit {
// Don't register the peer in the traffic registries.
atomic.AddInt32(&meteredPeerCount, -1)
@@ -170,7 +169,7 @@ func (c *meteredConn) handshakeDone(nodeID enode.ID) {
c.lock.Unlock()
log.Warn("Metered peer count reached the limit")
} else {
- key := fmt.Sprintf("%s/%s", c.ip, id)
+ key := fmt.Sprintf("%s/%s", c.ip, id.String())
c.lock.Lock()
c.id, c.trafficMetered = id, true
c.ingressMeter = metrics.NewRegisteredMeter(key, PeerIngressRegistry)
@@ -190,7 +189,7 @@ func (c *meteredConn) handshakeDone(nodeID enode.ID) {
func (c *meteredConn) Close() error {
err := c.Conn.Close()
c.lock.RLock()
- if c.id == "" {
+ if c.id == (enode.ID{}) {
// If the peer disconnects before the handshake.
c.lock.RUnlock()
meteredPeerFeed.Send(MeteredPeerEvent{
diff --git a/p2p/protocols/protocol_test.go b/p2p/protocols/protocol_test.go
index 2874af48d..a26222cd8 100644
--- a/p2p/protocols/protocol_test.go
+++ b/p2p/protocols/protocol_test.go
@@ -318,7 +318,7 @@ func TestProtocolHook(t *testing.T) {
<-testHook.waitC
time.Sleep(100 * time.Millisecond)
- err = tester.TestDisconnected(&p2ptest.Disconnect{tester.Nodes[1].ID(), testHook.err})
+ err = tester.TestDisconnected(&p2ptest.Disconnect{Peer: tester.Nodes[1].ID(), Error: testHook.err})
if err != nil {
t.Fatalf("Expected a specific disconnect error, but got different one: %v", err)
}
diff --git a/p2p/rlpx.go b/p2p/rlpx.go
index a105720a4..22a27dd96 100644
--- a/p2p/rlpx.go
+++ b/p2p/rlpx.go
@@ -151,7 +151,7 @@ func readProtocolHandshake(rw MsgReader, our *protoHandshake) (*protoHandshake,
}
if msg.Code == discMsg {
// Disconnect before protocol handshake is valid according to the
- // spec and we send it ourself if the posthanshake checks fail.
+ // spec and we send it ourself if the post-handshake checks fail.
// We can't return the reason directly, though, because it is echoed
// back otherwise. Wrap it in a string instead.
var reason [1]DiscReason
diff --git a/p2p/server.go b/p2p/server.go
index 38a881f7b..667860863 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -228,7 +228,7 @@ type transport interface {
MsgReadWriter
// transports must provide Close because we use MsgPipe in some of
// the tests. Closing the actual network connection doesn't do
- // anything in those tests because NsgPipe doesn't use it.
+ // anything in those tests because MsgPipe doesn't use it.
close(err error)
}