ethstats: fix last golint warning (#16837)

This commit is contained in:
kiel barry 2018-05-30 01:36:02 -07:00 committed by stolen
parent 19714e0230
commit a8ede7cc83
11 changed files with 137 additions and 148 deletions

View file

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

View file

@ -2307,7 +2307,7 @@ var toChecksumAddress = function (address) {
};
/**
* Transforms given string to valid 20 bytes-length address with 0x prefix
* Transforms given string to valid 20 bytes-length addres with 0x prefix
*
* @method toAddress
* @param {String} address

View file

@ -12,6 +12,7 @@ const timeKey = "t"
const lvlKey = "lvl"
const msgKey = "msg"
const errorKey = "LOG15_ERROR"
const skipLevel = 2
type Lvl int
@ -157,27 +158,27 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
}
func (l *logger) Trace(msg string, ctx ...interface{}) {
l.write(msg, LvlTrace, ctx, 2)
l.write(msg, LvlTrace, ctx, skipLevel)
}
func (l *logger) Debug(msg string, ctx ...interface{}) {
l.write(msg, LvlDebug, ctx, 2)
l.write(msg, LvlDebug, ctx, skipLevel)
}
func (l *logger) Info(msg string, ctx ...interface{}) {
l.write(msg, LvlInfo, ctx, 2)
l.write(msg, LvlInfo, ctx, skipLevel)
}
func (l *logger) Warn(msg string, ctx ...interface{}) {
l.write(msg, LvlWarn, ctx, 2)
l.write(msg, LvlWarn, ctx, skipLevel)
}
func (l *logger) Error(msg string, ctx ...interface{}) {
l.write(msg, LvlError, ctx, 2)
l.write(msg, LvlError, ctx, skipLevel)
}
func (l *logger) Crit(msg string, ctx ...interface{}) {
l.write(msg, LvlCrit, ctx, 2)
l.write(msg, LvlCrit, ctx, skipLevel)
os.Exit(1)
}

View file

@ -31,32 +31,32 @@ func Root() Logger {
// Trace is a convenient alias for Root().Trace
func Trace(msg string, ctx ...interface{}) {
root.write(msg, LvlTrace, ctx, 2)
root.write(msg, LvlTrace, ctx, skipLevel)
}
// Debug is a convenient alias for Root().Debug
func Debug(msg string, ctx ...interface{}) {
root.write(msg, LvlDebug, ctx, 2)
root.write(msg, LvlDebug, ctx, skipLevel)
}
// Info is a convenient alias for Root().Info
func Info(msg string, ctx ...interface{}) {
root.write(msg, LvlInfo, ctx, 2)
root.write(msg, LvlInfo, ctx, skipLevel)
}
// Warn is a convenient alias for Root().Warn
func Warn(msg string, ctx ...interface{}) {
root.write(msg, LvlWarn, ctx, 2)
root.write(msg, LvlWarn, ctx, skipLevel)
}
// Error is a convenient alias for Root().Error
func Error(msg string, ctx ...interface{}) {
root.write(msg, LvlError, ctx, 2)
root.write(msg, LvlError, ctx, skipLevel)
}
// Crit is a convenient alias for Root().Crit
func Crit(msg string, ctx ...interface{}) {
root.write(msg, LvlCrit, ctx, 2)
root.write(msg, LvlCrit, ctx, skipLevel)
os.Exit(1)
}

View file

@ -29,7 +29,6 @@ import (
)
func TestUPNP_DDWRT(t *testing.T) {
t.Skip("broken")
if runtime.GOOS == "windows" {
t.Skipf("disabled to avoid firewall prompt")
}

View file

@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
"github.com/ethereum/go-ethereum/rlp"
)
@ -159,7 +160,7 @@ func TestProtocolHandshake(t *testing.T) {
wg sync.WaitGroup
)
fd0, fd1, err := tcpPipe()
fd0, fd1, err := pipes.TCPPipe()
if err != nil {
t.Fatal(err)
}
@ -601,31 +602,3 @@ func TestHandshakeForwardCompatibility(t *testing.T) {
t.Errorf("ingress-mac('foo') mismatch:\ngot %x\nwant %x", fooIngressHash, wantFooIngressHash)
}
}
// tcpPipe creates an in process full duplex pipe based on a localhost TCP socket
func tcpPipe() (net.Conn, net.Conn, error) {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return nil, nil, err
}
defer l.Close()
var aconn net.Conn
aerr := make(chan error, 1)
go func() {
var err error
aconn, err = l.Accept()
aerr <- err
}()
dconn, err := net.Dial("tcp", l.Addr().String())
if err != nil {
<-aerr
return nil, nil, err
}
if err := <-aerr; err != nil {
dconn.Close()
return nil, nil, err
}
return aconn, dconn, nil
}

View file

@ -17,20 +17,18 @@
package adapters
import (
"crypto/rand"
"errors"
"fmt"
"math"
"net"
"os"
"sync"
"syscall"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
"github.com/ethereum/go-ethereum/rpc"
)
@ -49,7 +47,7 @@ type SimAdapter struct {
// the adapter uses a net.Pipe for in-memory simulated network connections
func NewSimAdapter(services map[string]ServiceFunc) *SimAdapter {
return &SimAdapter{
pipe: netPipe,
pipe: pipes.NetPipe,
nodes: make(map[discover.NodeID]*SimNode),
services: services,
}
@ -61,7 +59,7 @@ func NewSimAdapter(services map[string]ServiceFunc) *SimAdapter {
// the adapter uses a OS socketpairs for in-memory simulated network connections
func NewSocketAdapter(services map[string]ServiceFunc) *SimAdapter {
return &SimAdapter{
pipe: socketPipe,
pipe: pipes.SocketPipe,
nodes: make(map[discover.NodeID]*SimNode),
services: services,
}
@ -69,7 +67,7 @@ func NewSocketAdapter(services map[string]ServiceFunc) *SimAdapter {
func NewTCPAdapter(services map[string]ServiceFunc) *SimAdapter {
return &SimAdapter{
pipe: tcpPipe,
pipe: pipes.TCPPipe,
nodes: make(map[discover.NodeID]*SimNode),
services: services,
}
@ -348,34 +346,6 @@ func (sn *SimNode) NodeInfo() *p2p.NodeInfo {
return server.NodeInfo()
}
// socketPipe creates an in process full duplex pipe based on OS sockets
// credit to @lmars & Flynn
// https://github.com/flynn/flynn/blob/master/host/containerinit/init.go#L743-L749
// using this in large simulations requires raising OS's max open file limit
func socketPipe() (net.Conn, net.Conn, error) {
pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
if err != nil {
return nil, nil, err
}
nameb := make([]byte, 8)
_, err = rand.Read(nameb)
if err != nil {
return nil, nil, err
}
f1 := os.NewFile(uintptr(pair[0]), string(nameb)+".out")
f2 := os.NewFile(uintptr(pair[1]), string(nameb)+".in")
pipe1, err := net.FileConn(f1)
if err != nil {
return nil, nil, err
}
pipe2, err := net.FileConn(f2)
if err != nil {
return nil, nil, err
}
return pipe1, pipe2, nil
}
func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int) error {
switch v := conn.(type) {
case *net.UnixConn:
@ -390,64 +360,3 @@ func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int)
}
return nil
}
// netPipe wraps net.Pipe in a signature returning an error
func netPipe() (net.Conn, net.Conn, error) {
p1, p2 := net.Pipe()
return p1, p2, nil
}
// tcpPipe creates an in process full duplex pipe based on a localhost TCP socket
func tcpPipe() (net.Conn, net.Conn, error) {
type result struct {
conn net.Conn
err error
}
cl := make(chan result)
cd := make(chan result)
start := make(chan net.Addr)
go func(res chan result, start chan net.Addr) {
// resolve
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
if err != nil {
res <- result{err: err}
return
}
// listen
l, err := net.ListenTCP("tcp", addr)
if err != nil {
res <- result{err: err}
return
}
start <- l.Addr()
c, err := l.AcceptTCP()
if err != nil {
res <- result{err: err}
return
}
res <- result{conn: c}
}(cl, start)
go func(res chan result, start chan net.Addr) {
addr := <-start
c, err := net.DialTCP("tcp", nil, addr.(*net.TCPAddr))
if err != nil {
res <- result{err: err}
return
}
res <- result{conn: c}
}(cd, start)
a := <-cl
if a.err != nil {
return nil, nil, a.err
}
b := <-cd
if b.err != nil {
return nil, nil, b.err
}
return a.conn, b.conn, nil
}

View file

@ -22,10 +22,12 @@ import (
"fmt"
"testing"
"time"
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
)
func TestSocketPipe(t *testing.T) {
c1, c2, err := socketPipe()
c1, c2, err := pipes.SocketPipe()
if err != nil {
t.Fatal(err)
}
@ -74,7 +76,7 @@ func TestSocketPipe(t *testing.T) {
}
func TestSocketPipeBidirections(t *testing.T) {
c1, c2, err := socketPipe()
c1, c2, err := pipes.SocketPipe()
if err != nil {
t.Fatal(err)
}
@ -138,7 +140,7 @@ func TestSocketPipeBidirections(t *testing.T) {
}
func TestTcpPipe(t *testing.T) {
c1, c2, err := tcpPipe()
c1, c2, err := pipes.TCPPipe()
if err != nil {
t.Fatal(err)
}
@ -183,7 +185,7 @@ func TestTcpPipe(t *testing.T) {
}
func TestTcpPipeBidirections(t *testing.T) {
c1, c2, err := tcpPipe()
c1, c2, err := pipes.TCPPipe()
if err != nil {
t.Fatal(err)
}
@ -246,7 +248,7 @@ func TestTcpPipeBidirections(t *testing.T) {
}
func TestNetPipe(t *testing.T) {
c1, c2, err := netPipe()
c1, c2, err := pipes.NetPipe()
if err != nil {
t.Fatal(err)
}
@ -295,7 +297,7 @@ func TestNetPipe(t *testing.T) {
}
func TestNetPipeBidirections(t *testing.T) {
c1, c2, err := netPipe()
c1, c2, err := pipes.NetPipe()
if err != nil {
t.Fatal(err)
}

View file

@ -382,6 +382,27 @@ func (net *Network) GetNodeByName(name string) *Node {
return net.getNodeByName(name)
}
// GetNodes returns the existing nodes
func (net *Network) GetNodes() (nodes []*Node) {
net.lock.Lock()
defer net.lock.Unlock()
nodes = append(nodes, net.Nodes...)
return nodes
}
// GetUpNodes returns the existing nodes that are up
func (net *Network) GetUpNodes() (nodes []*Node) {
net.lock.Lock()
defer net.lock.Unlock()
for _, n := range net.Nodes {
if n.Up {
nodes = append(nodes, n)
}
}
return nodes
}
func (net *Network) getNode(id discover.NodeID) *Node {
i, found := net.nodeMap[id]
if !found {

View file

@ -0,0 +1,86 @@
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package pipes
import (
"crypto/rand"
"net"
"os"
"syscall"
)
// NetPipe wraps net.Pipe in a signature returning an error
func NetPipe() (net.Conn, net.Conn, error) {
p1, p2 := net.Pipe()
return p1, p2, nil
}
// TCPPipe creates an in process full duplex pipe based on a localhost TCP socket
func TCPPipe() (net.Conn, net.Conn, error) {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return nil, nil, err
}
defer l.Close()
var aconn net.Conn
aerr := make(chan error, 1)
go func() {
var err error
aconn, err = l.Accept()
aerr <- err
}()
dconn, err := net.Dial("tcp", l.Addr().String())
if err != nil {
<-aerr
return nil, nil, err
}
if err := <-aerr; err != nil {
dconn.Close()
return nil, nil, err
}
return aconn, dconn, nil
}
// SocketPipe creates an in process full duplex pipe based on OS sockets
// credit to @lmars & Flynn
// https://github.com/flynn/flynn/blob/master/host/containerinit/init.go#L743-L749
// using this in large simulations requires raising OS's max open file limit
func SocketPipe() (net.Conn, net.Conn, error) {
pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
if err != nil {
return nil, nil, err
}
nameb := make([]byte, 8)
_, err = rand.Read(nameb)
if err != nil {
return nil, nil, err
}
f1 := os.NewFile(uintptr(pair[0]), string(nameb)+".out")
f2 := os.NewFile(uintptr(pair[1]), string(nameb)+".in")
pipe1, err := net.FileConn(f1)
if err != nil {
return nil, nil, err
}
pipe2, err := net.FileConn(f2)
if err != nil {
return nil, nil, err
}
return pipe1, pipe2, nil
}

View file

@ -91,9 +91,7 @@ func (s *ProtocolSession) trigger(trig Trigger) error {
errc := make(chan error)
go func() {
log.Trace(fmt.Sprintf("trigger %v (%v)....", trig.Msg, trig.Code))
errc <- mockNode.Trigger(&trig)
log.Trace(fmt.Sprintf("triggered %v (%v)", trig.Msg, trig.Code))
}()
t := trig.Timeout