Commit dcca66bc authored by Andrey Petrov's avatar Andrey Petrov

p2p: Cache inbound flag on Peer.isInbound to avoid a race

parent 399aa710
...@@ -96,6 +96,7 @@ type PeerEvent struct { ...@@ -96,6 +96,7 @@ type PeerEvent struct {
// Peer represents a connected remote node. // Peer represents a connected remote node.
type Peer struct { type Peer struct {
rw *conn rw *conn
isInbound bool // Cached from rw.flags to avoid a race condition
running map[string]*protoRW running map[string]*protoRW
log log.Logger log log.Logger
created mclock.AbsTime created mclock.AbsTime
...@@ -160,13 +161,14 @@ func (p *Peer) String() string { ...@@ -160,13 +161,14 @@ func (p *Peer) String() string {
// Inbound returns true if the peer is an inbound connection // Inbound returns true if the peer is an inbound connection
func (p *Peer) Inbound() bool { func (p *Peer) Inbound() bool {
return p.rw.flags&inboundConn != 0 return p.isInbound
} }
func newPeer(conn *conn, protocols []Protocol) *Peer { func newPeer(conn *conn, protocols []Protocol) *Peer {
protomap := matchProtocols(protocols, conn.caps, conn) protomap := matchProtocols(protocols, conn.caps, conn)
p := &Peer{ p := &Peer{
rw: conn, rw: conn,
isInbound: conn.is(inboundConn),
running: protomap, running: protomap,
created: mclock.Now(), created: mclock.Now(),
disc: make(chan DiscReason), disc: make(chan DiscReason),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment