refactor nextSeqno out of Publish

This commit is contained in:
vyzo 2018-03-10 10:14:21 +02:00 committed by Steven Allen
parent e8a91d330a
commit d6dfe83ebe

View File

@ -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