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
706da56f
Commit
706da56f
authored
Apr 27, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discover: wrap the pinger to update the node db too
parent
85b4b442
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
table.go
p2p/discover/table.go
+15
-4
No files found.
p2p/discover/table.go
View file @
706da56f
...
@@ -288,8 +288,7 @@ func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAdd
...
@@ -288,8 +288,7 @@ func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAdd
defer
func
()
{
tab
.
bondslots
<-
struct
{}{}
}()
defer
func
()
{
tab
.
bondslots
<-
struct
{}{}
}()
// Ping the remote side and wait for a pong
// Ping the remote side and wait for a pong
tab
.
db
.
updateLastPing
(
id
,
time
.
Now
())
if
w
.
err
=
tab
.
ping
(
id
,
addr
);
w
.
err
!=
nil
{
if
w
.
err
=
tab
.
net
.
ping
(
id
,
addr
);
w
.
err
!=
nil
{
close
(
w
.
done
)
close
(
w
.
done
)
return
return
}
}
...
@@ -307,14 +306,13 @@ func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAdd
...
@@ -307,14 +306,13 @@ func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAdd
TCPPort
:
int
(
tcpPort
),
TCPPort
:
int
(
tcpPort
),
}
}
tab
.
db
.
updateNode
(
w
.
n
)
tab
.
db
.
updateNode
(
w
.
n
)
tab
.
db
.
updateLastPong
(
id
,
time
.
Now
())
close
(
w
.
done
)
close
(
w
.
done
)
}
}
func
(
tab
*
Table
)
pingreplace
(
new
*
Node
,
b
*
bucket
)
{
func
(
tab
*
Table
)
pingreplace
(
new
*
Node
,
b
*
bucket
)
{
if
len
(
b
.
entries
)
==
bucketSize
{
if
len
(
b
.
entries
)
==
bucketSize
{
oldest
:=
b
.
entries
[
bucketSize
-
1
]
oldest
:=
b
.
entries
[
bucketSize
-
1
]
if
err
:=
tab
.
net
.
ping
(
oldest
.
ID
,
oldest
.
addr
());
err
==
nil
{
if
err
:=
tab
.
ping
(
oldest
.
ID
,
oldest
.
addr
());
err
==
nil
{
// The node responded, we don't need to replace it.
// The node responded, we don't need to replace it.
return
return
}
}
...
@@ -327,6 +325,19 @@ func (tab *Table) pingreplace(new *Node, b *bucket) {
...
@@ -327,6 +325,19 @@ func (tab *Table) pingreplace(new *Node, b *bucket) {
b
.
entries
[
0
]
=
new
b
.
entries
[
0
]
=
new
}
}
// ping a remote endpoint and wait for a reply, also updating the node database
// accordingly.
func
(
tab
*
Table
)
ping
(
id
NodeID
,
addr
*
net
.
UDPAddr
)
error
{
// Update the last ping and send the message
tab
.
db
.
updateLastPing
(
id
,
time
.
Now
())
if
err
:=
tab
.
net
.
ping
(
id
,
addr
);
err
!=
nil
{
return
err
}
// Pong received, update the database and return
tab
.
db
.
updateLastPong
(
id
,
time
.
Now
())
return
nil
}
// add puts the entries into the table if their corresponding
// add puts the entries into the table if their corresponding
// bucket is not full. The caller must hold tab.mutex.
// bucket is not full. The caller must hold tab.mutex.
func
(
tab
*
Table
)
add
(
entries
[]
*
Node
)
{
func
(
tab
*
Table
)
add
(
entries
[]
*
Node
)
{
...
...
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