p2p: use errors.New instead of fmt.Errorf (#18193)

pull/18222/head
needkane 6 years ago committed by Felix Lange
parent ef8ced4151
commit 54abb97e3b
  1. 9
      p2p/server.go

@ -22,7 +22,6 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt"
"net" "net"
"sort" "sort"
"sync" "sync"
@ -391,7 +390,7 @@ type sharedUDPConn struct {
func (s *sharedUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) { func (s *sharedUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) {
packet, ok := <-s.unhandled packet, ok := <-s.unhandled
if !ok { if !ok {
return 0, nil, fmt.Errorf("Connection was closed") return 0, nil, errors.New("Connection was closed")
} }
l := len(packet.Data) l := len(packet.Data)
if l > len(b) { if l > len(b) {
@ -425,7 +424,7 @@ func (srv *Server) Start() (err error) {
// static fields // static fields
if srv.PrivateKey == nil { if srv.PrivateKey == nil {
return fmt.Errorf("Server.PrivateKey must be set to a non-nil key") return errors.New("Server.PrivateKey must be set to a non-nil key")
} }
if srv.newTransport == nil { if srv.newTransport == nil {
srv.newTransport = newRLPX srv.newTransport = newRLPX
@ -903,7 +902,7 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) erro
if dialDest != nil { if dialDest != nil {
dialPubkey = new(ecdsa.PublicKey) dialPubkey = new(ecdsa.PublicKey)
if err := dialDest.Load((*enode.Secp256k1)(dialPubkey)); err != nil { if err := dialDest.Load((*enode.Secp256k1)(dialPubkey)); err != nil {
return fmt.Errorf("dial destination doesn't have a secp256k1 public key") return errors.New("dial destination doesn't have a secp256k1 public key")
} }
} }
// Run the encryption handshake. // Run the encryption handshake.
@ -937,7 +936,7 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) erro
return err return err
} }
if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.ID), id[:]) { if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.ID), id[:]) {
clog.Trace("Wrong devp2p handshake identity", "phsid", fmt.Sprintf("%x", phs.ID)) clog.Trace("Wrong devp2p handshake identity", "phsid", hex.EncodeToString(phs.ID))
return DiscUnexpectedIdentity return DiscUnexpectedIdentity
} }
c.caps, c.name = phs.Caps, phs.Name c.caps, c.name = phs.Caps, phs.Name

Loading…
Cancel
Save