2018-03-19 13:13:19 +03:00
|
|
|
package dummy
|
|
|
|
|
|
|
|
import (
|
2018-05-07 17:15:12 +02:00
|
|
|
"net"
|
|
|
|
|
2018-07-18 13:23:29 +04:00
|
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
2018-03-19 13:13:19 +03:00
|
|
|
p2p "github.com/tendermint/tendermint/p2p"
|
|
|
|
tmconn "github.com/tendermint/tendermint/p2p/conn"
|
|
|
|
)
|
|
|
|
|
|
|
|
type peer struct {
|
|
|
|
cmn.BaseService
|
|
|
|
kv map[string]interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ p2p.Peer = (*peer)(nil)
|
|
|
|
|
|
|
|
// NewPeer creates new dummy peer.
|
|
|
|
func NewPeer() *peer {
|
|
|
|
p := &peer{
|
|
|
|
kv: make(map[string]interface{}),
|
|
|
|
}
|
|
|
|
p.BaseService = *cmn.NewBaseService(nil, "peer", p)
|
2018-05-07 17:15:12 +02:00
|
|
|
|
2018-03-19 13:13:19 +03:00
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2018-11-16 17:44:19 -05:00
|
|
|
// FlushStop just calls Stop.
|
|
|
|
func (p *peer) FlushStop() {
|
|
|
|
p.Stop()
|
|
|
|
}
|
|
|
|
|
2018-03-19 13:13:19 +03:00
|
|
|
// ID always returns dummy.
|
|
|
|
func (p *peer) ID() p2p.ID {
|
|
|
|
return p2p.ID("dummy")
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsOutbound always returns false.
|
|
|
|
func (p *peer) IsOutbound() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsPersistent always returns false.
|
|
|
|
func (p *peer) IsPersistent() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeInfo always returns empty node info.
|
|
|
|
func (p *peer) NodeInfo() p2p.NodeInfo {
|
2018-10-12 19:25:33 -04:00
|
|
|
return p2p.DefaultNodeInfo{}
|
2018-03-19 13:13:19 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 17:15:12 +02:00
|
|
|
// RemoteIP always returns localhost.
|
|
|
|
func (p *peer) RemoteIP() net.IP {
|
|
|
|
return net.ParseIP("127.0.0.1")
|
|
|
|
}
|
|
|
|
|
p2p: file descriptor leaks (#3150)
* close peer's connection to avoid fd leak
Fixes #2967
* rename peer#Addr to RemoteAddr
* fix test
* fixes after Ethan's review
* bring back the check
* changelog entry
* write a test for switch#acceptRoutine
* increase timeouts? :(
* remove extra assertNPeersWithTimeout
* simplify test
* assert number of peers (just to be safe)
* Cleanup in OnStop
* run tests with verbose flag on CircleCI
* spawn a reading routine to prevent connection from closing
* get port from the listener
random port is faster, but often results in
```
panic: listen tcp 127.0.0.1:44068: bind: address already in use [recovered]
panic: listen tcp 127.0.0.1:44068: bind: address already in use
goroutine 79 [running]:
testing.tRunner.func1(0xc0001bd600)
/usr/local/go/src/testing/testing.go:792 +0x387
panic(0x974d20, 0xc0001b0500)
/usr/local/go/src/runtime/panic.go:513 +0x1b9
github.com/tendermint/tendermint/p2p.MakeSwitch(0xc0000f42a0, 0x0, 0x9fb9cc, 0x9, 0x9fc346, 0xb, 0xb42128, 0x0, 0x0, 0x0, ...)
/home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:182 +0xa28
github.com/tendermint/tendermint/p2p.MakeConnectedSwitches(0xc0000f42a0, 0x2, 0xb42128, 0xb41eb8, 0x4f1205, 0xc0001bed80, 0x4f16ed)
/home/vagrant/go/src/github.com/tendermint/tendermint/p2p/test_util.go:75 +0xf9
github.com/tendermint/tendermint/p2p.MakeSwitchPair(0xbb8d20, 0xc0001bd600, 0xb42128, 0x2f7, 0x4f16c0)
/home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:94 +0x4c
github.com/tendermint/tendermint/p2p.TestSwitches(0xc0001bd600)
/home/vagrant/go/src/github.com/tendermint/tendermint/p2p/switch_test.go:117 +0x58
testing.tRunner(0xc0001bd600, 0xb42038)
/usr/local/go/src/testing/testing.go:827 +0xbf
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:878 +0x353
exit status 2
FAIL github.com/tendermint/tendermint/p2p 0.350s
```
2019-01-22 22:23:18 +04:00
|
|
|
// Addr always returns tcp://localhost:8800.
|
|
|
|
func (p *peer) RemoteAddr() net.Addr {
|
|
|
|
return &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8800}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CloseConn always returns nil.
|
|
|
|
func (p *peer) CloseConn() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-19 13:13:19 +03:00
|
|
|
// Status always returns empry connection status.
|
|
|
|
func (p *peer) Status() tmconn.ConnectionStatus {
|
|
|
|
return tmconn.ConnectionStatus{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send does not do anything and just returns true.
|
2018-04-07 16:25:10 +03:00
|
|
|
func (p *peer) Send(byte, []byte) bool {
|
2018-03-19 13:13:19 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// TrySend does not do anything and just returns true.
|
2018-04-07 16:25:10 +03:00
|
|
|
func (p *peer) TrySend(byte, []byte) bool {
|
2018-03-19 13:13:19 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set records value under key specified in the map.
|
|
|
|
func (p *peer) Set(key string, value interface{}) {
|
|
|
|
p.kv[key] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns a value associated with the key. Nil is returned if no value
|
|
|
|
// found.
|
|
|
|
func (p *peer) Get(key string) interface{} {
|
|
|
|
if value, ok := p.kv[key]; ok {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-10-18 18:26:32 -04:00
|
|
|
|
|
|
|
// OriginalAddr always returns nil.
|
|
|
|
func (p *peer) OriginalAddr() *p2p.NetAddress {
|
|
|
|
return nil
|
|
|
|
}
|