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
56977c22
Commit
56977c22
authored
Apr 10, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p: use RLock instead of Lock for pre-dial checks
parent
b3c058a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
10 deletions
+12
-10
server.go
p2p/server.go
+12
-10
No files found.
p2p/server.go
View file @
56977c22
...
...
@@ -86,12 +86,12 @@ type Server struct {
ourHandshake
*
protoHandshake
lock
sync
.
RWMutex
running
bool
listener
net
.
Listener
peers
map
[
discover
.
NodeID
]
*
Peer
lock
sync
.
RWMutex
// protects running and peers
running
bool
peers
map
[
discover
.
NodeID
]
*
Peer
ntab
*
discover
.
Table
ntab
*
discover
.
Table
listener
net
.
Listener
quit
chan
struct
{}
loopWG
sync
.
WaitGroup
// {dial,listen,nat}Loop
...
...
@@ -293,16 +293,17 @@ func (srv *Server) dialLoop() {
// TODO: maybe limit number of active dials
dial
:=
func
(
dest
*
discover
.
Node
)
{
srv
.
lock
.
Lock
()
ok
,
_
:=
srv
.
checkPeer
(
dest
.
ID
)
srv
.
lock
.
Unlock
()
// Don't dial nodes that would fail the checks in addPeer.
// This is important because the connection handshake is a lot
// of work and we'd rather avoid doing that work for peers
// that can't be added.
srv
.
lock
.
RLock
()
ok
,
_
:=
srv
.
checkPeer
(
dest
.
ID
)
srv
.
lock
.
RUnlock
()
if
!
ok
||
dialing
[
dest
.
ID
]
{
return
}
dialing
[
dest
.
ID
]
=
true
srv
.
peerWG
.
Add
(
1
)
go
func
()
{
...
...
@@ -315,9 +316,10 @@ func (srv *Server) dialLoop() {
for
{
select
{
case
<-
refresh
.
C
:
srv
.
lock
.
Lock
()
// Grab some nodes to connect to if we're not at capacity.
srv
.
lock
.
RLock
()
needpeers
:=
len
(
srv
.
peers
)
<
srv
.
MaxPeers
srv
.
lock
.
Unlock
()
srv
.
lock
.
R
Unlock
()
if
needpeers
{
go
func
()
{
var
target
discover
.
NodeID
...
...
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