aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/testing
diff options
context:
space:
mode:
Diffstat (limited to 'p2p/testing')
-rw-r--r--p2p/testing/peerpool.go34
-rw-r--r--p2p/testing/protocolsession.go26
-rw-r--r--p2p/testing/protocoltester.go12
3 files changed, 36 insertions, 36 deletions
diff --git a/p2p/testing/peerpool.go b/p2p/testing/peerpool.go
index 45c6e6142..ed00396e2 100644
--- a/p2p/testing/peerpool.go
+++ b/p2p/testing/peerpool.go
@@ -39,29 +39,29 @@ func NewTestPeerPool() *TestPeerPool {
return &TestPeerPool{peers: make(map[discover.NodeID]TestPeer)}
}
-func (self *TestPeerPool) Add(p TestPeer) {
- self.lock.Lock()
- defer self.lock.Unlock()
- log.Trace(fmt.Sprintf("pp add peer %v", p.ID()))
- self.peers[p.ID()] = p
+func (p *TestPeerPool) Add(peer TestPeer) {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+ log.Trace(fmt.Sprintf("pp add peer %v", peer.ID()))
+ p.peers[peer.ID()] = peer
}
-func (self *TestPeerPool) Remove(p TestPeer) {
- self.lock.Lock()
- defer self.lock.Unlock()
- delete(self.peers, p.ID())
+func (p *TestPeerPool) Remove(peer TestPeer) {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+ delete(p.peers, peer.ID())
}
-func (self *TestPeerPool) Has(id discover.NodeID) bool {
- self.lock.Lock()
- defer self.lock.Unlock()
- _, ok := self.peers[id]
+func (p *TestPeerPool) Has(id discover.NodeID) bool {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+ _, ok := p.peers[id]
return ok
}
-func (self *TestPeerPool) Get(id discover.NodeID) TestPeer {
- self.lock.Lock()
- defer self.lock.Unlock()
- return self.peers[id]
+func (p *TestPeerPool) Get(id discover.NodeID) TestPeer {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+ return p.peers[id]
}
diff --git a/p2p/testing/protocolsession.go b/p2p/testing/protocolsession.go
index 361285f06..8f73bfa03 100644
--- a/p2p/testing/protocolsession.go
+++ b/p2p/testing/protocolsession.go
@@ -78,10 +78,10 @@ type Disconnect struct {
}
// trigger sends messages from peers
-func (self *ProtocolSession) trigger(trig Trigger) error {
- simNode, ok := self.adapter.GetNode(trig.Peer)
+func (s *ProtocolSession) trigger(trig Trigger) error {
+ simNode, ok := s.adapter.GetNode(trig.Peer)
if !ok {
- return fmt.Errorf("trigger: peer %v does not exist (1- %v)", trig.Peer, len(self.IDs))
+ return fmt.Errorf("trigger: peer %v does not exist (1- %v)", trig.Peer, len(s.IDs))
}
mockNode, ok := simNode.Services()[0].(*mockNode)
if !ok {
@@ -107,7 +107,7 @@ func (self *ProtocolSession) trigger(trig Trigger) error {
}
// expect checks an expectation of a message sent out by the pivot node
-func (self *ProtocolSession) expect(exps []Expect) error {
+func (s *ProtocolSession) expect(exps []Expect) error {
// construct a map of expectations for each node
peerExpects := make(map[discover.NodeID][]Expect)
for _, exp := range exps {
@@ -120,9 +120,9 @@ func (self *ProtocolSession) expect(exps []Expect) error {
// construct a map of mockNodes for each node
mockNodes := make(map[discover.NodeID]*mockNode)
for nodeID := range peerExpects {
- simNode, ok := self.adapter.GetNode(nodeID)
+ simNode, ok := s.adapter.GetNode(nodeID)
if !ok {
- return fmt.Errorf("trigger: peer %v does not exist (1- %v)", nodeID, len(self.IDs))
+ return fmt.Errorf("trigger: peer %v does not exist (1- %v)", nodeID, len(s.IDs))
}
mockNode, ok := simNode.Services()[0].(*mockNode)
if !ok {
@@ -202,9 +202,9 @@ func (self *ProtocolSession) expect(exps []Expect) error {
}
// TestExchanges tests a series of exchanges against the session
-func (self *ProtocolSession) TestExchanges(exchanges ...Exchange) error {
+func (s *ProtocolSession) TestExchanges(exchanges ...Exchange) error {
for i, e := range exchanges {
- if err := self.testExchange(e); err != nil {
+ if err := s.testExchange(e); err != nil {
return fmt.Errorf("exchange #%d %q: %v", i, e.Label, err)
}
log.Trace(fmt.Sprintf("exchange #%d %q: run successfully", i, e.Label))
@@ -214,14 +214,14 @@ func (self *ProtocolSession) TestExchanges(exchanges ...Exchange) error {
// testExchange tests a single Exchange.
// Default timeout value is 2 seconds.
-func (self *ProtocolSession) testExchange(e Exchange) error {
+func (s *ProtocolSession) testExchange(e Exchange) error {
errc := make(chan error)
done := make(chan struct{})
defer close(done)
go func() {
for _, trig := range e.Triggers {
- err := self.trigger(trig)
+ err := s.trigger(trig)
if err != nil {
errc <- err
return
@@ -229,7 +229,7 @@ func (self *ProtocolSession) testExchange(e Exchange) error {
}
select {
- case errc <- self.expect(e.Expects):
+ case errc <- s.expect(e.Expects):
case <-done:
}
}()
@@ -250,7 +250,7 @@ func (self *ProtocolSession) testExchange(e Exchange) error {
// TestDisconnected tests the disconnections given as arguments
// the disconnect structs describe what disconnect error is expected on which peer
-func (self *ProtocolSession) TestDisconnected(disconnects ...*Disconnect) error {
+func (s *ProtocolSession) TestDisconnected(disconnects ...*Disconnect) error {
expects := make(map[discover.NodeID]error)
for _, disconnect := range disconnects {
expects[disconnect.Peer] = disconnect.Error
@@ -259,7 +259,7 @@ func (self *ProtocolSession) TestDisconnected(disconnects ...*Disconnect) error
timeout := time.After(time.Second)
for len(expects) > 0 {
select {
- case event := <-self.events:
+ case event := <-s.events:
if event.Type != p2p.PeerEventTypeDrop {
continue
}
diff --git a/p2p/testing/protocoltester.go b/p2p/testing/protocoltester.go
index a797412d6..636613c57 100644
--- a/p2p/testing/protocoltester.go
+++ b/p2p/testing/protocoltester.go
@@ -101,24 +101,24 @@ func NewProtocolTester(t *testing.T, id discover.NodeID, n int, run func(*p2p.Pe
}
// Stop stops the p2p server
-func (self *ProtocolTester) Stop() error {
- self.Server.Stop()
+func (t *ProtocolTester) Stop() error {
+ t.Server.Stop()
return nil
}
// Connect brings up the remote peer node and connects it using the
// p2p/simulations network connection with the in memory network adapter
-func (self *ProtocolTester) Connect(selfID discover.NodeID, peers ...*adapters.NodeConfig) {
+func (t *ProtocolTester) Connect(selfID discover.NodeID, peers ...*adapters.NodeConfig) {
for _, peer := range peers {
log.Trace(fmt.Sprintf("start node %v", peer.ID))
- if _, err := self.network.NewNodeWithConfig(peer); err != nil {
+ if _, err := t.network.NewNodeWithConfig(peer); err != nil {
panic(fmt.Sprintf("error starting peer %v: %v", peer.ID, err))
}
- if err := self.network.Start(peer.ID); err != nil {
+ if err := t.network.Start(peer.ID); err != nil {
panic(fmt.Sprintf("error starting peer %v: %v", peer.ID, err))
}
log.Trace(fmt.Sprintf("connect to %v", peer.ID))
- if err := self.network.Connect(selfID, peer.ID); err != nil {
+ if err := t.network.Connect(selfID, peer.ID); err != nil {
panic(fmt.Sprintf("error connecting to peer %v: %v", peer.ID, err))
}
}