diff --git a/pubsub.go b/pubsub.go index a6394fc..2e33315 100644 --- a/pubsub.go +++ b/pubsub.go @@ -597,10 +597,7 @@ func (p *PubSub) GetTopics() []string { // Publish publishes data under the given topic func (p *PubSub) Publish(topic string, data []byte) error { - seqno := make([]byte, 8) - counter := atomic.AddUint64(&p.counter, 1) - binary.BigEndian.PutUint64(seqno, counter) - + seqno := p.nextSeqno() p.publish <- &Message{ &pb.Message{ Data: data, @@ -612,6 +609,13 @@ func (p *PubSub) Publish(topic string, data []byte) error { return nil } +func (p *PubSub) nextSeqno() []byte { + seqno := make([]byte, 8) + counter := atomic.AddUint64(&p.counter, 1) + binary.BigEndian.PutUint64(seqno, counter) + return seqno +} + type listPeerReq struct { resp chan []peer.ID topic string