p2p/simulations: fix code inspection problems

- typos
- unused function parameters
- redundant import alias
- code style issue: snake case
This commit is contained in:
Ferenc Szabo 2018-12-26 19:08:32 +01:00
parent e56b7d80f2
commit f938f30cbf
6 changed files with 15 additions and 13 deletions

View file

@ -46,7 +46,7 @@ import (
func init() { func init() {
// Register a reexec function to start a simulation node when the current binary is // Register a reexec function to start a simulation node when the current binary is
// executed as "p2p-node" (rather than whataver the main() function would normally do). // executed as "p2p-node" (rather than whatever the main() function would normally do).
reexec.Register("p2p-node", execP2PNode) reexec.Register("p2p-node", execP2PNode)
} }

View file

@ -130,7 +130,7 @@ func (s *SimAdapter) Dial(dest *enode.Node) (conn net.Conn, err error) {
return nil, err return nil, err
} }
// this is simulated 'listening' // this is simulated 'listening'
// asynchronously call the dialed destintion node's p2p server // asynchronously call the dialed destination node's p2p server
// to set up connection on the 'listening' side // to set up connection on the 'listening' side
go srv.SetupConn(pipe1, 0, nil) go srv.SetupConn(pipe1, 0, nil)
return pipe2, nil return pipe2, nil

View file

@ -25,6 +25,7 @@ import (
) )
func newTestNetwork(t *testing.T, nodeCount int) (*Network, []enode.ID) { func newTestNetwork(t *testing.T, nodeCount int) (*Network, []enode.ID) {
t.Helper()
adapter := adapters.NewSimAdapter(adapters.Services{ adapter := adapters.NewSimAdapter(adapters.Services{
"noopwoop": func(ctx *adapters.ServiceContext) (node.Service, error) { "noopwoop": func(ctx *adapters.ServiceContext) (node.Service, error) {
return NewNoopService(nil), nil return NewNoopService(nil), nil

View file

@ -35,7 +35,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/simulations/adapters" "github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
colorable "github.com/mattn/go-colorable" "github.com/mattn/go-colorable"
) )
var ( var (
@ -294,6 +294,7 @@ var testServices = adapters.Services{
} }
func testHTTPServer(t *testing.T) (*Network, *httptest.Server) { func testHTTPServer(t *testing.T) (*Network, *httptest.Server) {
t.Helper()
adapter := adapters.NewSimAdapter(testServices) adapter := adapters.NewSimAdapter(testServices)
network := NewNetwork(adapter, &NetworkConfig{ network := NewNetwork(adapter, &NetworkConfig{
DefaultService: "test", DefaultService: "test",

View file

@ -15,7 +15,7 @@
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package simulations simulates p2p networks. // Package simulations simulates p2p networks.
// A mokcer simulates starting and stopping real nodes in a network. // A mocker simulates starting and stopping real nodes in a network.
package simulations package simulations
import ( import (
@ -135,13 +135,13 @@ func TestMocker(t *testing.T) {
wg.Wait() wg.Wait()
//check there are nodeCount number of nodes in the network //check there are nodeCount number of nodes in the network
nodes_info, err := client.GetNodes() nodesInfo, err := client.GetNodes()
if err != nil { if err != nil {
t.Fatalf("Could not get nodes list: %s", err) t.Fatalf("Could not get nodes list: %s", err)
} }
if len(nodes_info) != nodeCount { if len(nodesInfo) != nodeCount {
t.Fatalf("Expected %d number of nodes, got: %d", nodeCount, len(nodes_info)) t.Fatalf("Expected %d number of nodes, got: %d", nodeCount, len(nodesInfo))
} }
//stop the mocker //stop the mocker
@ -160,12 +160,12 @@ func TestMocker(t *testing.T) {
} }
//now the number of nodes in the network should be zero //now the number of nodes in the network should be zero
nodes_info, err = client.GetNodes() nodesInfo, err = client.GetNodes()
if err != nil { if err != nil {
t.Fatalf("Could not get nodes list: %s", err) t.Fatalf("Could not get nodes list: %s", err)
} }
if len(nodes_info) != 0 { if len(nodesInfo) != 0 {
t.Fatalf("Expected empty list of nodes, got: %d", len(nodes_info)) t.Fatalf("Expected empty list of nodes, got: %d", len(nodesInfo))
} }
} }

View file

@ -518,7 +518,7 @@ func (net *Network) getConn(oneID, otherID enode.ID) *Conn {
return net.Conns[i] return net.Conns[i]
} }
// InitConn(one, other) retrieves the connectiton model for the connection between // InitConn(one, other) retrieves the connection model for the connection between
// peers one and other, or creates a new one if it does not exist // peers one and other, or creates a new one if it does not exist
// the order of nodes does not matter, i.e., Conn(i,j) == Conn(j, i) // the order of nodes does not matter, i.e., Conn(i,j) == Conn(j, i)
// it checks if the connection is already up, and if the nodes are running // it checks if the connection is already up, and if the nodes are running
@ -564,8 +564,8 @@ func (net *Network) Shutdown() {
close(net.quitc) close(net.quitc)
} }
//Reset resets all network properties: // Reset resets all network properties:
//emtpies the nodes and the connection list // empties the nodes and the connection list
func (net *Network) Reset() { func (net *Network) Reset() {
net.lock.Lock() net.lock.Lock()
defer net.lock.Unlock() defer net.lock.Unlock()