Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
nucleo
Commits
517188f7
Commit
517188f7
authored
6 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
monitor.js did not save peers.cache ages - it now does again.
parent
98b54484
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/monitor.js
+45
-29
45 additions, 29 deletions
bin/monitor.js
with
45 additions
and
29 deletions
bin/monitor.js
+
45
−
29
View file @
517188f7
...
...
@@ -25,6 +25,9 @@ function readPeersCache()
function
writePeersCache
(
peers
)
{
// max 100 entries, FIFO
if
(
peers
.
length
>
100
)
peers
.
splice
(
0
,
peers
.
length
-
100
);
// peers.cache is a list of peers we have connected out to in the past.
bfa
.
fs
.
writeFileSync
(
bfa
.
networkdir
+
'
/peers.cache
'
,
...
...
@@ -47,12 +50,11 @@ function writeStatus( peers )
function
parsenode
(
node
)
{
if
(
!
n
||
!
n
.
protocols
||
typeof
n
.
protocols
.
eth
!=
'
object
'
)
if
(
!
n
ode
||
!
n
ode
.
protocols
||
typeof
n
ode
.
protocols
.
eth
!=
'
object
'
)
return
;
// default info - likely to get overwritten.
var
n
;
if
(
!
node
.
network
)
return
{
info
:
"
<
"
+
node
.
id
+
"
>
"
};
var
n
=
{};
if
(
typeof
node
.
network
.
inbound
==
'
boolean
'
)
n
.
dir
=
node
.
network
.
inbound
?
"
in
"
:
"
out
"
;
if
(
typeof
node
.
enode
==
'
string
'
)
...
...
@@ -74,42 +76,56 @@ function parsenode( node )
function
gotAdminPeers
(
nodelist
)
{
var
nowpeers
=
[];
var
peers
=
readPeersCache
();
var
peers
cache
=
readPeersCache
();
var
outpeers
=
[];
var
candidatenew
=
[];
var
currentnodes
=
[];
// The nodelist also contains peers which are not yet validated
// if they even belong to this network. Parsenode returns an
// object or nothing, based on our criteria
nodelist
.
forEach
(
function
(
node
)
{
var
n
=
parsenode
(
node
);
var
n
=
parsenode
(
node
);
if
(
n
)
{
nowpeers
.
push
(
"
peer
"
+
(
n
.
dir
?
n
.
dir
:
''
)
+
"
:
"
+
n
.
info
);
if
(
peers
.
indexOf
(
n
.
info
)
==
-
1
)
{
if
(
n
.
dir
==
'
out
'
)
outpeers
.
push
(
n
.
info
);
candidatenew
.
push
(
n
.
info
);
}
}
currentnodes
.
push
(
n
);
}
);
currentnodes
.
forEach
(
function
(
n
)
{
// Add to list of nowpeers (for stats file)
nowpeers
.
push
(
"
peer
"
+
(
n
.
dir
?
n
.
dir
:
''
)
+
"
:
"
+
n
.
info
);
// See if this node reported by geth is already a known peers
// from our peers.cache
if
((
peerscache
.
indexOf
(
n
.
info
)
==
-
1
)
&&
(
n
.
dir
==
'
out
'
))
outpeers
.
push
(
n
.
info
);
}
);
writeStatus
(
nowpeers
);
// write peers.cache (max 100 entries, FIFO)
peers
=
peers
.
concat
(
outpeers
);
if
(
peers
.
length
>
100
)
peers
.
splice
(
0
,
peers
.
length
-
100
);
writePeersCache
(
peers
);
writePeersCache
(
peerscache
.
concat
(
outpeers
)
);
// Try to connect to a random node if we have very few peers
if
(
nowpeers
.
length
<
5
&&
candidatenew
.
length
>
0
)
if
(
nowpeers
.
length
<
5
)
{
var
i
=
Math
.
floor
(
Math
.
random
()
*
candidatenew
.
length
)
;
var
enode
=
candidatenew
[
i
];
c
onsole
.
log
(
"
We have
"
+
nowpeers
.
length
+
"
peer
"
+
(
nowpeers
.
length
==
1
?
''
:
'
s
'
)
+
"
, so will try to connect to
"
+
enode
var
candidatenew
=
[]
;
// find candidate nodes which we can connect to
c
urrentnodes
.
forEach
(
function
(
n
)
{
if
(
peerscache
.
indexOf
(
n
.
info
)
==
-
1
)
candidatenew
.
push
(
n
.
info
);
}
);
web3
.
bfa
.
admin
.
addPeer
(
enode
);
if
(
candidatenew
.
length
>
0
)
{
var
i
=
Math
.
floor
(
Math
.
random
()
*
candidatenew
.
length
);
var
enode
=
candidatenew
[
i
];
console
.
log
(
"
We have
"
+
nowpeers
.
length
+
"
peer
"
+
(
nowpeers
.
length
==
1
?
''
:
'
s
'
)
+
"
, so will try to connect to
"
+
enode
);
web3
.
bfa
.
admin
.
addPeer
(
enode
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment