You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
  1. package mock
  2. import (
  3. "net"
  4. "github.com/tendermint/tendermint/crypto/ed25519"
  5. "github.com/tendermint/tendermint/libs/service"
  6. "github.com/tendermint/tendermint/p2p"
  7. "github.com/tendermint/tendermint/p2p/conn"
  8. )
  9. type Peer struct {
  10. *service.BaseService
  11. ip net.IP
  12. id p2p.ID
  13. addr *p2p.NetAddress
  14. kv map[string]interface{}
  15. Outbound, Persistent bool
  16. }
  17. // NewPeer creates and starts a new mock peer. If the ip
  18. // is nil, random routable address is used.
  19. func NewPeer(ip net.IP) *Peer {
  20. var netAddr *p2p.NetAddress
  21. if ip == nil {
  22. _, netAddr = p2p.CreateRoutableAddr()
  23. } else {
  24. netAddr = p2p.NewNetAddressIPPort(ip, 26656)
  25. }
  26. nodeKey := p2p.NodeKey{PrivKey: ed25519.GenPrivKey()}
  27. netAddr.ID = nodeKey.ID()
  28. mp := &Peer{
  29. ip: ip,
  30. id: nodeKey.ID(),
  31. addr: netAddr,
  32. kv: make(map[string]interface{}),
  33. }
  34. mp.BaseService = service.NewBaseService(nil, "MockPeer", mp)
  35. mp.Start()
  36. return mp
  37. }
  38. func (mp *Peer) FlushStop() { mp.Stop() }
  39. func (mp *Peer) TrySend(chID byte, msgBytes []byte) bool { return true }
  40. func (mp *Peer) Send(chID byte, msgBytes []byte) bool { return true }
  41. func (mp *Peer) NodeInfo() p2p.NodeInfo {
  42. return p2p.DefaultNodeInfo{
  43. DefaultNodeID: mp.addr.ID,
  44. ListenAddr: mp.addr.DialString(),
  45. }
  46. }
  47. func (mp *Peer) Status() conn.ConnectionStatus { return conn.ConnectionStatus{} }
  48. func (mp *Peer) ID() p2p.ID { return mp.id }
  49. func (mp *Peer) IsOutbound() bool { return mp.Outbound }
  50. func (mp *Peer) IsPersistent() bool { return mp.Persistent }
  51. func (mp *Peer) Get(key string) interface{} {
  52. if value, ok := mp.kv[key]; ok {
  53. return value
  54. }
  55. return nil
  56. }
  57. func (mp *Peer) Set(key string, value interface{}) {
  58. mp.kv[key] = value
  59. }
  60. func (mp *Peer) RemoteIP() net.IP { return mp.ip }
  61. func (mp *Peer) SocketAddr() *p2p.NetAddress { return mp.addr }
  62. func (mp *Peer) RemoteAddr() net.Addr { return &net.TCPAddr{IP: mp.ip, Port: 8800} }
  63. func (mp *Peer) CloseConn() error { return nil }