mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
resolve pr comments regarding logging, formatting and comments
This commit is contained in:
parent
608ac82f53
commit
23b5b4663a
2 changed files with 10 additions and 4 deletions
|
|
@ -235,7 +235,7 @@ func (d *Delivery) RequestFromPeers(ctx context.Context, req *network.Request) (
|
||||||
d.kad.EachConn(req.Addr[:], 255, func(p *network.Peer, po int, nn bool) bool {
|
d.kad.EachConn(req.Addr[:], 255, func(p *network.Peer, po int, nn bool) bool {
|
||||||
id := p.ID()
|
id := p.ID()
|
||||||
if p.LightNode {
|
if p.LightNode {
|
||||||
log.Trace("Delivery.RequestFromPeers: skip lightnode peer", "peer id", id)
|
// skip light nodes
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if req.SkipPeer(id.String()) {
|
if req.SkipPeer(id.String()) {
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
||||||
"github.com/ethereum/go-ethereum/p2p/protocols"
|
|
||||||
|
|
||||||
"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/enode"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/protocols"
|
||||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
p2ptest "github.com/ethereum/go-ethereum/p2p/testing"
|
p2ptest "github.com/ethereum/go-ethereum/p2p/testing"
|
||||||
"github.com/ethereum/go-ethereum/swarm/log"
|
"github.com/ethereum/go-ethereum/swarm/log"
|
||||||
|
|
@ -228,6 +227,7 @@ func TestStreamerUpstreamRetrieveRequestMsgExchange(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there is one peer in the Kademlia, RequestFromPeers should return it
|
||||||
func TestRequestFromPeers(t *testing.T) {
|
func TestRequestFromPeers(t *testing.T) {
|
||||||
dummyPeerID := enode.HexID("3431c3939e1ee2a6345e976a8234f9870152d64879f30bc272a074f6859e75e8")
|
dummyPeerID := enode.HexID("3431c3939e1ee2a6345e976a8234f9870152d64879f30bc272a074f6859e75e8")
|
||||||
|
|
||||||
|
|
@ -243,6 +243,7 @@ func TestRequestFromPeers(t *testing.T) {
|
||||||
to.On(peer)
|
to.On(peer)
|
||||||
r := NewRegistry(addr.ID(), delivery, nil, nil, nil)
|
r := NewRegistry(addr.ID(), delivery, nil, nil, nil)
|
||||||
|
|
||||||
|
// an empty priorityQueue has to be created to prevent a goroutine being called after the test has finished
|
||||||
sp := &Peer{
|
sp := &Peer{
|
||||||
Peer: protocolsPeer,
|
Peer: protocolsPeer,
|
||||||
pq: pq.New(int(PriorityQueue), PriorityQueueCap),
|
pq: pq.New(int(PriorityQueue), PriorityQueueCap),
|
||||||
|
|
@ -265,13 +266,16 @@ func TestRequestFromPeers(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequestFromPeers should not return light nodes
|
||||||
func TestRequestFromPeersWithLightNode(t *testing.T) {
|
func TestRequestFromPeersWithLightNode(t *testing.T) {
|
||||||
dummyPeerID := enode.HexID("3431c3939e1ee2a6345e976a8234f9870152d64879f30bc272a074f6859e75e8")
|
dummyPeerID := enode.HexID("3431c3939e1ee2a6345e976a8234f9870152d64879f30bc272a074f6859e75e8")
|
||||||
|
|
||||||
addr := network.RandomAddr()
|
addr := network.RandomAddr()
|
||||||
to := network.NewKademlia(addr.OAddr, network.NewKadParams())
|
to := network.NewKademlia(addr.OAddr, network.NewKadParams())
|
||||||
delivery := NewDelivery(to, nil)
|
delivery := NewDelivery(to, nil)
|
||||||
|
|
||||||
protocolsPeer := protocols.NewPeer(p2p.NewPeer(dummyPeerID, "dummy", nil), nil, nil)
|
protocolsPeer := protocols.NewPeer(p2p.NewPeer(dummyPeerID, "dummy", nil), nil, nil)
|
||||||
|
// setting up a lightnode
|
||||||
peer := network.NewPeer(&network.BzzPeer{
|
peer := network.NewPeer(&network.BzzPeer{
|
||||||
BzzAddr: network.RandomAddr(),
|
BzzAddr: network.RandomAddr(),
|
||||||
LightNode: true,
|
LightNode: true,
|
||||||
|
|
@ -279,6 +283,7 @@ func TestRequestFromPeersWithLightNode(t *testing.T) {
|
||||||
}, to)
|
}, to)
|
||||||
to.On(peer)
|
to.On(peer)
|
||||||
r := NewRegistry(addr.ID(), delivery, nil, nil, nil)
|
r := NewRegistry(addr.ID(), delivery, nil, nil, nil)
|
||||||
|
// an empty priorityQueue has to be created to prevent a goroutine being called after the test has finished
|
||||||
sp := &Peer{
|
sp := &Peer{
|
||||||
Peer: protocolsPeer,
|
Peer: protocolsPeer,
|
||||||
pq: pq.New(int(PriorityQueue), PriorityQueueCap),
|
pq: pq.New(int(PriorityQueue), PriorityQueueCap),
|
||||||
|
|
@ -293,6 +298,7 @@ func TestRequestFromPeersWithLightNode(t *testing.T) {
|
||||||
)
|
)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
// making a request which should return with "no peer found"
|
||||||
_, _, err := delivery.RequestFromPeers(ctx, req)
|
_, _, err := delivery.RequestFromPeers(ctx, req)
|
||||||
|
|
||||||
expectedError := "no peer found"
|
expectedError := "no peer found"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue