github.com/koko1123/flow-go-1@v0.29.6/network/p2p/p2pnode/gossipSubTopic.go (about)

     1  package p2pnode
     2  
     3  import (
     4  	"context"
     5  
     6  	pubsub "github.com/libp2p/go-libp2p-pubsub"
     7  
     8  	"github.com/koko1123/flow-go-1/network/p2p"
     9  )
    10  
    11  // GossipSubTopic is a wrapper around libp2p pubsub topics that implements the
    12  // PubSubTopic interface for the Flow network.
    13  type GossipSubTopic struct {
    14  	t *pubsub.Topic
    15  }
    16  
    17  var _ p2p.Topic = (*GossipSubTopic)(nil)
    18  
    19  func NewGossipSubTopic(topic *pubsub.Topic) *GossipSubTopic {
    20  	return &GossipSubTopic{
    21  		t: topic,
    22  	}
    23  }
    24  
    25  func (g *GossipSubTopic) String() string {
    26  	return g.t.String()
    27  }
    28  
    29  func (g *GossipSubTopic) Close() error {
    30  	return g.t.Close()
    31  }
    32  
    33  func (g *GossipSubTopic) Publish(ctx context.Context, bytes []byte) error {
    34  	return g.t.Publish(ctx, bytes)
    35  }
    36  
    37  func (g *GossipSubTopic) Subscribe() (p2p.Subscription, error) {
    38  	return g.t.Subscribe()
    39  }