From 7f0e170f7aa953b5b84773acb337066262b01525 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 6 Feb 2019 15:51:44 -0800 Subject: [PATCH] =?UTF-8?q?Rename=20GroupReceiver=20=E2=86=92=20GroupRecei?= =?UTF-8?q?verImpl=20in=20hostv2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suggested-by: Minh Doan --- p2p/host/hostv2/hostv2.go | 10 +++++----- p2p/host/hostv2/hostv2_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/p2p/host/hostv2/hostv2.go b/p2p/host/hostv2/hostv2.go index c014ba43b..9086fba25 100644 --- a/p2p/host/hostv2/hostv2.go +++ b/p2p/host/hostv2/hostv2.go @@ -58,20 +58,20 @@ type Subscription interface { Cancel() } -// GroupReceiver is a multicast group receiver implementation. -type GroupReceiver struct { +// GroupReceiverImpl is a multicast group receiver implementation. +type GroupReceiverImpl struct { sub Subscription } // Close closes this receiver. -func (r *GroupReceiver) Close() error { +func (r *GroupReceiverImpl) Close() error { r.sub.Cancel() r.sub = nil return nil } // Receive receives a message. -func (r *GroupReceiver) Receive(ctx context.Context) ( +func (r *GroupReceiverImpl) Receive(ctx context.Context) ( msg []byte, sender peer.ID, err error, ) { m, err := r.sub.Next(ctx) @@ -91,7 +91,7 @@ func (host *HostV2) GroupReceiver(group p2p.GroupID) ( if err != nil { return nil, err } - return &GroupReceiver{sub: sub}, nil + return &GroupReceiverImpl{sub: sub}, nil } // AddPeer add p2p.Peer into Peerstore diff --git a/p2p/host/hostv2/hostv2_test.go b/p2p/host/hostv2/hostv2_test.go index 4d80e95e0..6cfc38dd5 100644 --- a/p2p/host/hostv2/hostv2_test.go +++ b/p2p/host/hostv2/hostv2_test.go @@ -54,7 +54,7 @@ func TestGroupReceiver_Close(t *testing.T) { defer mc.Finish() sub := mock.NewMockSubscription(mc) sub.EXPECT().Cancel() - receiver := GroupReceiver{sub: sub} + receiver := GroupReceiverImpl{sub: sub} if err := receiver.Close(); err != nil { t.Errorf("expected no error but got %v", err) } @@ -75,7 +75,7 @@ func TestGroupReceiver_Receive(t *testing.T) { sub.EXPECT().Next(ctx).Return(pubsubMessage("DEF", []byte{4, 5, 6}), nil), sub.EXPECT().Next(ctx).Return(nil, errors.New("FIAL")), ) - receiver := GroupReceiver{sub: sub} + receiver := GroupReceiverImpl{sub: sub} verify := func(sender peer.ID, msg []byte, shouldError bool) { gotMsg, gotSender, err := receiver.Receive(ctx) if (err != nil) != shouldError { @@ -106,8 +106,8 @@ func TestHostV2_GroupReceiver(t *testing.T) { pubsub.EXPECT().Subscribe("ABC").Return(sub, nil) host := &HostV2{pubsub: pubsub} gotReceiver, err := host.GroupReceiver("ABC") - if r, ok := gotReceiver.(*GroupReceiver); !ok { - t.Errorf("expected a hostv2 GroupReceiver; got %v", gotReceiver) + if r, ok := gotReceiver.(*GroupReceiverImpl); !ok { + t.Errorf("expected a hostv2 GroupReceiverImpl; got %v", gotReceiver) } else if r.sub != sub { t.Errorf("unexpected subscriber %v", r.sub) } @@ -123,7 +123,7 @@ func TestHostV2_GroupReceiver(t *testing.T) { host := &HostV2{pubsub: pubsub} gotReceiver, err := host.GroupReceiver("ABC") if gotReceiver != nil { - t.Errorf("expected a nil hostv2 GroupReceiver; got %v", gotReceiver) + t.Errorf("expected a nil hostv2 GroupReceiverImpl; got %v", gotReceiver) } if err == nil { t.Error("expected an error; got none")