mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
subpackages: * adapters: * msgpipes for simulated test connections * rlpx the RLPx adapter for normal non-test use * inproc simulated in-process network adapter * docker placeholder for docker cluster remote adapter * protocols: easy-to-setup modular protocols * simulations: * generic network model * journal, events, snapshots * cytoscape visualisation plugin * resourceful controller suite + REST API server * example: connectivity UX backend * testing: test resource drivers * exchange: trigger/expect style driver for single node and its peers * sessions: for unit testing protocols and protocol modules * (network: for network testing, benchmarking, stats, correctness, fault tolerance) * test peerpool see more in the README-s in each subpackage * p2p/server : conn/disconn hooks * reporter remote client skeleton
48 lines
990 B
Go
48 lines
990 B
Go
package testing
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/adapters"
|
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
|
)
|
|
|
|
type TestPeer interface {
|
|
ID() discover.NodeID
|
|
Drop()
|
|
}
|
|
|
|
// TestPeerPool is an example peerPool to demonstrate registration of peer connections
|
|
type TestPeerPool struct {
|
|
lock sync.Mutex
|
|
peers map[discover.NodeID]TestPeer
|
|
}
|
|
|
|
func NewTestPeerPool() *TestPeerPool {
|
|
return &TestPeerPool{peers: make(map[discover.NodeID]TestPeer)}
|
|
}
|
|
|
|
func (self *TestPeerPool) Add(p TestPeer) {
|
|
self.lock.Lock()
|
|
defer self.lock.Unlock()
|
|
self.peers[p.ID()] = p
|
|
}
|
|
|
|
func (self *TestPeerPool) Remove(p TestPeer) {
|
|
self.lock.Lock()
|
|
defer self.lock.Unlock()
|
|
delete(self.peers, p.ID())
|
|
}
|
|
|
|
func (self *TestPeerPool) Has(n *adapters.NodeId) bool {
|
|
self.lock.Lock()
|
|
defer self.lock.Unlock()
|
|
_, ok := self.peers[n.NodeID]
|
|
return ok
|
|
}
|
|
|
|
func (self *TestPeerPool) Get(n *adapters.NodeId) TestPeer {
|
|
self.lock.Lock()
|
|
defer self.lock.Unlock()
|
|
return self.peers[n.NodeID]
|
|
}
|