Skip to content

Commit 3476c19

Browse files
committed
move rpc methods near the type
1 parent 70837d4 commit 3476c19

File tree

3 files changed

+51
-51
lines changed

3 files changed

+51
-51
lines changed

comm.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -205,49 +205,3 @@ func (p *PubSub) handleSendingMessages(ctx context.Context, s network.Stream, ou
205205
}
206206
}
207207
}
208-
209-
func rpcWithSubs(subs ...*pb.RPC_SubOpts) *RPC {
210-
return &RPC{
211-
RPC: pb.RPC{
212-
Subscriptions: subs,
213-
},
214-
}
215-
}
216-
217-
func rpcWithMessages(msgs ...*pb.Message) *RPC {
218-
return &RPC{RPC: pb.RPC{Publish: msgs}}
219-
}
220-
221-
func rpcWithMessageAndMsgID(msg *pb.Message, msgID string) *RPC {
222-
return &RPC{RPC: pb.RPC{Publish: []*pb.Message{msg}}, MsgIDs: []string{msgID}}
223-
}
224-
225-
func rpcWithControl(msgs []*pb.Message,
226-
ihave []*pb.ControlIHave,
227-
iwant []*pb.ControlIWant,
228-
graft []*pb.ControlGraft,
229-
prune []*pb.ControlPrune,
230-
idontwant []*pb.ControlIDontWant) *RPC {
231-
return &RPC{
232-
RPC: pb.RPC{
233-
Publish: msgs,
234-
Control: &pb.ControlMessage{
235-
Ihave: ihave,
236-
Iwant: iwant,
237-
Graft: graft,
238-
Prune: prune,
239-
Idontwant: idontwant,
240-
},
241-
},
242-
}
243-
}
244-
245-
func copyRPC(rpc *RPC) *RPC {
246-
res := new(RPC)
247-
*res = *rpc
248-
if rpc.Control != nil {
249-
res.Control = new(pb.ControlMessage)
250-
*res.Control = *rpc.Control
251-
}
252-
return res
253-
}

pubsub.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,52 @@ func (rpc *RPC) split(limit int) iter.Seq[RPC] {
461461
}
462462
}
463463

464+
func rpcWithSubs(subs ...*pb.RPC_SubOpts) *RPC {
465+
return &RPC{
466+
RPC: pb.RPC{
467+
Subscriptions: subs,
468+
},
469+
}
470+
}
471+
472+
func rpcWithMessages(msgs ...*pb.Message) *RPC {
473+
return &RPC{RPC: pb.RPC{Publish: msgs}}
474+
}
475+
476+
func rpcWithMessageAndMsgID(msg *pb.Message, msgID string) *RPC {
477+
return &RPC{RPC: pb.RPC{Publish: []*pb.Message{msg}}, MessageIDs: []string{msgID}}
478+
}
479+
480+
func rpcWithControl(msgs []*pb.Message,
481+
ihave []*pb.ControlIHave,
482+
iwant []*pb.ControlIWant,
483+
graft []*pb.ControlGraft,
484+
prune []*pb.ControlPrune,
485+
idontwant []*pb.ControlIDontWant) *RPC {
486+
return &RPC{
487+
RPC: pb.RPC{
488+
Publish: msgs,
489+
Control: &pb.ControlMessage{
490+
Ihave: ihave,
491+
Iwant: iwant,
492+
Graft: graft,
493+
Prune: prune,
494+
Idontwant: idontwant,
495+
},
496+
},
497+
}
498+
}
499+
500+
func copyRPC(rpc *RPC) *RPC {
501+
res := new(RPC)
502+
*res = *rpc
503+
if rpc.Control != nil {
504+
res.Control = new(pb.ControlMessage)
505+
*res.Control = *rpc.Control
506+
}
507+
return res
508+
}
509+
464510
// pbFieldNumberLT15Size is the number of bytes required to encode a protobuf
465511
// field number less than or equal to 15 along with its wire type. This is 1
466512
// byte because the protobuf encoding of field numbers is a varint encoding of:

rpc_queue_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func TestRPCQueueCancellations(t *testing.T) {
298298
}
299299
})
300300

301-
t.Run("cancel duplicate", func(t *testing.T) {
301+
t.Run("only one rpc cancelled", func(t *testing.T) {
302302
msgs, msgIDs := getMesssages(10)
303303
rpc := &RPC{
304304
RPC: pb.RPC{Publish: slices.Clone(msgs)},
@@ -326,11 +326,11 @@ func TestRPCQueueCancellations(t *testing.T) {
326326
if err != nil {
327327
t.Fatalf("failed to pop RPC: %v", err)
328328
}
329-
if !slices.Equal(msgs[3:], popped.Publish) {
330-
t.Fatalf("expected popped.Publish to be %v, got %v", msgs[3:], popped.Publish)
329+
if !slices.Equal(msgs, popped.Publish) {
330+
t.Fatalf("expected popped.Publish to be %v, got %v", msgs, popped.Publish)
331331
}
332-
if !slices.Equal(msgIDs[3:], popped.MessageIDs) {
333-
t.Fatalf("expected popped.MsgIDs to be %v, got %v", msgIDs[3:], popped.MessageIDs)
332+
if !slices.Equal(msgIDs, popped.MessageIDs) {
333+
t.Fatalf("expected popped.MsgIDs to be %v, got %v", msgIDs, popped.MessageIDs)
334334
}
335335
if len(q.queuedMessageIDs) != 0 {
336336
t.Fatalf("expected q.queuedMsgIDs to be empty, got %v", q.queuedMessageIDs)

0 commit comments

Comments
 (0)