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.

53 lines
1.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package p2p
  2. import (
  3. cmn "github.com/tendermint/tendermint/libs/common"
  4. "github.com/tendermint/tendermint/p2p/conn"
  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. // NOTE reactor can not keep msgBytes around after Receive completes without
  20. // copying.
  21. //
  22. // CONTRACT: msgBytes are not nil.
  23. Receive(chID byte, peer Peer, msgBytes []byte)
  24. }
  25. //--------------------------------------
  26. type BaseReactor struct {
  27. cmn.BaseService // Provides Start, Stop, .Quit
  28. Switch *Switch
  29. }
  30. func NewBaseReactor(name string, impl Reactor) *BaseReactor {
  31. return &BaseReactor{
  32. BaseService: *cmn.NewBaseService(nil, name, impl),
  33. Switch: nil,
  34. }
  35. }
  36. func (br *BaseReactor) SetSwitch(sw *Switch) {
  37. br.Switch = sw
  38. }
  39. func (*BaseReactor) GetChannels() []*conn.ChannelDescriptor { return nil }
  40. func (*BaseReactor) AddPeer(peer Peer) {}
  41. func (*BaseReactor) RemovePeer(peer Peer, reason interface{}) {}
  42. func (*BaseReactor) Receive(chID byte, peer Peer, msgBytes []byte) {}