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.

69 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/libs/service"
  5. "github.com/tendermint/tendermint/p2p"
  6. "github.com/tendermint/tendermint/p2p/conn"
  7. )
  8. type Peer struct {
  9. *service.BaseService
  10. ip net.IP
  11. id p2p.ID
  12. addr *p2p.NetAddress
  13. kv map[string]interface{}
  14. Outbound, Persistent bool
  15. }
  16. // NewPeer creates and starts a new mock peer. If the ip
  17. // is nil, random routable address is used.
  18. func NewPeer(ip net.IP) *Peer {
  19. var netAddr *p2p.NetAddress
  20. if ip == nil {
  21. _, netAddr = p2p.CreateRoutableAddr()
  22. } else {
  23. netAddr = p2p.NewNetAddressIPPort(ip, 26656)
  24. }
  25. nodeKey := p2p.GenNodeKey()
  26. netAddr.ID = nodeKey.ID
  27. mp := &Peer{
  28. ip: ip,
  29. id: nodeKey.ID,
  30. addr: netAddr,
  31. kv: make(map[string]interface{}),
  32. }
  33. mp.BaseService = service.NewBaseService(nil, "MockPeer", mp)
  34. if err := mp.Start(); err != nil {
  35. panic(err)
  36. }
  37. return mp
  38. }
  39. func (mp *Peer) FlushStop() { mp.Stop() } //nolint:errcheck //ignore error
  40. func (mp *Peer) TrySend(chID byte, msgBytes []byte) bool { return true }
  41. func (mp *Peer) Send(chID byte, msgBytes []byte) bool { return true }
  42. func (mp *Peer) NodeInfo() p2p.NodeInfo {
  43. return p2p.NodeInfo{
  44. DefaultNodeID: mp.addr.ID,
  45. ListenAddr: mp.addr.DialString(),
  46. }
  47. }
  48. func (mp *Peer) Status() conn.ConnectionStatus { return conn.ConnectionStatus{} }
  49. func (mp *Peer) ID() p2p.ID { return mp.id }
  50. func (mp *Peer) IsOutbound() bool { return mp.Outbound }
  51. func (mp *Peer) IsPersistent() bool { return mp.Persistent }
  52. func (mp *Peer) Get(key string) interface{} {
  53. if value, ok := mp.kv[key]; ok {
  54. return value
  55. }
  56. return nil
  57. }
  58. func (mp *Peer) Set(key string, value interface{}) {
  59. mp.kv[key] = value
  60. }
  61. func (mp *Peer) RemoteIP() net.IP { return mp.ip }
  62. func (mp *Peer) SocketAddr() *p2p.NetAddress { return mp.addr }
  63. func (mp *Peer) RemoteAddr() net.Addr { return &net.TCPAddr{IP: mp.ip, Port: 8800} }
  64. func (mp *Peer) CloseConn() error { return nil }