github.com/celestiaorg/celestia-node@v0.15.0-beta.1/share/p2p/shrexsub/doc.go (about)

     1  // This package defines a protocol that is used to broadcast shares to peers over a pubsub network.
     2  //
     3  // This protocol runs on a rudimentary floodsub network is primarily a pubsub protocol
     4  // that broadcasts and listens for shares over a pubsub topic.
     5  //
     6  // The pubsub topic used by this protocol is:
     7  //
     8  //	"{networkID}/eds-sub/v0.1.0"
     9  //
    10  // where networkID is the network ID of the celestia-node that is running the protocol. (e.g. "arabica")
    11  //
    12  // # Usage
    13  //
    14  // To use this protocol, you must first create a new `shrexsub.PubSub` instance by:
    15  //
    16  //	pubsub, err := shrexsub.NewPubSub(ctx, host, networkID)
    17  //
    18  // where host is the libp2p host that is running the protocol, and networkID is the network ID of the celestia-node
    19  // that is running the protocol.
    20  //
    21  // After this, you can start the pubsub protocol by:
    22  //
    23  //	err := pubsub.Start(ctx)
    24  //
    25  // Once you have started the `shrexsub.PubSub` instance, you can broadcast a share by:
    26  //
    27  //	err := pubsub.Broadcast(ctx, notification)
    28  //
    29  // where `notification` is of type [shrexsub.Notification].
    30  //
    31  // and `DataHash` is the hash of the share that you want to broadcast, and `Height` is the height of the share.
    32  //
    33  // You can also subscribe to the pubsub topic by:
    34  //
    35  //	sub, err := pubsub.Subscribe(ctx)
    36  //
    37  // and then receive notifications by:
    38  //
    39  //	  for {
    40  //	  	select {
    41  //	  	case <-ctx.Done():
    42  //				sub.Cancel()
    43  //	  		return
    44  //	  	case notification, err := <-sub.Next():
    45  //	  		// handle notification or err
    46  //	  	}
    47  //	  }
    48  //
    49  // You can also manipulate the received pubsub messages by using the [PubSub.AddValidator] method:
    50  //
    51  //	pubsub.AddValidator(validator ValidatorFn)
    52  //
    53  // where `validator` is of type [shrexsub.ValidatorFn] and `Notification` is the same as above.
    54  //
    55  // You can also stop the pubsub protocol by:
    56  //
    57  //	err := pubsub.Stop(ctx)
    58  package shrexsub