tendermint/p2p/base_reactor.go

54 lines
1.4 KiB
Go
Raw Permalink Normal View History

2018-01-13 14:25:51 -08:00
package p2p
2018-01-20 18:12:04 -08:00
import (
2018-07-01 19:36:49 -07:00
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/p2p/conn"
2018-01-20 18:12:04 -08:00
)
2018-01-13 14:25:51 -08:00
type Reactor interface {
cmn.Service // Start, Stop
2018-02-08 01:07:40 -08:00
// SetSwitch allows setting a switch.
2018-01-13 14:25:51 -08:00
SetSwitch(*Switch)
2018-02-08 01:07:40 -08:00
// GetChannels returns the list of channel descriptors.
2018-01-20 21:33:53 -08:00
GetChannels() []*conn.ChannelDescriptor
2018-02-08 01:07:40 -08:00
// AddPeer is called by the switch when a new peer is added.
2018-01-13 14:25:51 -08:00
AddPeer(peer Peer)
2018-02-08 01:07:40 -08:00
// RemovePeer is called by the switch when the peer is stopped (due to error
// or other reason).
2018-01-13 14:25:51 -08:00
RemovePeer(peer Peer, reason interface{})
2018-02-08 01:07:40 -08:00
// Receive is called when msgBytes is received from peer.
//
// NOTE reactor can not keep msgBytes around after Receive completes without
// copying.
//
// CONTRACT: msgBytes are not nil.
2018-02-08 01:07:40 -08:00
Receive(chID byte, peer Peer, msgBytes []byte)
2018-01-13 14:25:51 -08:00
}
//--------------------------------------
type BaseReactor struct {
cmn.BaseService // Provides Start, Stop, .Quit
Switch *Switch
}
func NewBaseReactor(name string, impl Reactor) *BaseReactor {
return &BaseReactor{
BaseService: *cmn.NewBaseService(nil, name, impl),
Switch: nil,
}
}
func (br *BaseReactor) SetSwitch(sw *Switch) {
br.Switch = sw
}
func (*BaseReactor) GetChannels() []*conn.ChannelDescriptor { return nil }
func (*BaseReactor) AddPeer(peer Peer) {}
func (*BaseReactor) RemovePeer(peer Peer, reason interface{}) {}
func (*BaseReactor) Receive(chID byte, peer Peer, msgBytes []byte) {}