diff options
author | Andrey Petrov <andrey.petrov@shazow.net> | 2018-06-08 09:50:08 +0800 |
---|---|---|
committer | Andrey Petrov <andrey.petrov@shazow.net> | 2018-06-22 00:22:47 +0800 |
commit | 6209545083f656f2dccbe4561644a757ff6443b5 (patch) | |
tree | 5ce7677791bcce83e57f70836a3c5d6004bc036c /p2p/peer.go | |
parent | 193a402cc08e69f8c6b92106e8e81104d260d26c (diff) | |
download | dexon-6209545083f656f2dccbe4561644a757ff6443b5.tar.gz dexon-6209545083f656f2dccbe4561644a757ff6443b5.tar.zst dexon-6209545083f656f2dccbe4561644a757ff6443b5.zip |
p2p: Wrap conn.flags ops with atomic.Load/Store
Diffstat (limited to 'p2p/peer.go')
-rw-r--r-- | p2p/peer.go | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/p2p/peer.go b/p2p/peer.go index ff8602602..c4c1fcd7c 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -95,11 +95,10 @@ type PeerEvent struct { // Peer represents a connected remote node. type Peer struct { - rw *conn - isInbound bool // Cached from rw.flags to avoid a race condition - running map[string]*protoRW - log log.Logger - created mclock.AbsTime + rw *conn + running map[string]*protoRW + log log.Logger + created mclock.AbsTime wg sync.WaitGroup protoErr chan error @@ -161,20 +160,19 @@ func (p *Peer) String() string { // Inbound returns true if the peer is an inbound connection func (p *Peer) Inbound() bool { - return p.isInbound + return p.rw.is(inboundConn) } func newPeer(conn *conn, protocols []Protocol) *Peer { protomap := matchProtocols(protocols, conn.caps, conn) p := &Peer{ - rw: conn, - isInbound: conn.is(inboundConn), - running: protomap, - created: mclock.Now(), - disc: make(chan DiscReason), - protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop - closed: make(chan struct{}), - log: log.New("id", conn.id, "conn", conn.flags), + rw: conn, + running: protomap, + created: mclock.Now(), + disc: make(chan DiscReason), + protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop + closed: make(chan struct{}), + log: log.New("id", conn.id, "conn", conn.flags), } return p } |