mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
p2p: fixes for most golint warnings not regarding comments
This commit is contained in:
parent
415969f534
commit
baa1cad86e
13 changed files with 43 additions and 48 deletions
|
|
@ -235,7 +235,7 @@ func (n NodeID) String() string {
|
||||||
return fmt.Sprintf("%x", n[:])
|
return fmt.Sprintf("%x", n[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Go syntax representation of a NodeID is a call to HexID.
|
// GoString is the Go syntax representation of a NodeID is a call to HexID.
|
||||||
func (n NodeID) GoString() string {
|
func (n NodeID) GoString() string {
|
||||||
return fmt.Sprintf("discover.HexID(\"%x\")", n[:])
|
return fmt.Sprintf("discover.HexID(\"%x\")", n[:])
|
||||||
}
|
}
|
||||||
|
|
@ -317,11 +317,11 @@ func PubkeyID(pub *ecdsa.PublicKey) NodeID {
|
||||||
|
|
||||||
// Pubkey returns the public key represented by the node ID.
|
// Pubkey returns the public key represented by the node ID.
|
||||||
// It returns an error if the ID is not a point on the curve.
|
// It returns an error if the ID is not a point on the curve.
|
||||||
func (id NodeID) Pubkey() (*ecdsa.PublicKey, error) {
|
func (n NodeID) Pubkey() (*ecdsa.PublicKey, error) {
|
||||||
p := &ecdsa.PublicKey{Curve: crypto.S256(), X: new(big.Int), Y: new(big.Int)}
|
p := &ecdsa.PublicKey{Curve: crypto.S256(), X: new(big.Int), Y: new(big.Int)}
|
||||||
half := len(id) / 2
|
half := len(n) / 2
|
||||||
p.X.SetBytes(id[:half])
|
p.X.SetBytes(n[:half])
|
||||||
p.Y.SetBytes(id[half:])
|
p.Y.SetBytes(n[half:])
|
||||||
if !p.Curve.IsOnCurve(p.X, p.Y) {
|
if !p.Curve.IsOnCurve(p.X, p.Y) {
|
||||||
return nil, errors.New("id is invalid secp256k1 curve point")
|
return nil, errors.New("id is invalid secp256k1 curve point")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -217,9 +217,8 @@ func (t *pingRecorder) ping(toid NodeID, toaddr *net.UDPAddr) error {
|
||||||
t.pinged[toid] = true
|
t.pinged[toid] = true
|
||||||
if t.dead[toid] {
|
if t.dead[toid] {
|
||||||
return errTimeout
|
return errTimeout
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTable_closest(t *testing.T) {
|
func TestTable_closest(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -567,12 +567,11 @@ loop:
|
||||||
net.ticketStore.searchLookupDone(res.target, res.nodes, func(n *Node, topic Topic) []byte {
|
net.ticketStore.searchLookupDone(res.target, res.nodes, func(n *Node, topic Topic) []byte {
|
||||||
if n.state != nil && n.state.canQuery {
|
if n.state != nil && n.state.canQuery {
|
||||||
return net.conn.send(n, topicQueryPacket, topicQuery{Topic: topic}) // TODO: set expiration
|
return net.conn.send(n, topicQueryPacket, topicQuery{Topic: topic}) // TODO: set expiration
|
||||||
} else {
|
|
||||||
if n.state == unknown {
|
|
||||||
net.ping(n, n.addr())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
if n.state == unknown {
|
||||||
|
net.ping(n, n.addr())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
case <-statsDump.C:
|
case <-statsDump.C:
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ func (n NodeID) String() string {
|
||||||
return fmt.Sprintf("%x", n[:])
|
return fmt.Sprintf("%x", n[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Go syntax representation of a NodeID is a call to HexID.
|
// GoString is the Go syntax representation of a NodeID is a call to HexID.
|
||||||
func (n NodeID) GoString() string {
|
func (n NodeID) GoString() string {
|
||||||
return fmt.Sprintf("discover.HexID(\"%x\")", n[:])
|
return fmt.Sprintf("discover.HexID(\"%x\")", n[:])
|
||||||
}
|
}
|
||||||
|
|
@ -326,8 +326,8 @@ func (n NodeID) Pubkey() (*ecdsa.PublicKey, error) {
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id NodeID) mustPubkey() ecdsa.PublicKey {
|
func (n NodeID) mustPubkey() ecdsa.PublicKey {
|
||||||
pk, err := id.Pubkey()
|
pk, err := n.Pubkey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,9 +176,8 @@ func (t *pingRecorder) ping(toid NodeID, toaddr *net.UDPAddr) error {
|
||||||
t.pinged[toid] = true
|
t.pinged[toid] = true
|
||||||
if t.responding[toid] {
|
if t.responding[toid] {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return errTimeout
|
|
||||||
}
|
}
|
||||||
|
return errTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTable_closest(t *testing.T) {
|
func TestTable_closest(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -689,7 +689,7 @@ func (b *topicRadiusBucket) update(now mclock.AbsTime) {
|
||||||
|
|
||||||
for target, tm := range b.lookupSent {
|
for target, tm := range b.lookupSent {
|
||||||
if now-tm > mclock.AbsTime(respTimeout) {
|
if now-tm > mclock.AbsTime(respTimeout) {
|
||||||
b.weights[trNoAdjust] += 1
|
b.weights[trNoAdjust]++
|
||||||
delete(b.lookupSent, target)
|
delete(b.lookupSent, target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -698,10 +698,10 @@ func (b *topicRadiusBucket) update(now mclock.AbsTime) {
|
||||||
func (b *topicRadiusBucket) adjust(now mclock.AbsTime, inside float64) {
|
func (b *topicRadiusBucket) adjust(now mclock.AbsTime, inside float64) {
|
||||||
b.update(now)
|
b.update(now)
|
||||||
if inside <= 0 {
|
if inside <= 0 {
|
||||||
b.weights[trOutside] += 1
|
b.weights[trOutside]++
|
||||||
} else {
|
} else {
|
||||||
if inside >= 1 {
|
if inside >= 1 {
|
||||||
b.weights[trInside] += 1
|
b.weights[trInside]++
|
||||||
} else {
|
} else {
|
||||||
b.weights[trInside] += inside
|
b.weights[trInside] += inside
|
||||||
b.weights[trOutside] += 1 - inside
|
b.weights[trOutside] += 1 - inside
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"github.com/jackpal/go-nat-pmp"
|
"github.com/jackpal/go-nat-pmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// An implementation of nat.Interface can map local ports to ports
|
// Interface is an implementation of nat.Interface that can map local ports to ports
|
||||||
// accessible from the Internet.
|
// accessible from the Internet.
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
// These methods manage a mapping between a port on the local
|
// These methods manage a mapping between a port on the local
|
||||||
|
|
@ -226,9 +226,8 @@ func (n *autodisc) String() string {
|
||||||
defer n.mu.Unlock()
|
defer n.mu.Unlock()
|
||||||
if n.found == nil {
|
if n.found == nil {
|
||||||
return n.what
|
return n.what
|
||||||
} else {
|
|
||||||
return n.found.String()
|
|
||||||
}
|
}
|
||||||
|
return n.found.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait blocks until auto-discovery has been performed.
|
// wait blocks until auto-discovery has been performed.
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ func (srv *Server) RemovePeer(node *discover.Node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubscribePeers subscribes the given channel to peer events
|
// SubscribeEvents subscribes the given channel to peer events
|
||||||
func (srv *Server) SubscribeEvents(ch chan *PeerEvent) event.Subscription {
|
func (srv *Server) SubscribeEvents(ch chan *PeerEvent) event.Subscription {
|
||||||
return srv.peerFeed.Subscribe(ch)
|
return srv.peerFeed.Subscribe(ch)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,7 @@ func (s *Server) StopMocker(w http.ResponseWriter, req *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMockerList returns a list of available mockers
|
// GetMockers returns a list of available mockers
|
||||||
func (s *Server) GetMockers(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) GetMockers(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
list := GetMockerList()
|
list := GetMockerList()
|
||||||
|
|
|
||||||
|
|
@ -385,11 +385,11 @@ func startTestNetwork(t *testing.T, client *Client) []string {
|
||||||
|
|
||||||
// connect the nodes
|
// connect the nodes
|
||||||
for i := 0; i < nodeCount-1; i++ {
|
for i := 0; i < nodeCount-1; i++ {
|
||||||
peerId := i + 1
|
peerID := i + 1
|
||||||
if i == nodeCount-1 {
|
if i == nodeCount-1 {
|
||||||
peerId = 0
|
peerID = 0
|
||||||
}
|
}
|
||||||
if err := client.ConnectNode(nodeIDs[i], nodeIDs[peerId]); err != nil {
|
if err := client.ConnectNode(nodeIDs[i], nodeIDs[peerID]); err != nil {
|
||||||
t.Fatalf("error connecting nodes: %s", err)
|
t.Fatalf("error connecting nodes: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,19 +28,19 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
)
|
)
|
||||||
|
|
||||||
//a map of mocker names to its function
|
// mockerList maps mocker names to its function
|
||||||
var mockerList = map[string]func(net *Network, quit chan struct{}, nodeCount int){
|
var mockerList = map[string]func(net *Network, quit chan struct{}, nodeCount int){
|
||||||
"startStop": startStop,
|
"startStop": startStop,
|
||||||
"probabilistic": probabilistic,
|
"probabilistic": probabilistic,
|
||||||
"boot": boot,
|
"boot": boot,
|
||||||
}
|
}
|
||||||
|
|
||||||
//Lookup a mocker by its name, returns the mockerFn
|
// LookupMocker retrieves a mocker by its name, returns the mockerFn
|
||||||
func LookupMocker(mockerType string) func(net *Network, quit chan struct{}, nodeCount int) {
|
func LookupMocker(mockerType string) func(net *Network, quit chan struct{}, nodeCount int) {
|
||||||
return mockerList[mockerType]
|
return mockerList[mockerType]
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get a list of mockers (keys of the map)
|
// GetMockerList returns a list of mockers (keys of the map)
|
||||||
//Useful for frontend to build available mocker selection
|
//Useful for frontend to build available mocker selection
|
||||||
func GetMockerList() []string {
|
func GetMockerList() []string {
|
||||||
list := make([]string, 0, len(mockerList))
|
list := make([]string, 0, len(mockerList))
|
||||||
|
|
@ -50,7 +50,7 @@ func GetMockerList() []string {
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
//The boot mockerFn only connects the node in a ring and doesn't do anything else
|
// boot mockerFn only connects the node in a ring and doesn't do anything else
|
||||||
func boot(net *Network, quit chan struct{}, nodeCount int) {
|
func boot(net *Network, quit chan struct{}, nodeCount int) {
|
||||||
_, err := connectNodesInRing(net, nodeCount)
|
_, err := connectNodesInRing(net, nodeCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -58,7 +58,7 @@ func boot(net *Network, quit chan struct{}, nodeCount int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//The startStop mockerFn stops and starts nodes in a defined period (ticker)
|
// startStop mockerFn stops and starts nodes in a defined period (ticker)
|
||||||
func startStop(net *Network, quit chan struct{}, nodeCount int) {
|
func startStop(net *Network, quit chan struct{}, nodeCount int) {
|
||||||
nodes, err := connectNodesInRing(net, nodeCount)
|
nodes, err := connectNodesInRing(net, nodeCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -95,10 +95,10 @@ func startStop(net *Network, quit chan struct{}, nodeCount int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//The probabilistic mocker func has a more probabilistic pattern
|
// probabilistic mocker func has a more probabilistic pattern
|
||||||
//(the implementation could probably be improved):
|
// (the implementation could probably be improved):
|
||||||
//nodes are connected in a ring, then a varying number of random nodes is selected,
|
// nodes are connected in a ring, then a varying number of random nodes is selected,
|
||||||
//mocker then stops and starts them in random intervals, and continues the loop
|
// mocker then stops and starts them in random intervals, and continues the loop
|
||||||
func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
|
func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
|
||||||
nodes, err := connectNodesInRing(net, nodeCount)
|
nodes, err := connectNodesInRing(net, nodeCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ func TestMocker(t *testing.T) {
|
||||||
//time.Sleep( 3 *time.Second)
|
//time.Sleep( 3 *time.Second)
|
||||||
}
|
}
|
||||||
} else if event.Conn != nil && nodesComplete {
|
} else if event.Conn != nil && nodesComplete {
|
||||||
connCount += 1
|
connCount++
|
||||||
if connCount == (nodeCount-1)*2 {
|
if connCount == (nodeCount-1)*2 {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
return
|
return
|
||||||
|
|
@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -374,7 +374,7 @@ func (net *Network) GetNode(id discover.NodeID) *Node {
|
||||||
return net.getNode(id)
|
return net.getNode(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNode gets the node with the given name, returning nil if the node does
|
// GetNodeByName gets the node with the given name, returning nil if the node does
|
||||||
// not exist
|
// not exist
|
||||||
func (net *Network) GetNodeByName(name string) *Node {
|
func (net *Network) GetNodeByName(name string) *Node {
|
||||||
net.lock.Lock()
|
net.lock.Lock()
|
||||||
|
|
@ -458,7 +458,7 @@ func (net *Network) getConn(oneID, otherID discover.NodeID) *Conn {
|
||||||
return net.Conns[i]
|
return net.Conns[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitConn(one, other) retrieves the connectiton model for the connection between
|
// InitConn retrieves the connectiton 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
|
||||||
|
|
@ -738,7 +738,6 @@ func (net *Network) executeNodeEvent(e *Event) error {
|
||||||
func (net *Network) executeConnEvent(e *Event) error {
|
func (net *Network) executeConnEvent(e *Event) error {
|
||||||
if e.Conn.Up {
|
if e.Conn.Up {
|
||||||
return net.Connect(e.Conn.One, e.Conn.Other)
|
return net.Connect(e.Conn.One, e.Conn.Other)
|
||||||
} else {
|
|
||||||
return net.Disconnect(e.Conn.One, e.Conn.Other)
|
|
||||||
}
|
}
|
||||||
|
return net.Disconnect(e.Conn.One, e.Conn.Other)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue