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
e9837ab5
Commit
e9837ab5
authored
6 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
issue#4 resuelto + fastconnect
parent
38eefbfd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bin/libbfa.js
+7
-0
7 additions, 0 deletions
bin/libbfa.js
bin/monitor.js
+85
-13
85 additions, 13 deletions
bin/monitor.js
bin/start.sh
+5
-3
5 additions, 3 deletions
bin/start.sh
with
97 additions
and
16 deletions
bin/libbfa.js
+
7
−
0
View file @
e9837ab5
...
...
@@ -107,6 +107,13 @@ module.exports = class Libbfa
params
:
0
}]
});
w3
.
eth
.
extend
({
methods
:
[{
name
:
'
bfaAdminaddPeer
'
,
call
:
'
admin_addPeer
'
,
params
:
1
}]
});
w3
.
eth
.
personal
.
extend
({
methods
:
[{
name
:
'
bfalistWallets
'
,
...
...
This diff is collapsed.
Click to expand it.
bin/monitor.js
+
85
−
13
View file @
e9837ab5
...
...
@@ -7,29 +7,101 @@
const
Libbfa
=
require
(
process
.
env
.
BFAHOME
+
'
/bin/libbfa.js
'
);
var
bfa
=
new
Libbfa
();
var
web3
=
bfa
.
newweb3
();
var
now
;
function
monitor
()
function
pluralEnglish
(
num
,
single
,
plural
)
{
if
(
num
==
1
)
return
single
;
return
plural
;
}
function
peerlist
()
{
web3
.
eth
.
bfaAdminpeers
().
then
(
function
gotAdminPeers
(
nodelist
)
{
var
peers
=
[];
var
now
=
new
Date
();
var
nowpeers
=
[];
var
peers
=
[];
var
newpeers
=
[];
if
(
bfa
.
fs
.
existsSync
(
bfa
.
networkdir
+
'
/peers.cache
'
)
)
{
var
data
=
bfa
.
fs
.
readFileSync
(
bfa
.
networkdir
+
'
/peers.cache
'
).
toString
();
if
(
data
.
length
>
0
)
peers
=
data
.
split
(
/
\r?\n
/
);
var
i
=
peers
.
length
;
// for some odd reason, I keep seeing empty entries
while
(
i
--
>
0
)
if
(
peers
[
i
]
==
''
)
peers
.
splice
(
i
,
1
);
}
nodelist
.
forEach
(
function
(
node
)
{
if
(
typeof
(
node
.
protocols
.
eth
)
==
'
object
'
)
{
var
dir
=
"
out
"
;
if
(
node
.
network
.
inbound
)
dir
=
"
in
"
;
peers
.
push
(
"
peer
"
+
dir
+
"
:
"
+
node
.
enode
);
if
(
'
object
'
==
typeof
(
node
.
protocols
.
eth
)
)
{
// default info - likely to get overwritten.
var
info
=
"
<
"
+
node
.
id
+
"
>
"
;
var
dir
=
""
;
if
(
undefined
!=
node
.
network
)
{
if
(
'
boolean
'
==
typeof
(
node
.
network
.
inbound
)
)
{
if
(
node
.
network
.
inbound
)
dir
=
"
in
"
;
else
dir
=
"
out
"
;
}
if
(
'
string
'
==
typeof
(
node
.
enode
)
)
{
info
=
node
.
enode
;
if
(
peers
.
indexOf
(
node
.
enode
)
==
-
1
)
newpeers
.
push
(
node
.
enode
);
}
else
{
info
=
""
;
if
(
undefined
!=
node
.
id
)
info
+=
"
<
"
+
node
.
id
+
"
>
"
;
if
(
undefined
!=
node
.
network
.
remoteAddress
)
{
if
(
info
!=
""
)
info
+=
"
@
"
;
info
+=
node
.
network
.
remoteAddress
;
}
}
}
nowpeers
.
push
(
"
peer
"
+
dir
+
"
:
"
+
info
);
}
}
);
// write network/status
bfa
.
fs
.
writeFileSync
(
bfa
.
networkdir
+
'
/status
'
,
"
UTC:
"
+
now
.
toUTCString
()
+
"
\n
"
+
"
BFA peers:
"
+
peers
.
length
+
"
\n
"
+
peers
.
sort
().
join
(
"
\n
"
)
+
"
\n
"
,
+
"
BFA peers:
"
+
nowpeers
.
length
+
"
\n
"
+
nowpeers
.
sort
().
join
(
"
\n
"
)
+
"
\n
"
,
{
mode
:
0o644
}
);
// Try to connect to a random node if we have very few peers
if
(
nowpeers
.
length
<
5
&&
peers
.
length
>
0
)
{
var
i
=
Math
.
floor
(
Math
.
random
()
*
peers
.
length
);
var
enode
=
peers
[
i
];
console
.
log
(
"
We have
"
+
nowpeers
.
length
+
"
peer
"
+
pluralEnglish
(
nowpeers
.
length
,
''
,
'
s
'
)
+
"
, so will try to connect to
"
+
enode
);
web3
.
eth
.
bfaAdminaddPeer
(
enode
);
}
// write network/peers.cache
// peers.cache is a list of peers we have connected out to in the past.
peers
.
concat
(
newpeers
);
if
(
peers
.
length
>
100
)
peers
.
splice
(
0
,
peers
.
length
-
100
);
bfa
.
fs
.
writeFileSync
(
bfa
.
networkdir
+
'
/peers.cache
'
,
peers
.
join
(
"
\n
"
)
+
"
\n
"
,
{
mode
:
0o644
}
);
},
...
...
@@ -97,9 +169,9 @@ function mayseal()
function
timer
()
{
now
=
new
Date
();
monitor
();
peerlist
();
mayseal
();
}
peerlist
();
setInterval
(
timer
,
60
*
1000
);
This diff is collapsed.
Click to expand it.
bin/start.sh
+
5
−
3
View file @
e9837ab5
...
...
@@ -68,9 +68,11 @@ function startmonitor
echo
"A monitor is already running."
false
)
||
exit
monitor.js &
echo
$!
>
$pidfile
wait
(
monitor.js &
echo
$!
>
$pidfile
wait
)
2>&1 |
${
BFAHOME
}
/bin/log.sh
${
BFANODEDIR
}
/log &
)
9>>
$pidfile
}
...
...
This diff is collapsed.
Click to expand it.
Robert Martin-Legene
@robert
mentioned in issue
#4 (closed)
·
6 years ago
mentioned in issue
#4 (closed)
mentioned in issue #4
Toggle commit list
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