mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Merge baa1cad86e into 62467e4405
This commit is contained in:
commit
6dd3b9ce4c
13 changed files with 43 additions and 48 deletions
|
|
@ -235,7 +235,7 @@ func (n NodeID) String() string {
|
|||
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 {
|
||||
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.
|
||||
// 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)}
|
||||
half := len(id) / 2
|
||||
p.X.SetBytes(id[:half])
|
||||
p.Y.SetBytes(id[half:])
|
||||
half := len(n) / 2
|
||||
p.X.SetBytes(n[:half])
|
||||
p.Y.SetBytes(n[half:])
|
||||
if !p.Curve.IsOnCurve(p.X, p.Y) {
|
||||
return nil, errors.New("id is invalid secp256k1 curve point")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,9 +209,8 @@ func (t *pingRecorder) ping(toid NodeID, toaddr *net.UDPAddr) error {
|
|||
t.pinged[toid] = true
|
||||
if t.dead[toid] {
|
||||
return errTimeout
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *pingRecorder) close() {}
|
||||
|
|
|
|||
|
|
@ -567,12 +567,11 @@ loop:
|
|||
net.ticketStore.searchLookupDone(res.target, res.nodes, func(n *Node, topic Topic) []byte {
|
||||
if n.state != nil && n.state.canQuery {
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ func (n NodeID) String() string {
|
|||
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 {
|
||||
return fmt.Sprintf("discover.HexID(\"%x\")", n[:])
|
||||
}
|
||||
|
|
@ -326,8 +326,8 @@ func (n NodeID) Pubkey() (*ecdsa.PublicKey, error) {
|
|||
return p, nil
|
||||
}
|
||||
|
||||
func (id NodeID) mustPubkey() ecdsa.PublicKey {
|
||||
pk, err := id.Pubkey()
|
||||
func (n NodeID) mustPubkey() ecdsa.PublicKey {
|
||||
pk, err := n.Pubkey()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,9 +176,8 @@ func (t *pingRecorder) ping(toid NodeID, toaddr *net.UDPAddr) error {
|
|||
t.pinged[toid] = true
|
||||
if t.responding[toid] {
|
||||
return nil
|
||||
} else {
|
||||
return errTimeout
|
||||
}
|
||||
return errTimeout
|
||||
}
|
||||
|
||||
func TestTable_closest(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -689,7 +689,7 @@ func (b *topicRadiusBucket) update(now mclock.AbsTime) {
|
|||
|
||||
for target, tm := range b.lookupSent {
|
||||
if now-tm > mclock.AbsTime(respTimeout) {
|
||||
b.weights[trNoAdjust] += 1
|
||||
b.weights[trNoAdjust]++
|
||||
delete(b.lookupSent, target)
|
||||
}
|
||||
}
|
||||
|
|
@ -698,10 +698,10 @@ func (b *topicRadiusBucket) update(now mclock.AbsTime) {
|
|||
func (b *topicRadiusBucket) adjust(now mclock.AbsTime, inside float64) {
|
||||
b.update(now)
|
||||
if inside <= 0 {
|
||||
b.weights[trOutside] += 1
|
||||
b.weights[trOutside]++
|
||||
} else {
|
||||
if inside >= 1 {
|
||||
b.weights[trInside] += 1
|
||||
b.weights[trInside]++
|
||||
} else {
|
||||
b.weights[trInside] += inside
|
||||
b.weights[trOutside] += 1 - inside
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import (
|
|||
"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.
|
||||
type Interface interface {
|
||||
// These methods manage a mapping between a port on the local
|
||||
|
|
@ -226,9 +226,8 @@ func (n *autodisc) String() string {
|
|||
defer n.mu.Unlock()
|
||||
if n.found == nil {
|
||||
return n.what
|
||||
} else {
|
||||
return n.found.String()
|
||||
}
|
||||
return n.found.String()
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return srv.peerFeed.Subscribe(ch)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ func (s *Server) StopMocker(w http.ResponseWriter, req *http.Request) {
|
|||
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) {
|
||||
|
||||
list := GetMockerList()
|
||||
|
|
|
|||
|
|
@ -386,11 +386,11 @@ func startTestNetwork(t *testing.T, client *Client) []string {
|
|||
|
||||
// connect the nodes
|
||||
for i := 0; i < nodeCount-1; i++ {
|
||||
peerId := i + 1
|
||||
peerID := i + 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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,19 +29,19 @@ import (
|
|||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||
)
|
||||
|
||||
//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){
|
||||
"startStop": startStop,
|
||||
"probabilistic": probabilistic,
|
||||
"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) {
|
||||
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
|
||||
func GetMockerList() []string {
|
||||
list := make([]string, 0, len(mockerList))
|
||||
|
|
@ -51,7 +51,7 @@ func GetMockerList() []string {
|
|||
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) {
|
||||
_, err := connectNodesInRing(net, nodeCount)
|
||||
if err != nil {
|
||||
|
|
@ -59,7 +59,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) {
|
||||
nodes, err := connectNodesInRing(net, nodeCount)
|
||||
if err != nil {
|
||||
|
|
@ -96,10 +96,10 @@ func startStop(net *Network, quit chan struct{}, nodeCount int) {
|
|||
}
|
||||
}
|
||||
|
||||
//The probabilistic mocker func has a more probabilistic pattern
|
||||
//(the implementation could probably be improved):
|
||||
//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
|
||||
// probabilistic mocker func has a more probabilistic pattern
|
||||
// (the implementation could probably be improved):
|
||||
// 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
|
||||
func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
|
||||
nodes, err := connectNodesInRing(net, nodeCount)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ func TestMocker(t *testing.T) {
|
|||
//time.Sleep( 3 *time.Second)
|
||||
}
|
||||
} else if event.Conn != nil && nodesComplete {
|
||||
connCount += 1
|
||||
connCount++
|
||||
if connCount == (nodeCount-1)*2 {
|
||||
wg.Done()
|
||||
return
|
||||
|
|
@ -135,13 +135,13 @@ func TestMocker(t *testing.T) {
|
|||
wg.Wait()
|
||||
|
||||
//check there are nodeCount number of nodes in the network
|
||||
nodes_info, err := client.GetNodes()
|
||||
nodesInfo, err := client.GetNodes()
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get nodes list: %s", err)
|
||||
}
|
||||
|
||||
if len(nodes_info) != nodeCount {
|
||||
t.Fatalf("Expected %d number of nodes, got: %d", nodeCount, len(nodes_info))
|
||||
if len(nodesInfo) != nodeCount {
|
||||
t.Fatalf("Expected %d number of nodes, got: %d", nodeCount, len(nodesInfo))
|
||||
}
|
||||
|
||||
//stop the mocker
|
||||
|
|
@ -160,12 +160,12 @@ func TestMocker(t *testing.T) {
|
|||
}
|
||||
|
||||
//now the number of nodes in the network should be zero
|
||||
nodes_info, err = client.GetNodes()
|
||||
nodesInfo, err = client.GetNodes()
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get nodes list: %s", err)
|
||||
}
|
||||
|
||||
if len(nodes_info) != 0 {
|
||||
t.Fatalf("Expected empty list of nodes, got: %d", len(nodes_info))
|
||||
if len(nodesInfo) != 0 {
|
||||
t.Fatalf("Expected empty list of nodes, got: %d", len(nodesInfo))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,7 +370,7 @@ func (net *Network) GetNode(id discover.NodeID) *Node {
|
|||
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
|
||||
func (net *Network) GetNodeByName(name string) *Node {
|
||||
net.lock.Lock()
|
||||
|
|
@ -454,7 +454,7 @@ func (net *Network) getConn(oneID, otherID discover.NodeID) *Conn {
|
|||
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
|
||||
// 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
|
||||
|
|
@ -737,7 +737,6 @@ func (net *Network) executeNodeEvent(e *Event) error {
|
|||
func (net *Network) executeConnEvent(e *Event) error {
|
||||
if e.Conn.Up {
|
||||
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