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
2ba93747
Unverified
Commit
2ba93747
authored
8 years ago
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethstats: try both ws:// and wss:// if none specified
parent
dc4c59d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
10 deletions
+28
-10
ethstats.go
ethstats/ethstats.go
+28
-10
No files found.
ethstats/ethstats.go
View file @
2ba93747
...
...
@@ -22,10 +22,11 @@ import (
"errors"
"fmt"
"math/big"
"net"
"net/url"
"regexp"
"runtime"
"strconv"
"strings"
"time"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -123,17 +124,34 @@ func (s *Service) loop() {
// Loop reporting until termination
for
{
// Establish a websocket connection to the server and authenticate the node
url
:=
fmt
.
Sprintf
(
"%s/api"
,
s
.
host
)
if
!
strings
.
Contains
(
url
,
"://"
)
{
url
=
"wss://"
+
url
// Resolve the URL, defaulting to TLS, but falling back to none too
path
:=
fmt
.
Sprintf
(
"%s/api"
,
s
.
host
)
urls
:=
[]
string
{
path
}
if
parsed
,
err
:=
url
.
Parse
(
path
);
err
==
nil
&&
!
parsed
.
IsAbs
()
{
urls
=
[]
string
{
"wss://"
+
path
,
"ws://"
+
path
}
}
// Establish a websocket connection to the server on any supported URL
var
(
conf
*
websocket
.
Config
conn
*
websocket
.
Conn
err
error
)
for
_
,
url
:=
range
urls
{
if
conf
,
err
=
websocket
.
NewConfig
(
url
,
"http://localhost/"
);
err
!=
nil
{
continue
}
conf
.
Dialer
=
&
net
.
Dialer
{
Timeout
:
3
*
time
.
Second
}
if
conn
,
err
=
websocket
.
DialConfig
(
conf
);
err
==
nil
{
break
}
}
conn
,
err
:=
websocket
.
Dial
(
url
,
""
,
"http://localhost/"
)
if
err
!=
nil
{
log
.
Warn
(
"Stats server unreachable"
,
"err"
,
err
)
time
.
Sleep
(
10
*
time
.
Second
)
continue
}
// Authenticate the client with the server
in
:=
json
.
NewDecoder
(
conn
)
out
:=
json
.
NewEncoder
(
conn
)
...
...
@@ -244,12 +262,12 @@ func (s *Service) readLoop(conn *websocket.Conn, in *json.Decoder) {
// Make sure the request is valid and doesn't crash us
request
,
ok
:=
msg
[
"emit"
][
1
]
.
(
map
[
string
]
interface
{})
if
!
ok
{
log
.
Warn
(
"Invalid history request"
,
"msg"
,
msg
[
"emit"
][
1
])
return
log
.
Warn
(
"Invalid
stats
history request"
,
"msg"
,
msg
[
"emit"
][
1
])
continue
// Ethstats sometime sends invalid history requests, ignore those
}
list
,
ok
:=
request
[
"list"
]
.
([]
interface
{})
if
!
ok
{
log
.
Warn
(
"Invalid history block list"
,
"list"
,
request
[
"list"
])
log
.
Warn
(
"Invalid
stats
history block list"
,
"list"
,
request
[
"list"
])
return
}
// Convert the block number list to an integer list
...
...
@@ -257,7 +275,7 @@ func (s *Service) readLoop(conn *websocket.Conn, in *json.Decoder) {
for
i
,
num
:=
range
list
{
n
,
ok
:=
num
.
(
float64
)
if
!
ok
{
log
.
Warn
(
"Invalid history block number"
,
"number"
,
num
)
log
.
Warn
(
"Invalid
stats
history block number"
,
"number"
,
num
)
return
}
numbers
[
i
]
=
uint64
(
n
)
...
...
This diff is collapsed.
Click to expand it.
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