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.

72 lines
1.5 KiB

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