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
39abd92c
Unverified
Commit
39abd92c
authored
Jun 08, 2020
by
ucwong
Committed by
GitHub
Jun 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethstats: use timer instead of time.sleep (#20924)
parent
45b75351
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
62 deletions
+71
-62
ethstats.go
ethstats/ethstats.go
+71
-62
No files found.
ethstats/ethstats.go
View file @
39abd92c
...
@@ -203,77 +203,86 @@ func (s *Service) loop() {
...
@@ -203,77 +203,86 @@ func (s *Service) loop() {
if
!
strings
.
Contains
(
path
,
"://"
)
{
if
!
strings
.
Contains
(
path
,
"://"
)
{
urls
=
[]
string
{
"wss://"
+
path
,
"ws://"
+
path
}
urls
=
[]
string
{
"wss://"
+
path
,
"ws://"
+
path
}
}
}
errTimer
:=
time
.
NewTimer
(
0
)
defer
errTimer
.
Stop
()
// Loop reporting until termination
// Loop reporting until termination
for
{
for
{
// Establish a websocket connection to the server on any supported URL
select
{
var
(
case
<-
quitCh
:
conn
*
websocket
.
Conn
return
err
error
case
<-
errTimer
.
C
:
)
// Establish a websocket connection to the server on any supported URL
dialer
:=
websocket
.
Dialer
{
HandshakeTimeout
:
5
*
time
.
Second
}
var
(
header
:=
make
(
http
.
Header
)
conn
*
websocket
.
Conn
header
.
Set
(
"origin"
,
"http://localhost"
)
err
error
for
_
,
url
:=
range
urls
{
)
conn
,
_
,
err
=
dialer
.
Dial
(
url
,
header
)
dialer
:=
websocket
.
Dialer
{
HandshakeTimeout
:
5
*
time
.
Second
}
if
err
==
nil
{
header
:=
make
(
http
.
Header
)
break
header
.
Set
(
"origin"
,
"http://localhost"
)
for
_
,
url
:=
range
urls
{
conn
,
_
,
err
=
dialer
.
Dial
(
url
,
header
)
if
err
==
nil
{
break
}
}
}
}
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Warn
(
"Stats server unreachable"
,
"err"
,
err
)
log
.
Warn
(
"Stats server unreachable"
,
"err"
,
err
)
errTimer
.
Reset
(
10
*
time
.
Second
)
time
.
Sleep
(
10
*
time
.
Second
)
continue
continue
}
}
// Authenticate the client with the server
// Authenticate the client with the server
if
err
=
s
.
login
(
conn
);
err
!=
nil
{
if
err
=
s
.
login
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Stats login failed"
,
"err"
,
err
)
log
.
Warn
(
"Stats login failed"
,
"err"
,
err
)
conn
.
Close
()
conn
.
Close
()
errTimer
.
Reset
(
10
*
time
.
Second
)
time
.
Sleep
(
10
*
time
.
Second
)
continue
continue
}
}
go
s
.
readLoop
(
conn
)
go
s
.
readLoop
(
conn
)
// Send the initial stats so our node looks decent from the get go
if
err
=
s
.
report
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Initial stats report failed"
,
"err"
,
err
)
conn
.
Close
()
continue
}
// Keep sending status updates until the connection breaks
fullReport
:=
time
.
NewTicker
(
15
*
time
.
Second
)
for
err
==
nil
{
// Send the initial stats so our node looks decent from the get go
select
{
if
err
=
s
.
report
(
conn
);
err
!=
nil
{
case
<-
quitCh
:
log
.
Warn
(
"Initial stats report failed"
,
"err"
,
err
)
fullReport
.
Stop
()
// Make sure the connection is closed
conn
.
Close
()
conn
.
Close
()
return
errTimer
.
Reset
(
0
)
continue
}
// Keep sending status updates until the connection breaks
fullReport
:=
time
.
NewTicker
(
15
*
time
.
Second
)
case
<-
fullReport
.
C
:
for
err
==
nil
{
if
err
=
s
.
report
(
conn
);
err
!=
nil
{
select
{
log
.
Warn
(
"Full stats report failed"
,
"err"
,
err
)
case
<-
quitCh
:
}
fullReport
.
Stop
()
case
list
:=
<-
s
.
histCh
:
// Make sure the connection is closed
if
err
=
s
.
reportHistory
(
conn
,
list
);
err
!=
nil
{
conn
.
Close
()
log
.
Warn
(
"Requested history report failed"
,
"err"
,
err
)
return
}
case
head
:=
<-
headCh
:
case
<-
fullReport
.
C
:
if
err
=
s
.
reportBlock
(
conn
,
head
);
err
!=
nil
{
if
err
=
s
.
report
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Block stats report failed"
,
"err"
,
err
)
log
.
Warn
(
"Full stats report failed"
,
"err"
,
err
)
}
}
if
err
=
s
.
reportPending
(
conn
);
err
!=
nil
{
case
list
:=
<-
s
.
histCh
:
log
.
Warn
(
"Post-block transaction stats report failed"
,
"err"
,
err
)
if
err
=
s
.
reportHistory
(
conn
,
list
);
err
!=
nil
{
}
log
.
Warn
(
"Requested history report failed"
,
"err"
,
err
)
case
<-
txCh
:
}
if
err
=
s
.
reportPending
(
conn
);
err
!=
nil
{
case
head
:=
<-
headCh
:
log
.
Warn
(
"Transaction stats report failed"
,
"err"
,
err
)
if
err
=
s
.
reportBlock
(
conn
,
head
);
err
!=
nil
{
log
.
Warn
(
"Block stats report failed"
,
"err"
,
err
)
}
if
err
=
s
.
reportPending
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Post-block transaction stats report failed"
,
"err"
,
err
)
}
case
<-
txCh
:
if
err
=
s
.
reportPending
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Transaction stats report failed"
,
"err"
,
err
)
}
}
}
}
}
fullReport
.
Stop
()
// Make sure the connection is closed
conn
.
Close
()
}
}
fullReport
.
Stop
()
// Make sure the connection is closed
conn
.
Close
()
}
}
}
}
...
...
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