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.

50 lines
1.3 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package p2p
  2. import (
  3. "github.com/tendermint/tendermint/p2p/conn"
  4. cmn "github.com/tendermint/tmlibs/common"
  5. )
  6. type Reactor interface {
  7. cmn.Service // Start, Stop
  8. // SetSwitch allows setting a switch.
  9. SetSwitch(*Switch)
  10. // GetChannels returns the list of channel descriptors.
  11. GetChannels() []*conn.ChannelDescriptor
  12. // AddPeer is called by the switch when a new peer is added.
  13. AddPeer(peer Peer)
  14. // RemovePeer is called by the switch when the peer is stopped (due to error
  15. // or other reason).
  16. RemovePeer(peer Peer, reason interface{})
  17. // Receive is called when msgBytes is received from peer.
  18. //
  19. // CONTRACT: msgBytes are not nil
  20. Receive(chID byte, peer Peer, msgBytes []byte)
  21. }
  22. //--------------------------------------
  23. type BaseReactor struct {
  24. cmn.BaseService // Provides Start, Stop, .Quit
  25. Switch *Switch
  26. }
  27. func NewBaseReactor(name string, impl Reactor) *BaseReactor {
  28. return &BaseReactor{
  29. BaseService: *cmn.NewBaseService(nil, name, impl),
  30. Switch: nil,
  31. }
  32. }
  33. func (br *BaseReactor) SetSwitch(sw *Switch) {
  34. br.Switch = sw
  35. }
  36. func (_ *BaseReactor) GetChannels() []*conn.ChannelDescriptor { return nil }
  37. func (_ *BaseReactor) AddPeer(peer Peer) {}
  38. func (_ *BaseReactor) RemovePeer(peer Peer, reason interface{}) {}
  39. func (_ *BaseReactor) Receive(chID byte, peer Peer, msgBytes []byte) {}