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.

90 lines
1.8 KiB

7 years ago
7 years ago
7 years ago
  1. package dummy
  2. import (
  3. "net"
  4. cmn "github.com/tendermint/tendermint/libs/common"
  5. p2p "github.com/tendermint/tendermint/p2p"
  6. tmconn "github.com/tendermint/tendermint/p2p/conn"
  7. )
  8. type peer struct {
  9. cmn.BaseService
  10. kv map[string]interface{}
  11. }
  12. var _ p2p.Peer = (*peer)(nil)
  13. // NewPeer creates new dummy peer.
  14. func NewPeer() *peer {
  15. p := &peer{
  16. kv: make(map[string]interface{}),
  17. }
  18. p.BaseService = *cmn.NewBaseService(nil, "peer", p)
  19. return p
  20. }
  21. // FlushStop just calls Stop.
  22. func (p *peer) FlushStop() {
  23. p.Stop()
  24. }
  25. // ID always returns dummy.
  26. func (p *peer) ID() p2p.ID {
  27. return p2p.ID("dummy")
  28. }
  29. // IsOutbound always returns false.
  30. func (p *peer) IsOutbound() bool {
  31. return false
  32. }
  33. // IsPersistent always returns false.
  34. func (p *peer) IsPersistent() bool {
  35. return false
  36. }
  37. // NodeInfo always returns empty node info.
  38. func (p *peer) NodeInfo() p2p.NodeInfo {
  39. return p2p.DefaultNodeInfo{}
  40. }
  41. // RemoteIP always returns localhost.
  42. func (p *peer) RemoteIP() net.IP {
  43. return net.ParseIP("127.0.0.1")
  44. }
  45. // Status always returns empry connection status.
  46. func (p *peer) Status() tmconn.ConnectionStatus {
  47. return tmconn.ConnectionStatus{}
  48. }
  49. // Send does not do anything and just returns true.
  50. func (p *peer) Send(byte, []byte) bool {
  51. return true
  52. }
  53. // TrySend does not do anything and just returns true.
  54. func (p *peer) TrySend(byte, []byte) bool {
  55. return true
  56. }
  57. // Set records value under key specified in the map.
  58. func (p *peer) Set(key string, value interface{}) {
  59. p.kv[key] = value
  60. }
  61. // Get returns a value associated with the key. Nil is returned if no value
  62. // found.
  63. func (p *peer) Get(key string) interface{} {
  64. if value, ok := p.kv[key]; ok {
  65. return value
  66. }
  67. return nil
  68. }
  69. // OriginalAddr always returns nil.
  70. func (p *peer) OriginalAddr() *p2p.NetAddress {
  71. return nil
  72. }