diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-07 05:49:52 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-07 05:49:52 +0800 |
commit | a0cb1945aeac215b1909ff0063b66171ebe73c70 (patch) | |
tree | fc07f2354402ef786a4196c3a4d29be7d703806c /p2p | |
parent | b719801db0bc80b49f05b249e2d4cf322c09eb24 (diff) | |
parent | 3e2a928caa74e523f43e14eec9918033ac1cbe0a (diff) | |
download | go-tangerine-a0cb1945aeac215b1909ff0063b66171ebe73c70.tar go-tangerine-a0cb1945aeac215b1909ff0063b66171ebe73c70.tar.gz go-tangerine-a0cb1945aeac215b1909ff0063b66171ebe73c70.tar.bz2 go-tangerine-a0cb1945aeac215b1909ff0063b66171ebe73c70.tar.lz go-tangerine-a0cb1945aeac215b1909ff0063b66171ebe73c70.tar.xz go-tangerine-a0cb1945aeac215b1909ff0063b66171ebe73c70.tar.zst go-tangerine-a0cb1945aeac215b1909ff0063b66171ebe73c70.zip |
Merge pull request #866 from fjl/p2p-last-minute
Last minute p2p fixes
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/discover/udp.go | 4 | ||||
-rw-r--r-- | p2p/nat/nat.go | 8 | ||||
-rw-r--r-- | p2p/peer.go | 21 | ||||
-rw-r--r-- | p2p/server.go | 2 |
4 files changed, 16 insertions, 19 deletions
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index 7213325da..1213c12c8 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -31,8 +31,8 @@ var ( // Timeouts const ( - respTimeout = 300 * time.Millisecond - sendTimeout = 300 * time.Millisecond + respTimeout = 500 * time.Millisecond + sendTimeout = 500 * time.Millisecond expiration = 20 * time.Second refreshInterval = 1 * time.Hour diff --git a/p2p/nat/nat.go b/p2p/nat/nat.go index 4ae7e6b17..fe00bdab0 100644 --- a/p2p/nat/nat.go +++ b/p2p/nat/nat.go @@ -91,7 +91,8 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na }() glog.V(logger.Debug).Infof("add mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m) if err := m.AddMapping(protocol, intport, extport, name, mapTimeout); err != nil { - glog.V(logger.Error).Infof("mapping error: %v\n", err) + glog.V(logger.Warn).Infof("network port %d could not be mapped: %v\n", intport, err) + glog.V(logger.Debug).Infof("mapping with %v returned %v\n", m, err) } for { select { @@ -102,7 +103,8 @@ func Map(m Interface, c chan struct{}, protocol string, extport, intport int, na case <-refresh.C: glog.V(logger.Detail).Infof("refresh mapping: %s %d -> %d (%s) using %s\n", protocol, extport, intport, name, m) if err := m.AddMapping(protocol, intport, extport, name, mapTimeout); err != nil { - glog.V(logger.Error).Infof("mapping error: %v\n", err) + glog.V(logger.Warn).Infof("network port %d could not be mapped: %v\n", intport, err) + glog.V(logger.Debug).Infof("mapping with %v returned %v\n", m, err) } refresh.Reset(mapUpdateInterval) } @@ -225,7 +227,7 @@ func (n *autodisc) wait() error { return nil } if found = <-n.done; found == nil { - return errors.New("no devices discovered") + return errors.New("no UPnP or NAT-PMP router discovered") } n.mu.Lock() n.found = found diff --git a/p2p/peer.go b/p2p/peer.go index 94fa03f8d..cdf9ba965 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -10,6 +10,7 @@ import ( "time" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/rlp" ) @@ -34,10 +35,6 @@ const ( // Peer represents a connected remote node. type Peer struct { - // Peers have all the log methods. - // Use them to display messages related to the peer. - *logger.Logger - conn net.Conn rw *conn running map[string]*protoRW @@ -99,10 +96,8 @@ func (p *Peer) String() string { } func newPeer(fd net.Conn, conn *conn, protocols []Protocol) *Peer { - logtag := fmt.Sprintf("Peer %.8x %v", conn.ID[:], fd.RemoteAddr()) protomap := matchProtocols(protocols, conn.Caps, conn) p := &Peer{ - Logger: logger.NewLogger(logtag), conn: fd, rw: conn, running: protomap, @@ -130,7 +125,7 @@ func (p *Peer) run() DiscReason { } else { // Note: We rely on protocols to abort if there is a write // error. It might be more robust to handle them here as well. - p.DebugDetailf("Read error: %v\n", err) + glog.V(logger.Detail).Infof("%v: Read error: %v\n", p, err) reason = DiscNetworkError } case err := <-p.protoErr: @@ -141,7 +136,7 @@ func (p *Peer) run() DiscReason { close(p.closed) p.politeDisconnect(reason) p.wg.Wait() - p.Debugf("Disconnected: %v\n", reason) + glog.V(logger.Debug).Infof("%v: Disconnected: %v\n", p, reason) return reason } @@ -195,7 +190,7 @@ func (p *Peer) handle(msg Msg) error { // This is the last message. We don't need to discard or // check errors because, the connection will be closed after it. rlp.Decode(msg.Payload, &reason) - p.Debugf("Disconnect requested: %v\n", reason[0]) + glog.V(logger.Debug).Infof("%v: Disconnect Requested: %v\n", p, reason[0]) return DiscRequested case msg.Code < baseProtocolLength: // ignore other base protocol messages @@ -239,14 +234,14 @@ func (p *Peer) startProtocols() { for _, proto := range p.running { proto := proto proto.closed = p.closed - p.DebugDetailf("Starting protocol %s/%d\n", proto.Name, proto.Version) + glog.V(logger.Detail).Infof("%v: Starting protocol %s/%d\n", p, proto.Name, proto.Version) go func() { err := proto.Run(p, proto) if err == nil { - p.DebugDetailf("Protocol %s/%d returned\n", proto.Name, proto.Version) + glog.V(logger.Detail).Infof("%v: Protocol %s/%d returned\n", p, proto.Name, proto.Version) err = errors.New("protocol returned") - } else { - p.DebugDetailf("Protocol %s/%d error: %v\n", proto.Name, proto.Version, err) + } else if err != io.EOF { + glog.V(logger.Detail).Infof("%v: Protocol %s/%d error: \n", p, proto.Name, proto.Version, err) } p.protoErr <- err p.wg.Done() diff --git a/p2p/server.go b/p2p/server.go index 4a78e0bb9..5e0c917fc 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -428,7 +428,7 @@ func (srv *Server) dialLoop() { case <-refresh.C: // Grab some nodes to connect to if we're not at capacity. srv.lock.RLock() - needpeers := len(srv.peers) < srv.MaxPeers + needpeers := len(srv.peers) < srv.MaxPeers/2 srv.lock.RUnlock() if needpeers { go func() { |