Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
dcca66bc
Commit
dcca66bc
authored
Jun 07, 2018
by
Andrey Petrov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p: Cache inbound flag on Peer.isInbound to avoid a race
parent
399aa710
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
peer.go
p2p/peer.go
+14
-12
No files found.
p2p/peer.go
View file @
dcca66bc
...
@@ -95,10 +95,11 @@ type PeerEvent struct {
...
@@ -95,10 +95,11 @@ 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
running
map
[
string
]
*
protoRW
isInbound
bool
// Cached from rw.flags to avoid a race condition
log
log
.
Logger
running
map
[
string
]
*
protoRW
created
mclock
.
AbsTime
log
log
.
Logger
created
mclock
.
AbsTime
wg
sync
.
WaitGroup
wg
sync
.
WaitGroup
protoErr
chan
error
protoErr
chan
error
...
@@ -160,19 +161,20 @@ func (p *Peer) String() string {
...
@@ -160,19 +161,20 @@ 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
,
running
:
protomap
,
isInbound
:
conn
.
is
(
inboundConn
),
created
:
mclock
.
Now
(),
running
:
protomap
,
disc
:
make
(
chan
DiscReason
),
created
:
mclock
.
Now
(),
protoErr
:
make
(
chan
error
,
len
(
protomap
)
+
1
),
// protocols + pingLoop
disc
:
make
(
chan
DiscReason
),
closed
:
make
(
chan
struct
{}),
protoErr
:
make
(
chan
error
,
len
(
protomap
)
+
1
),
// protocols + pingLoop
log
:
log
.
New
(
"id"
,
conn
.
id
,
"conn"
,
conn
.
flags
),
closed
:
make
(
chan
struct
{}),
log
:
log
.
New
(
"id"
,
conn
.
id
,
"conn"
,
conn
.
flags
),
}
}
return
p
return
p
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment