func (node *HostNode) SubscribeMessage(topic string, handler func([]byte, peer.ID)) (*pubsub.Subscription, error) {
	subscription, err := node.gossipSub.Subscribe(topic)
	if err != nil {
		return nil, err
	}

	go func() {
		for {
			msg, err := subscription.Next(node.ctx)
			logrus.WithFields(logrus.Fields{
				"peer":  msg.GetFrom(),
				"topic": topic,
				"size":  len(msg.Data),
			}).Debug("got broadcast from peer")
			if err != nil {
				logrus.WithField("error", err).Warn("error when getting next topic message")
				continue
			}

			handler(msg.Data, msg.GetFrom())
		}
	}()

	return subscription, nil
}
// SubscribeMessage registers a handler for a network topic.
SubscribeMessage registers a handler for a network topic.
// SubscribeMessage registers a handler for a network topic .
func (node *HostNode) SubscribeMessage(topic string, handler func([]byte, peer.ID)) (*pubsub.Subscription, error) {
	subscription, err := node.gossipSub.Subscribe(topic)
	if err != nil {
		return nil, err
	}
	go func() {
		for {
			msg, err := subscription.Next(node.ctx)
			logrus.WithFields(logrus.Fields{
				"peer":  msg.GetFrom(),
				"topic": topic,
				"size":  len(msg.Data),
			}).Debug("got broadcast from peer")
			if err != nil {
				logrus.WithField("error", err).Warn("error when getting next topic message")
				continue
			}
			handler(msg.Data, msg.GetFrom())
		}
	}()
	return subscription, nil
}
func ( node * HostNode ) SubscribeMessage ( topic string , handler func ( [ ] byte , peer . ID ) ) ( * pubsub . Subscription , error ) { subscription , err := node . gossipSub . Subscribe ( topic ) if err != nil { return nil , err } go func ( ) { for { msg , err := subscription . Next ( node . ctx ) logrus . WithFields ( logrus . Fields { " " : msg . GetFrom ( ) , " " : topic , " " : len ( msg . Data ) , } ) . Debug ( " " ) if err != nil { logrus . WithField ( " " , err ) . Warn ( " " ) continue } handler ( msg . Data , msg . GetFrom ( ) ) } } ( ) return subscription , nil }
SubscribeMessage registers a handler for a network topic.
SubscribeMessage registers a handler for a network topic .