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
64174f19
Commit
64174f19
authored
May 25, 2015
by
Péter Szilágyi
Committed by
Felix Lange
May 26, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/discover: add support for counting findnode failures
parent
6a674ffe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
database.go
p2p/discover/database.go
+14
-3
database_test.go
p2p/discover/database_test.go
+11
-0
No files found.
p2p/discover/database.go
View file @
64174f19
...
...
@@ -44,9 +44,10 @@ var (
nodeDBVersionKey
=
[]
byte
(
"version"
)
// Version of the database to flush if changes
nodeDBItemPrefix
=
[]
byte
(
"n:"
)
// Identifier to prefix node entries with
nodeDBDiscoverRoot
=
":discover"
nodeDBDiscoverPing
=
nodeDBDiscoverRoot
+
":lastping"
nodeDBDiscoverPong
=
nodeDBDiscoverRoot
+
":lastpong"
nodeDBDiscoverRoot
=
":discover"
nodeDBDiscoverPing
=
nodeDBDiscoverRoot
+
":lastping"
nodeDBDiscoverPong
=
nodeDBDiscoverRoot
+
":lastpong"
nodeDBDiscoverFindFails
=
nodeDBDiscoverRoot
+
":findfail"
)
// newNodeDB creates a new node database for storing and retrieving infos about
...
...
@@ -275,6 +276,16 @@ func (db *nodeDB) updateLastPong(id NodeID, instance time.Time) error {
return
db
.
storeInt64
(
makeKey
(
id
,
nodeDBDiscoverPong
),
instance
.
Unix
())
}
// findFails retrieves the number of findnode failures since bonding.
func
(
db
*
nodeDB
)
findFails
(
id
NodeID
)
int
{
return
int
(
db
.
fetchInt64
(
makeKey
(
id
,
nodeDBDiscoverFindFails
)))
}
// updateFindFails updates the number of findnode failures since bonding.
func
(
db
*
nodeDB
)
updateFindFails
(
id
NodeID
,
fails
int
)
error
{
return
db
.
storeInt64
(
makeKey
(
id
,
nodeDBDiscoverFindFails
),
int64
(
fails
))
}
// querySeeds retrieves a batch of nodes to be used as potential seed servers
// during bootstrapping the node into the network.
//
...
...
p2p/discover/database_test.go
View file @
64174f19
...
...
@@ -93,6 +93,7 @@ func TestNodeDBFetchStore(t *testing.T) {
30303
,
)
inst
:=
time
.
Now
()
num
:=
314
db
,
_
:=
newNodeDB
(
""
,
Version
,
NodeID
{})
defer
db
.
close
()
...
...
@@ -117,6 +118,16 @@ func TestNodeDBFetchStore(t *testing.T) {
if
stored
:=
db
.
lastPong
(
node
.
ID
);
stored
.
Unix
()
!=
inst
.
Unix
()
{
t
.
Errorf
(
"pong: value mismatch: have %v, want %v"
,
stored
,
inst
)
}
// Check fetch/store operations on a node findnode-failure object
if
stored
:=
db
.
findFails
(
node
.
ID
);
stored
!=
0
{
t
.
Errorf
(
"find-node fails: non-existing object: %v"
,
stored
)
}
if
err
:=
db
.
updateFindFails
(
node
.
ID
,
num
);
err
!=
nil
{
t
.
Errorf
(
"find-node fails: failed to update: %v"
,
err
)
}
if
stored
:=
db
.
findFails
(
node
.
ID
);
stored
!=
num
{
t
.
Errorf
(
"find-node fails: value mismatch: have %v, want %v"
,
stored
,
num
)
}
// Check fetch/store operations on an actual node object
if
stored
:=
db
.
node
(
node
.
ID
);
stored
!=
nil
{
t
.
Errorf
(
"node: non-existing object: %v"
,
stored
)
...
...
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