aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-14 06:38:53 +0800
committerobscuren <geffobscura@gmail.com>2015-04-14 06:38:53 +0800
commitb7e1b686aa1fc2c44fd6827b08c546629607d1a2 (patch)
tree6cf0951e6da696b879d1f82cbaafb14bff84271c /p2p/peer.go
parent07eebc38b207e435d2397cefd1412a7ec9c1e32e (diff)
parent2ea98d9b74ac2d66dce6eeb92c371c0237245d79 (diff)
downloaddexon-b7e1b686aa1fc2c44fd6827b08c546629607d1a2.tar
dexon-b7e1b686aa1fc2c44fd6827b08c546629607d1a2.tar.gz
dexon-b7e1b686aa1fc2c44fd6827b08c546629607d1a2.tar.bz2
dexon-b7e1b686aa1fc2c44fd6827b08c546629607d1a2.tar.lz
dexon-b7e1b686aa1fc2c44fd6827b08c546629607d1a2.tar.xz
dexon-b7e1b686aa1fc2c44fd6827b08c546629607d1a2.tar.zst
dexon-b7e1b686aa1fc2c44fd6827b08c546629607d1a2.zip
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
Diffstat (limited to 'p2p/peer.go')
-rw-r--r--p2p/peer.go30
1 files changed, 8 insertions, 22 deletions
diff --git a/p2p/peer.go b/p2p/peer.go
index 7bc4f9cf6..1262ba64a 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
- "io/ioutil"
"net"
"sort"
"sync"
@@ -20,8 +19,7 @@ const (
baseProtocolLength = uint64(16)
baseProtocolMaxMsgSize = 10 * 1024 * 1024
- pingInterval = 15 * time.Second
- disconnectGracePeriod = 2 * time.Second
+ pingInterval = 15 * time.Second
)
const (
@@ -129,39 +127,27 @@ func (p *Peer) run() DiscReason {
case err := <-readErr:
if r, ok := err.(DiscReason); ok {
reason = r
- break
+ } 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)
+ reason = DiscNetworkError
}
- // 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)
- p.conn.Close()
- reason = DiscNetworkError
case err := <-p.protoErr:
reason = discReasonForError(err)
case reason = <-p.disc:
}
close(p.closed)
+ p.politeDisconnect(reason)
p.wg.Wait()
- if reason != DiscNetworkError {
- p.politeDisconnect(reason)
- }
p.Debugf("Disconnected: %v\n", reason)
return reason
}
func (p *Peer) politeDisconnect(reason DiscReason) {
- done := make(chan struct{})
- go func() {
+ if reason != DiscNetworkError {
SendItems(p.rw, discMsg, uint(reason))
- // Wait for the other side to close the connection.
- // Discard any data that they send until then.
- io.Copy(ioutil.Discard, p.conn)
- close(done)
- }()
- select {
- case <-done:
- case <-time.After(disconnectGracePeriod):
}
p.conn.Close()
}