p2p: remove message type from channel implementation (#8452)

This commit is contained in:
Sam Kleinman
2022-05-02 10:52:57 -04:00
committed by GitHub
parent 6c40ad39b2
commit 37287ead94
5 changed files with 8 additions and 21 deletions

View File

@@ -59,25 +59,17 @@ type Channel struct {
outCh chan<- Envelope // outbound messages (reactors to peers)
errCh chan<- PeerError // peer error reporting
messageType proto.Message // the channel's message type, used for unmarshaling
name string
name string
}
// NewChannel creates a new channel. It is primarily for internal and test
// use, reactors should use Router.OpenChannel().
func NewChannel(
id ChannelID,
messageType proto.Message,
inCh <-chan Envelope,
outCh chan<- Envelope,
errCh chan<- PeerError,
) *Channel {
func NewChannel(id ChannelID, inCh <-chan Envelope, outCh chan<- Envelope, errCh chan<- PeerError) *Channel {
return &Channel{
ID: id,
messageType: messageType,
inCh: inCh,
outCh: outCh,
errCh: errCh,
ID: id,
inCh: inCh,
outCh: outCh,
errCh: errCh,
}
}

View File

@@ -289,7 +289,6 @@ func setupSingle(ctx context.Context, t *testing.T) *singleTestReactor {
pexErrCh := make(chan p2p.PeerError, chBuf)
pexCh := p2p.NewChannel(
p2p.ChannelID(pex.PexChannel),
new(p2pproto.PexMessage),
pexInCh,
pexOutCh,
pexErrCh,

View File

@@ -262,7 +262,7 @@ func (r *Router) OpenChannel(ctx context.Context, chDesc *ChannelDescriptor) (*C
queue := r.queueFactory(chDesc.RecvBufferCapacity)
outCh := make(chan Envelope, chDesc.RecvBufferCapacity)
errCh := make(chan PeerError, chDesc.RecvBufferCapacity)
channel := NewChannel(id, messageType, queue.dequeue(), outCh, errCh)
channel := NewChannel(id, queue.dequeue(), outCh, errCh)
channel.name = chDesc.Name
var wrapper Wrapper

View File

@@ -30,7 +30,7 @@ func testChannel(size int) (*channelInternal, *p2p.Channel) {
Out: make(chan p2p.Envelope, size),
Error: make(chan p2p.PeerError, size),
}
return in, p2p.NewChannel(0, nil, in.In, in.Out, in.Error)
return in, p2p.NewChannel(0, in.In, in.Out, in.Error)
}
func TestDispatcherBasic(t *testing.T) {

View File

@@ -102,7 +102,6 @@ func setup(
rts.snapshotChannel = p2p.NewChannel(
SnapshotChannel,
new(ssproto.Message),
rts.snapshotInCh,
rts.snapshotOutCh,
rts.snapshotPeerErrCh,
@@ -110,7 +109,6 @@ func setup(
rts.chunkChannel = p2p.NewChannel(
ChunkChannel,
new(ssproto.Message),
rts.chunkInCh,
rts.chunkOutCh,
rts.chunkPeerErrCh,
@@ -118,7 +116,6 @@ func setup(
rts.blockChannel = p2p.NewChannel(
LightBlockChannel,
new(ssproto.Message),
rts.blockInCh,
rts.blockOutCh,
rts.blockPeerErrCh,
@@ -126,7 +123,6 @@ func setup(
rts.paramsChannel = p2p.NewChannel(
ParamsChannel,
new(ssproto.Message),
rts.paramsInCh,
rts.paramsOutCh,
rts.paramsPeerErrCh,