go-waku/waku/v2/protocol/waku_relay.go

37 lines
1.0 KiB
Go
Raw Normal View History

2021-03-12 19:06:20 +00:00
// Waku Relay module. Thin layer on top of GossipSub.
//
// See https://github.com/vacp2p/specs/blob/master/specs/waku/v2/waku-relay.md
// for spec.
package protocol
import (
"context"
"github.com/libp2p/go-libp2p-core/host"
libp2pProtocol "github.com/libp2p/go-libp2p-core/protocol"
pubsub "github.com/libp2p/go-libp2p-pubsub"
)
2021-03-18 16:40:47 +00:00
const WakuRelayProtocol = libp2pProtocol.ID("/vac/waku/relay/2.0.0-beta2")
2021-03-12 19:06:20 +00:00
type WakuRelay struct {
2021-03-12 19:06:20 +00:00
p *pubsub.PubSub
}
2021-03-15 16:07:23 +00:00
func NewWakuRelay(ctx context.Context, h host.Host, opts ...pubsub.Option) (*pubsub.PubSub, error) {
// Once https://github.com/status-im/nim-waku/issues/420 is fixed, implement a custom messageIdFn
//opts = append(opts, pubsub.WithNoAuthor())
//opts = append(opts, pubsub.WithMessageIdFn(messageIdFn))
2021-03-15 16:07:23 +00:00
opts = append(opts, pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign))
2021-03-18 16:40:47 +00:00
gossipSub, err := pubsub.NewGossipSub(ctx, h, []libp2pProtocol.ID{WakuRelayProtocol}, opts...)
2021-03-12 19:06:20 +00:00
if err != nil {
return nil, err
}
w := new(WakuRelay)
2021-03-12 19:06:20 +00:00
w.p = gossipSub
return gossipSub, nil
}