Receive called from OnReceive

This commit is contained in:
William Banfield
2022-10-26 18:37:21 -04:00
parent cf2e1f3954
commit 6eefce83ef
2 changed files with 24 additions and 6 deletions

View File

@@ -38,9 +38,25 @@ type Reactor interface {
// or other reason).
RemovePeer(peer Peer, reason interface{})
// Receive is called by the switch when an envelope is received from any connected
// NewReceive is called by the switch when an envelope is received from any connected
// peer on any of the channels registered by the reactor
//
// The set of messages passed to Receive and NewReceive are identical. While both
// need to be implemented to satisfy the interface, only one message stream
// should be used per reactor.
NewReceive(Envelope)
// Receive is called by the switch when msgBytes is received from the peer.
//
// NOTE reactor can not keep msgBytes around after Receive completes without
// copying.
//
// CONTRACT: msgBytes are not nil.
//
// The messages passed to Receive and NewReceive are identical. While both
// need to be implemented to satisfy the interface, only one message stream
// should be used per reactor.
Receive(chID byte, peer Peer, msgBytes []byte)
}
//--------------------------------------
@@ -60,8 +76,9 @@ func NewBaseReactor(name string, impl Reactor) *BaseReactor {
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) NewReceive(e Envelope) {}
func (*BaseReactor) InitPeer(peer Peer) Peer { return peer }
func (*BaseReactor) GetChannels() []*conn.ChannelDescriptor { return nil }
func (*BaseReactor) AddPeer(peer Peer) {}
func (*BaseReactor) RemovePeer(peer Peer, reason interface{}) {}
func (*BaseReactor) NewReceive(e Envelope) {}
func (*BaseReactor) Receive(chID byte, peer Peer, msgBytes []byte) {}
func (*BaseReactor) InitPeer(peer Peer) Peer { return peer }

View File

@@ -482,6 +482,7 @@ func createMConnection(
Src: p,
Message: msg,
})
reactor.Receive(chID, p, msgBytes)
}
onError := func(r interface{}) {