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.

35 lines
993 B

7 years ago
  1. package p2p
  2. import cmn "github.com/tendermint/tmlibs/common"
  3. type Reactor interface {
  4. cmn.Service // Start, Stop
  5. SetSwitch(*Switch)
  6. GetChannels() []*ChannelDescriptor
  7. AddPeer(peer Peer)
  8. RemovePeer(peer Peer, reason interface{})
  9. Receive(chID byte, peer Peer, msgBytes []byte) // CONTRACT: msgBytes are not nil
  10. }
  11. //--------------------------------------
  12. type BaseReactor struct {
  13. cmn.BaseService // Provides Start, Stop, .Quit
  14. Switch *Switch
  15. }
  16. func NewBaseReactor(name string, impl Reactor) *BaseReactor {
  17. return &BaseReactor{
  18. BaseService: *cmn.NewBaseService(nil, name, impl),
  19. Switch: nil,
  20. }
  21. }
  22. func (br *BaseReactor) SetSwitch(sw *Switch) {
  23. br.Switch = sw
  24. }
  25. func (_ *BaseReactor) GetChannels() []*ChannelDescriptor { return nil }
  26. func (_ *BaseReactor) AddPeer(peer Peer) {}
  27. func (_ *BaseReactor) RemovePeer(peer Peer, reason interface{}) {}
  28. func (_ *BaseReactor) Receive(chID byte, peer Peer, msgBytes []byte) {}