mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
ethstats: fix last golint warning (#16837)
This commit is contained in:
parent
19714e0230
commit
a8ede7cc83
11 changed files with 137 additions and 148 deletions
|
|
@ -362,7 +362,7 @@ type nodeInfo struct {
|
||||||
|
|
||||||
// authMsg is the authentication infos needed to login to a monitoring server.
|
// authMsg is the authentication infos needed to login to a monitoring server.
|
||||||
type authMsg struct {
|
type authMsg struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Info nodeInfo `json:"info"`
|
Info nodeInfo `json:"info"`
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
}
|
}
|
||||||
|
|
@ -381,7 +381,7 @@ func (s *Service) login(conn *websocket.Conn) error {
|
||||||
protocol = fmt.Sprintf("les/%d", les.ClientProtocolVersions[0])
|
protocol = fmt.Sprintf("les/%d", les.ClientProtocolVersions[0])
|
||||||
}
|
}
|
||||||
auth := &authMsg{
|
auth := &authMsg{
|
||||||
Id: s.node,
|
ID: s.node,
|
||||||
Info: nodeInfo{
|
Info: nodeInfo{
|
||||||
Name: s.node,
|
Name: s.node,
|
||||||
Node: infos.Name,
|
Node: infos.Name,
|
||||||
|
|
|
||||||
|
|
@ -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
|
* @method toAddress
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ const timeKey = "t"
|
||||||
const lvlKey = "lvl"
|
const lvlKey = "lvl"
|
||||||
const msgKey = "msg"
|
const msgKey = "msg"
|
||||||
const errorKey = "LOG15_ERROR"
|
const errorKey = "LOG15_ERROR"
|
||||||
|
const skipLevel = 2
|
||||||
|
|
||||||
type Lvl int
|
type Lvl int
|
||||||
|
|
||||||
|
|
@ -157,27 +158,27 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) Trace(msg string, ctx ...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{}) {
|
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{}) {
|
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{}) {
|
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{}) {
|
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{}) {
|
func (l *logger) Crit(msg string, ctx ...interface{}) {
|
||||||
l.write(msg, LvlCrit, ctx, 2)
|
l.write(msg, LvlCrit, ctx, skipLevel)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
12
log/root.go
12
log/root.go
|
|
@ -31,32 +31,32 @@ func Root() Logger {
|
||||||
|
|
||||||
// Trace is a convenient alias for Root().Trace
|
// Trace is a convenient alias for Root().Trace
|
||||||
func Trace(msg string, ctx ...interface{}) {
|
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
|
// Debug is a convenient alias for Root().Debug
|
||||||
func Debug(msg string, ctx ...interface{}) {
|
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
|
// Info is a convenient alias for Root().Info
|
||||||
func Info(msg string, ctx ...interface{}) {
|
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
|
// Warn is a convenient alias for Root().Warn
|
||||||
func Warn(msg string, ctx ...interface{}) {
|
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
|
// Error is a convenient alias for Root().Error
|
||||||
func Error(msg string, ctx ...interface{}) {
|
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
|
// Crit is a convenient alias for Root().Crit
|
||||||
func Crit(msg string, ctx ...interface{}) {
|
func Crit(msg string, ctx ...interface{}) {
|
||||||
root.write(msg, LvlCrit, ctx, 2)
|
root.write(msg, LvlCrit, ctx, skipLevel)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUPNP_DDWRT(t *testing.T) {
|
func TestUPNP_DDWRT(t *testing.T) {
|
||||||
t.Skip("broken")
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
t.Skipf("disabled to avoid firewall prompt")
|
t.Skipf("disabled to avoid firewall prompt")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto/ecies"
|
"github.com/ethereum/go-ethereum/crypto/ecies"
|
||||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -159,7 +160,7 @@ func TestProtocolHandshake(t *testing.T) {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
)
|
)
|
||||||
|
|
||||||
fd0, fd1, err := tcpPipe()
|
fd0, fd1, err := pipes.TCPPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -601,31 +602,3 @@ func TestHandshakeForwardCompatibility(t *testing.T) {
|
||||||
t.Errorf("ingress-mac('foo') mismatch:\ngot %x\nwant %x", fooIngressHash, wantFooIngressHash)
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -17,20 +17,18 @@
|
||||||
package adapters
|
package adapters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"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
|
// the adapter uses a net.Pipe for in-memory simulated network connections
|
||||||
func NewSimAdapter(services map[string]ServiceFunc) *SimAdapter {
|
func NewSimAdapter(services map[string]ServiceFunc) *SimAdapter {
|
||||||
return &SimAdapter{
|
return &SimAdapter{
|
||||||
pipe: netPipe,
|
pipe: pipes.NetPipe,
|
||||||
nodes: make(map[discover.NodeID]*SimNode),
|
nodes: make(map[discover.NodeID]*SimNode),
|
||||||
services: services,
|
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
|
// the adapter uses a OS socketpairs for in-memory simulated network connections
|
||||||
func NewSocketAdapter(services map[string]ServiceFunc) *SimAdapter {
|
func NewSocketAdapter(services map[string]ServiceFunc) *SimAdapter {
|
||||||
return &SimAdapter{
|
return &SimAdapter{
|
||||||
pipe: socketPipe,
|
pipe: pipes.SocketPipe,
|
||||||
nodes: make(map[discover.NodeID]*SimNode),
|
nodes: make(map[discover.NodeID]*SimNode),
|
||||||
services: services,
|
services: services,
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +67,7 @@ func NewSocketAdapter(services map[string]ServiceFunc) *SimAdapter {
|
||||||
|
|
||||||
func NewTCPAdapter(services map[string]ServiceFunc) *SimAdapter {
|
func NewTCPAdapter(services map[string]ServiceFunc) *SimAdapter {
|
||||||
return &SimAdapter{
|
return &SimAdapter{
|
||||||
pipe: tcpPipe,
|
pipe: pipes.TCPPipe,
|
||||||
nodes: make(map[discover.NodeID]*SimNode),
|
nodes: make(map[discover.NodeID]*SimNode),
|
||||||
services: services,
|
services: services,
|
||||||
}
|
}
|
||||||
|
|
@ -348,34 +346,6 @@ func (sn *SimNode) NodeInfo() *p2p.NodeInfo {
|
||||||
return server.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 {
|
func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int) error {
|
||||||
switch v := conn.(type) {
|
switch v := conn.(type) {
|
||||||
case *net.UnixConn:
|
case *net.UnixConn:
|
||||||
|
|
@ -390,64 +360,3 @@ func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int)
|
||||||
}
|
}
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/simulations/pipes"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSocketPipe(t *testing.T) {
|
func TestSocketPipe(t *testing.T) {
|
||||||
c1, c2, err := socketPipe()
|
c1, c2, err := pipes.SocketPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +76,7 @@ func TestSocketPipe(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSocketPipeBidirections(t *testing.T) {
|
func TestSocketPipeBidirections(t *testing.T) {
|
||||||
c1, c2, err := socketPipe()
|
c1, c2, err := pipes.SocketPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +140,7 @@ func TestSocketPipeBidirections(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTcpPipe(t *testing.T) {
|
func TestTcpPipe(t *testing.T) {
|
||||||
c1, c2, err := tcpPipe()
|
c1, c2, err := pipes.TCPPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +185,7 @@ func TestTcpPipe(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTcpPipeBidirections(t *testing.T) {
|
func TestTcpPipeBidirections(t *testing.T) {
|
||||||
c1, c2, err := tcpPipe()
|
c1, c2, err := pipes.TCPPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +248,7 @@ func TestTcpPipeBidirections(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetPipe(t *testing.T) {
|
func TestNetPipe(t *testing.T) {
|
||||||
c1, c2, err := netPipe()
|
c1, c2, err := pipes.NetPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -295,7 +297,7 @@ func TestNetPipe(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetPipeBidirections(t *testing.T) {
|
func TestNetPipeBidirections(t *testing.T) {
|
||||||
c1, c2, err := netPipe()
|
c1, c2, err := pipes.NetPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -382,6 +382,27 @@ func (net *Network) GetNodeByName(name string) *Node {
|
||||||
return net.getNodeByName(name)
|
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 {
|
func (net *Network) getNode(id discover.NodeID) *Node {
|
||||||
i, found := net.nodeMap[id]
|
i, found := net.nodeMap[id]
|
||||||
if !found {
|
if !found {
|
||||||
|
|
|
||||||
86
p2p/simulations/pipes/pipes.go
Normal file
86
p2p/simulations/pipes/pipes.go
Normal 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
|
||||||
|
}
|
||||||
|
|
@ -91,9 +91,7 @@ func (s *ProtocolSession) trigger(trig Trigger) error {
|
||||||
errc := make(chan error)
|
errc := make(chan error)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Trace(fmt.Sprintf("trigger %v (%v)....", trig.Msg, trig.Code))
|
|
||||||
errc <- mockNode.Trigger(&trig)
|
errc <- mockNode.Trigger(&trig)
|
||||||
log.Trace(fmt.Sprintf("triggered %v (%v)", trig.Msg, trig.Code))
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
t := trig.Timeout
|
t := trig.Timeout
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue