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.

85 lines
1.7 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. // ID always returns dummy.
  22. func (p *peer) ID() p2p.ID {
  23. return p2p.ID("dummy")
  24. }
  25. // IsOutbound always returns false.
  26. func (p *peer) IsOutbound() bool {
  27. return false
  28. }
  29. // IsPersistent always returns false.
  30. func (p *peer) IsPersistent() bool {
  31. return false
  32. }
  33. // NodeInfo always returns empty node info.
  34. func (p *peer) NodeInfo() p2p.NodeInfo {
  35. return p2p.NodeInfo{}
  36. }
  37. // RemoteIP always returns localhost.
  38. func (p *peer) RemoteIP() net.IP {
  39. return net.ParseIP("127.0.0.1")
  40. }
  41. // Status always returns empry connection status.
  42. func (p *peer) Status() tmconn.ConnectionStatus {
  43. return tmconn.ConnectionStatus{}
  44. }
  45. // Send does not do anything and just returns true.
  46. func (p *peer) Send(byte, []byte) bool {
  47. return true
  48. }
  49. // TrySend does not do anything and just returns true.
  50. func (p *peer) TrySend(byte, []byte) bool {
  51. return true
  52. }
  53. // Set records value under key specified in the map.
  54. func (p *peer) Set(key string, value interface{}) {
  55. p.kv[key] = value
  56. }
  57. // Get returns a value associated with the key. Nil is returned if no value
  58. // found.
  59. func (p *peer) Get(key string) interface{} {
  60. if value, ok := p.kv[key]; ok {
  61. return value
  62. }
  63. return nil
  64. }
  65. // OriginalAddr always returns nil.
  66. func (p *peer) OriginalAddr() *p2p.NetAddress {
  67. return nil
  68. }