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
e7ff2dea
Commit
e7ff2dea
authored
6 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
No funciono' el autoconnect a peers
parent
33d5a71a
No related branches found
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
+57
-24
57 additions, 24 deletions
bin/monitor.js
with
57 additions
and
24 deletions
bin/monitor.js
+
57
−
24
View file @
e7ff2dea
...
...
@@ -9,13 +9,14 @@ var bfa = new Libbfa();
var
web3
=
bfa
.
newweb3
();
var
lastUnlock
=
0
;
function
readPeersCache
()
function
readPeersCache
()
{
if
(
!
bfa
.
fs
.
existsSync
(
bfa
.
networkdir
+
'
/peers.cache
'
)
)
return
[];
var
data
=
bfa
.
fs
.
readFileSync
(
bfa
.
networkdir
+
'
/peers.cache
'
).
toString
();
var
p
=
[];
if
(
data
.
length
>
0
)
var
p
=
data
.
split
(
/
\r?\n
/
);
p
=
data
.
split
(
/
\r?\n
/
);
// for some odd reason, I keep seeing empty entries
for
(
var
i
=
p
.
length
;
i
>
0
;
i
--
)
if
(
p
[
i
]
==
''
)
...
...
@@ -23,20 +24,20 @@ function readPeersCache()
return
p
;
}
function
writePeersCache
(
peers
)
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
'
,
peers
.
join
(
"
\n
"
)
+
"
\n
"
,
{
mode
:
0o644
}
);
var
filename
=
bfa
.
networkdir
+
'
/peers.cache
'
;
var
txt
=
peers
.
join
(
"
\n
"
);
if
(
txt
.
length
>
0
&&
(
txt
.
substring
(
txt
.
length
-
1
)
!=
"
\n
"
))
txt
+=
"
\n
"
;
bfa
.
fs
.
writeFileSync
(
filename
,
txt
,
{
mode
:
0o644
}
);
}
function
writeStatus
(
peers
)
function
writeStatus
(
peers
)
{
// write network/status
bfa
.
fs
.
writeFileSync
(
...
...
@@ -77,7 +78,7 @@ function gotAdminPeers( nodelist )
{
var
nowpeers
=
[];
var
peerscache
=
readPeersCache
();
var
outpeers
=
[];
var
new
outpeers
=
[];
var
currentnodes
=
[];
// The nodelist also contains peers which are not yet validated
...
...
@@ -97,20 +98,27 @@ function gotAdminPeers( nodelist )
// 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
);
new
outpeers
.
push
(
n
.
info
);
}
);
writeStatus
(
nowpeers
);
writePeersCache
(
peers
cache
.
concat
(
out
peers
)
);
writePeersCache
(
newout
peers
.
concat
(
peers
cache
)
);
// Try to connect to a random node if we have very few peers
if
(
nowpeers
.
length
<
5
)
{
var
candidatenew
=
[];
// find candidate nodes which we can connect to
currentnodes
.
forEach
(
function
(
n
)
{
if
(
peerscache
.
indexOf
(
n
.
info
)
==
-
1
)
candidatenew
.
push
(
n
.
info
);
// (it comes from peers.cache)
peerscache
.
forEach
(
function
(
acachedpeer
)
{
if
(
// Add "a cached peer" to "candidate new" peers
// if the cached peer is not in the list of current node.
currentnodes
.
find
(
function
(
element
)
{
element
.
info
!=
acachedpeer
}
)
)
{
candidatenew
.
push
(
acachedpeer
);
}
}
);
if
(
candidatenew
.
length
>
0
)
...
...
@@ -134,19 +142,17 @@ function peerlist()
web3
.
bfa
.
admin
.
peers
(
gotAdminPeers
);
}
function
mayseal
()
// Function to determine if our defaultAccount is allowed to seal/mine.
// It will adjust the behaviour accordingly, i.e. stop or start mining.
function
mayseal
()
{
var
me
=
web3
.
eth
.
defaultAccount
;
if
(
undefined
==
me
)
{
// Failed to get default account information.
me
=
'
xxxx
'
}
me
=
me
.
toLowerCase
();
web3
.
eth
.
isMining
()
.
then
(
web3
.
eth
.
isMining
()
.
then
(
// returns a boolean whether or not we are currently mining/sealing.
function
(
isMining
)
{
...
...
@@ -179,7 +185,7 @@ function mayseal()
function
failedToGetIsMiningBool
(
x
)
{
// Probably geth is not running.
throw
new
Error
(
x
);
//
throw new Error(x);
}
);
}
...
...
@@ -188,6 +194,7 @@ function unlock()
{
if
(
lastUnlock
+
600
>
Date
.
now
()
/
1000
)
return
;
var
unlockedsomething
=
false
;
web3
.
bfa
.
personal
.
listWallets
(
function
pushone
(
x
)
{
...
...
@@ -208,13 +215,39 @@ function unlock()
var
addr
=
wallets
[
i
].
accounts
[
j
].
address
;
var
promise
=
web3
.
eth
.
personal
.
unlockAccount
(
addr
,
""
,
0
)
.
catch
(
error
=>
{
}
);
.
then
(
x
=>
{
if
(
x
)
{
console
.
log
(
"
Unlocked
"
+
addr
);
}
}
)
.
catch
(
error
=>
{}
);
promises
.
push
(
promise
);
unlockedsomething
=
true
;
}
}
lastUnlock
=
Date
.
now
()
/
1000
;
Promise
.
all
(
promises
)
.
then
(
function
()
{
if
(
unlockedsomething
)
{
web3
.
eth
.
isMining
()
.
then
(
function
()
{
web3
.
bfa
.
miner
.
stop
();
web3
.
bfa
.
miner
.
start
();
}
)
}
},
function
()
{}
);
}
);
lastUnlock
=
Date
.
now
()
/
1000
;
}
function
timer
()
...
...
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