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.

38 lines
1.0 KiB

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(*Switch)
  9. GetChannels() []*conn.ChannelDescriptor
  10. AddPeer(peer Peer)
  11. RemovePeer(peer Peer, reason interface{})
  12. Receive(chID byte, peer Peer, msgBytes []byte) // CONTRACT: msgBytes are not nil
  13. }
  14. //--------------------------------------
  15. type BaseReactor struct {
  16. cmn.BaseService // Provides Start, Stop, .Quit
  17. Switch *Switch
  18. }
  19. func NewBaseReactor(name string, impl Reactor) *BaseReactor {
  20. return &BaseReactor{
  21. BaseService: *cmn.NewBaseService(nil, name, impl),
  22. Switch: nil,
  23. }
  24. }
  25. func (br *BaseReactor) SetSwitch(sw *Switch) {
  26. br.Switch = sw
  27. }
  28. func (_ *BaseReactor) GetChannels() []*conn.ChannelDescriptor { return nil }
  29. func (_ *BaseReactor) AddPeer(peer Peer) {}
  30. func (_ *BaseReactor) RemovePeer(peer Peer, reason interface{}) {}
  31. func (_ *BaseReactor) Receive(chID byte, peer Peer, msgBytes []byte) {}