Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit a8ede7c

Browse files
kielbarryacud
authored andcommitted
ethstats: fix last golint warning (#16837)
1 parent 19714e0 commit a8ede7c

File tree

11 files changed

+137
-148
lines changed

11 files changed

+137
-148
lines changed

ethstats/ethstats.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ type nodeInfo struct {
362362

363363
// authMsg is the authentication infos needed to login to a monitoring server.
364364
type authMsg struct {
365-
Id string `json:"id"`
365+
ID string `json:"id"`
366366
Info nodeInfo `json:"info"`
367367
Secret string `json:"secret"`
368368
}
@@ -381,7 +381,7 @@ func (s *Service) login(conn *websocket.Conn) error {
381381
protocol = fmt.Sprintf("les/%d", les.ClientProtocolVersions[0])
382382
}
383383
auth := &authMsg{
384-
Id: s.node,
384+
ID: s.node,
385385
Info: nodeInfo{
386386
Name: s.node,
387387
Node: infos.Name,

internal/jsre/deps/web3.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

log/logger.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const timeKey = "t"
1212
const lvlKey = "lvl"
1313
const msgKey = "msg"
1414
const errorKey = "LOG15_ERROR"
15+
const skipLevel = 2
1516

1617
type Lvl int
1718

@@ -157,27 +158,27 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
157158
}
158159

159160
func (l *logger) Trace(msg string, ctx ...interface{}) {
160-
l.write(msg, LvlTrace, ctx, 2)
161+
l.write(msg, LvlTrace, ctx, skipLevel)
161162
}
162163

163164
func (l *logger) Debug(msg string, ctx ...interface{}) {
164-
l.write(msg, LvlDebug, ctx, 2)
165+
l.write(msg, LvlDebug, ctx, skipLevel)
165166
}
166167

167168
func (l *logger) Info(msg string, ctx ...interface{}) {
168-
l.write(msg, LvlInfo, ctx, 2)
169+
l.write(msg, LvlInfo, ctx, skipLevel)
169170
}
170171

171172
func (l *logger) Warn(msg string, ctx ...interface{}) {
172-
l.write(msg, LvlWarn, ctx, 2)
173+
l.write(msg, LvlWarn, ctx, skipLevel)
173174
}
174175

175176
func (l *logger) Error(msg string, ctx ...interface{}) {
176-
l.write(msg, LvlError, ctx, 2)
177+
l.write(msg, LvlError, ctx, skipLevel)
177178
}
178179

179180
func (l *logger) Crit(msg string, ctx ...interface{}) {
180-
l.write(msg, LvlCrit, ctx, 2)
181+
l.write(msg, LvlCrit, ctx, skipLevel)
181182
os.Exit(1)
182183
}
183184

log/root.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,32 @@ func Root() Logger {
3131

3232
// Trace is a convenient alias for Root().Trace
3333
func Trace(msg string, ctx ...interface{}) {
34-
root.write(msg, LvlTrace, ctx, 2)
34+
root.write(msg, LvlTrace, ctx, skipLevel)
3535
}
3636

3737
// Debug is a convenient alias for Root().Debug
3838
func Debug(msg string, ctx ...interface{}) {
39-
root.write(msg, LvlDebug, ctx, 2)
39+
root.write(msg, LvlDebug, ctx, skipLevel)
4040
}
4141

4242
// Info is a convenient alias for Root().Info
4343
func Info(msg string, ctx ...interface{}) {
44-
root.write(msg, LvlInfo, ctx, 2)
44+
root.write(msg, LvlInfo, ctx, skipLevel)
4545
}
4646

4747
// Warn is a convenient alias for Root().Warn
4848
func Warn(msg string, ctx ...interface{}) {
49-
root.write(msg, LvlWarn, ctx, 2)
49+
root.write(msg, LvlWarn, ctx, skipLevel)
5050
}
5151

5252
// Error is a convenient alias for Root().Error
5353
func Error(msg string, ctx ...interface{}) {
54-
root.write(msg, LvlError, ctx, 2)
54+
root.write(msg, LvlError, ctx, skipLevel)
5555
}
5656

5757
// Crit is a convenient alias for Root().Crit
5858
func Crit(msg string, ctx ...interface{}) {
59-
root.write(msg, LvlCrit, ctx, 2)
59+
root.write(msg, LvlCrit, ctx, skipLevel)
6060
os.Exit(1)
6161
}
6262

p2p/nat/natupnp_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
)
3030

3131
func TestUPNP_DDWRT(t *testing.T) {
32-
t.Skip("broken")
3332
if runtime.GOOS == "windows" {
3433
t.Skipf("disabled to avoid firewall prompt")
3534
}

p2p/rlpx_test.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/ethereum/go-ethereum/crypto/ecies"
3636
"github.com/ethereum/go-ethereum/crypto/sha3"
3737
"github.com/ethereum/go-ethereum/p2p/discover"
38+
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
3839
"github.com/ethereum/go-ethereum/rlp"
3940
)
4041

@@ -159,7 +160,7 @@ func TestProtocolHandshake(t *testing.T) {
159160
wg sync.WaitGroup
160161
)
161162

162-
fd0, fd1, err := tcpPipe()
163+
fd0, fd1, err := pipes.TCPPipe()
163164
if err != nil {
164165
t.Fatal(err)
165166
}
@@ -601,31 +602,3 @@ func TestHandshakeForwardCompatibility(t *testing.T) {
601602
t.Errorf("ingress-mac('foo') mismatch:\ngot %x\nwant %x", fooIngressHash, wantFooIngressHash)
602603
}
603604
}
604-
605-
// tcpPipe creates an in process full duplex pipe based on a localhost TCP socket
606-
func tcpPipe() (net.Conn, net.Conn, error) {
607-
l, err := net.Listen("tcp", "127.0.0.1:0")
608-
if err != nil {
609-
return nil, nil, err
610-
}
611-
defer l.Close()
612-
613-
var aconn net.Conn
614-
aerr := make(chan error, 1)
615-
go func() {
616-
var err error
617-
aconn, err = l.Accept()
618-
aerr <- err
619-
}()
620-
621-
dconn, err := net.Dial("tcp", l.Addr().String())
622-
if err != nil {
623-
<-aerr
624-
return nil, nil, err
625-
}
626-
if err := <-aerr; err != nil {
627-
dconn.Close()
628-
return nil, nil, err
629-
}
630-
return aconn, dconn, nil
631-
}

p2p/simulations/adapters/inproc.go

Lines changed: 4 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717
package adapters
1818

1919
import (
20-
"crypto/rand"
2120
"errors"
2221
"fmt"
2322
"math"
2423
"net"
25-
"os"
2624
"sync"
27-
"syscall"
2825

2926
"github.com/ethereum/go-ethereum/event"
3027
"github.com/ethereum/go-ethereum/log"
3128
"github.com/ethereum/go-ethereum/node"
3229
"github.com/ethereum/go-ethereum/p2p"
3330
"github.com/ethereum/go-ethereum/p2p/discover"
31+
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
3432
"github.com/ethereum/go-ethereum/rpc"
3533
)
3634

@@ -49,7 +47,7 @@ type SimAdapter struct {
4947
// the adapter uses a net.Pipe for in-memory simulated network connections
5048
func NewSimAdapter(services map[string]ServiceFunc) *SimAdapter {
5149
return &SimAdapter{
52-
pipe: netPipe,
50+
pipe: pipes.NetPipe,
5351
nodes: make(map[discover.NodeID]*SimNode),
5452
services: services,
5553
}
@@ -61,15 +59,15 @@ func NewSimAdapter(services map[string]ServiceFunc) *SimAdapter {
6159
// the adapter uses a OS socketpairs for in-memory simulated network connections
6260
func NewSocketAdapter(services map[string]ServiceFunc) *SimAdapter {
6361
return &SimAdapter{
64-
pipe: socketPipe,
62+
pipe: pipes.SocketPipe,
6563
nodes: make(map[discover.NodeID]*SimNode),
6664
services: services,
6765
}
6866
}
6967

7068
func NewTCPAdapter(services map[string]ServiceFunc) *SimAdapter {
7169
return &SimAdapter{
72-
pipe: tcpPipe,
70+
pipe: pipes.TCPPipe,
7371
nodes: make(map[discover.NodeID]*SimNode),
7472
services: services,
7573
}
@@ -348,34 +346,6 @@ func (sn *SimNode) NodeInfo() *p2p.NodeInfo {
348346
return server.NodeInfo()
349347
}
350348

351-
// socketPipe creates an in process full duplex pipe based on OS sockets
352-
// credit to @lmars & Flynn
353-
// https://github.com/flynn/flynn/blob/master/host/containerinit/init.go#L743-L749
354-
// using this in large simulations requires raising OS's max open file limit
355-
func socketPipe() (net.Conn, net.Conn, error) {
356-
pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
357-
if err != nil {
358-
return nil, nil, err
359-
}
360-
nameb := make([]byte, 8)
361-
_, err = rand.Read(nameb)
362-
if err != nil {
363-
return nil, nil, err
364-
}
365-
f1 := os.NewFile(uintptr(pair[0]), string(nameb)+".out")
366-
f2 := os.NewFile(uintptr(pair[1]), string(nameb)+".in")
367-
pipe1, err := net.FileConn(f1)
368-
if err != nil {
369-
return nil, nil, err
370-
}
371-
pipe2, err := net.FileConn(f2)
372-
if err != nil {
373-
return nil, nil, err
374-
}
375-
376-
return pipe1, pipe2, nil
377-
}
378-
379349
func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int) error {
380350
switch v := conn.(type) {
381351
case *net.UnixConn:
@@ -390,64 +360,3 @@ func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int)
390360
}
391361
return nil
392362
}
393-
394-
// netPipe wraps net.Pipe in a signature returning an error
395-
func netPipe() (net.Conn, net.Conn, error) {
396-
p1, p2 := net.Pipe()
397-
return p1, p2, nil
398-
}
399-
400-
// tcpPipe creates an in process full duplex pipe based on a localhost TCP socket
401-
func tcpPipe() (net.Conn, net.Conn, error) {
402-
type result struct {
403-
conn net.Conn
404-
err error
405-
}
406-
407-
cl := make(chan result)
408-
cd := make(chan result)
409-
410-
start := make(chan net.Addr)
411-
412-
go func(res chan result, start chan net.Addr) {
413-
// resolve
414-
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
415-
if err != nil {
416-
res <- result{err: err}
417-
return
418-
}
419-
// listen
420-
l, err := net.ListenTCP("tcp", addr)
421-
if err != nil {
422-
res <- result{err: err}
423-
return
424-
}
425-
start <- l.Addr()
426-
c, err := l.AcceptTCP()
427-
if err != nil {
428-
res <- result{err: err}
429-
return
430-
}
431-
res <- result{conn: c}
432-
}(cl, start)
433-
434-
go func(res chan result, start chan net.Addr) {
435-
addr := <-start
436-
c, err := net.DialTCP("tcp", nil, addr.(*net.TCPAddr))
437-
if err != nil {
438-
res <- result{err: err}
439-
return
440-
}
441-
res <- result{conn: c}
442-
}(cd, start)
443-
444-
a := <-cl
445-
if a.err != nil {
446-
return nil, nil, a.err
447-
}
448-
b := <-cd
449-
if b.err != nil {
450-
return nil, nil, b.err
451-
}
452-
return a.conn, b.conn, nil
453-
}

p2p/simulations/adapters/inproc_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import (
2222
"fmt"
2323
"testing"
2424
"time"
25+
26+
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
2527
)
2628

2729
func TestSocketPipe(t *testing.T) {
28-
c1, c2, err := socketPipe()
30+
c1, c2, err := pipes.SocketPipe()
2931
if err != nil {
3032
t.Fatal(err)
3133
}
@@ -74,7 +76,7 @@ func TestSocketPipe(t *testing.T) {
7476
}
7577

7678
func TestSocketPipeBidirections(t *testing.T) {
77-
c1, c2, err := socketPipe()
79+
c1, c2, err := pipes.SocketPipe()
7880
if err != nil {
7981
t.Fatal(err)
8082
}
@@ -138,7 +140,7 @@ func TestSocketPipeBidirections(t *testing.T) {
138140
}
139141

140142
func TestTcpPipe(t *testing.T) {
141-
c1, c2, err := tcpPipe()
143+
c1, c2, err := pipes.TCPPipe()
142144
if err != nil {
143145
t.Fatal(err)
144146
}
@@ -183,7 +185,7 @@ func TestTcpPipe(t *testing.T) {
183185
}
184186

185187
func TestTcpPipeBidirections(t *testing.T) {
186-
c1, c2, err := tcpPipe()
188+
c1, c2, err := pipes.TCPPipe()
187189
if err != nil {
188190
t.Fatal(err)
189191
}
@@ -246,7 +248,7 @@ func TestTcpPipeBidirections(t *testing.T) {
246248
}
247249

248250
func TestNetPipe(t *testing.T) {
249-
c1, c2, err := netPipe()
251+
c1, c2, err := pipes.NetPipe()
250252
if err != nil {
251253
t.Fatal(err)
252254
}
@@ -295,7 +297,7 @@ func TestNetPipe(t *testing.T) {
295297
}
296298

297299
func TestNetPipeBidirections(t *testing.T) {
298-
c1, c2, err := netPipe()
300+
c1, c2, err := pipes.NetPipe()
299301
if err != nil {
300302
t.Fatal(err)
301303
}

0 commit comments

Comments
 (0)