refactor nextSeqno out of Publish
This commit is contained in:
parent
e8a91d330a
commit
d6dfe83ebe
12
pubsub.go
12
pubsub.go
@ -597,10 +597,7 @@ func (p *PubSub) GetTopics() []string {
|
|||||||
|
|
||||||
// Publish publishes data under the given topic
|
// Publish publishes data under the given topic
|
||||||
func (p *PubSub) Publish(topic string, data []byte) error {
|
func (p *PubSub) Publish(topic string, data []byte) error {
|
||||||
seqno := make([]byte, 8)
|
seqno := p.nextSeqno()
|
||||||
counter := atomic.AddUint64(&p.counter, 1)
|
|
||||||
binary.BigEndian.PutUint64(seqno, counter)
|
|
||||||
|
|
||||||
p.publish <- &Message{
|
p.publish <- &Message{
|
||||||
&pb.Message{
|
&pb.Message{
|
||||||
Data: data,
|
Data: data,
|
||||||
@ -612,6 +609,13 @@ func (p *PubSub) Publish(topic string, data []byte) error {
|
|||||||
return nil
|
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 {
|
type listPeerReq struct {
|
||||||
resp chan []peer.ID
|
resp chan []peer.ID
|
||||||
topic string
|
topic string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user