diff --git a/cmd/waku/flags.go b/cmd/waku/flags.go index 7c8c2c6b..2951932a 100644 --- a/cmd/waku/flags.go +++ b/cmd/waku/flags.go @@ -297,6 +297,12 @@ var ( Destination: &options.Filter.Enable, EnvVars: []string{"WAKUNODE2_FILTER"}, }) + FilterV2Flag = altsrc.NewBoolFlag(&cli.BoolFlag{ + Name: "use-filterv2", + Usage: "Use filterV2 protocol (experimental)", + Destination: &options.Filter.UseV2, + EnvVars: []string{"WAKUNODE2_FILTERV2"}, + }) LightClient = altsrc.NewBoolFlag(&cli.BoolFlag{ Name: "light-client", Usage: "Don't accept filter subscribers", diff --git a/cmd/waku/main.go b/cmd/waku/main.go index 3d61f961..af68d897 100644 --- a/cmd/waku/main.go +++ b/cmd/waku/main.go @@ -58,6 +58,7 @@ func main() { SwapPaymentThreshold, SwapDisconnectThreshold, FilterFlag, + FilterV2Flag, LightClient, FilterNode, FilterTimeout, diff --git a/examples/chat2/exec.go b/examples/chat2/exec.go index 40e7c07e..9caba2cf 100644 --- a/examples/chat2/exec.go +++ b/examples/chat2/exec.go @@ -11,6 +11,7 @@ import ( "github.com/multiformats/go-multiaddr" "github.com/waku-org/go-waku/waku/v2/node" "github.com/waku-org/go-waku/waku/v2/protocol/filter" + "github.com/waku-org/go-waku/waku/v2/protocol/filterv2" "github.com/waku-org/go-waku/waku/v2/protocol/lightpush" "github.com/waku-org/go-waku/waku/v2/protocol/pb" "github.com/waku-org/go-waku/waku/v2/protocol/store" @@ -81,13 +82,12 @@ func execute(options Options) { } if options.Filter.Enable { - opts = append(opts, node.WithWakuFilter(false)) + if options.Filter.UseV2 { + opts = append(opts, node.WithWakuFilterV2LightNode()) + } else { + opts = append(opts, node.WithWakuFilter(false)) + } } - - if options.LightPush.Enable { - opts = append(opts, node.WithLightPush()) - } - ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -109,7 +109,11 @@ func execute(options Options) { return } - err = addPeer(wakuNode, options.Filter.Node, string(filter.FilterID_v20beta1)) + if options.Filter.UseV2 { + err = addPeer(wakuNode, options.Filter.Node, string(filterv2.FilterSubscribeID_v20beta1)) + } else { + err = addPeer(wakuNode, options.Filter.Node, string(filter.FilterID_v20beta1)) + } if err != nil { fmt.Println(err.Error()) return diff --git a/examples/chat2/flags.go b/examples/chat2/flags.go index 1c613a2c..865238d6 100644 --- a/examples/chat2/flags.go +++ b/examples/chat2/flags.go @@ -117,7 +117,7 @@ func getFlags() []cli.Flag { }, &cli.BoolFlag{ Name: "store", - Usage: "Enable relay protocol", + Usage: "Enable store protocol", Value: true, Destination: &options.Store.Enable, }, @@ -133,6 +133,11 @@ func getFlags() []cli.Flag { Usage: "Enable filter protocol", Destination: &options.Filter.Enable, }, + &cli.BoolFlag{ + Name: "use-filterv2", + Usage: "Use filterV2 protocol (experimental)", + Destination: &options.Filter.UseV2, + }, &cli.GenericFlag{ Name: "filternode", Usage: "Multiaddr of a peer that supports filter protocol.", diff --git a/examples/chat2/go.mod b/examples/chat2/go.mod index 3066f552..aff7b963 100644 --- a/examples/chat2/go.mod +++ b/examples/chat2/go.mod @@ -16,7 +16,7 @@ require ( github.com/libp2p/go-libp2p v0.23.2 github.com/muesli/reflow v0.3.0 github.com/multiformats/go-multiaddr v0.7.0 - github.com/urfave/cli/v2 v2.20.2 + github.com/urfave/cli/v2 v2.23.7 github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba github.com/waku-org/go-zerokit-rln v0.1.7-wakuorg golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e @@ -25,6 +25,7 @@ require ( ) require ( + github.com/BurntSushi/toml v1.2.1 // indirect github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/VictoriaMetrics/fastcache v1.6.0 // indirect github.com/atotto/clipboard v0.1.4 // indirect @@ -154,5 +155,6 @@ require ( golang.org/x/tools v0.1.12 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect ) diff --git a/examples/chat2/go.sum b/examples/chat2/go.sum index 7f7caf86..19b2fb2c 100644 --- a/examples/chat2/go.sum +++ b/examples/chat2/go.sum @@ -56,6 +56,8 @@ github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -751,8 +753,8 @@ github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef h1:wHSqTBrZ github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -github.com/urfave/cli/v2 v2.20.2 h1:dKA0LUjznZpwmmbrc0pOgcLTEilnHeM8Av9Yng77gHM= -github.com/urfave/cli/v2 v2.20.2/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= +github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY= +github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= diff --git a/examples/chat2/options.go b/examples/chat2/options.go index 2ea62e81..b790c111 100644 --- a/examples/chat2/options.go +++ b/examples/chat2/options.go @@ -59,6 +59,7 @@ func nodePeerID(node *multiaddr.Multiaddr) (peer.ID, error) { // restricted devices. type FilterOptions struct { Enable bool + UseV2 bool Node *multiaddr.Multiaddr } diff --git a/waku/node.go b/waku/node.go index 08322738..e1eeecde 100644 --- a/waku/node.go +++ b/waku/node.go @@ -160,7 +160,14 @@ func Execute(options Options) { } if options.Filter.Enable { - nodeOpts = append(nodeOpts, node.WithWakuFilter(!options.Filter.DisableFullNode, filter.WithTimeout(options.Filter.Timeout))) + if options.Filter.UseV2 { + if !options.Filter.DisableFullNode { + nodeOpts = append(nodeOpts, node.WithWakuFilterV2FullNode(filter.WithTimeout(options.Filter.Timeout))) + } + nodeOpts = append(nodeOpts, node.WithWakuFilterV2LightNode()) + } else { + nodeOpts = append(nodeOpts, node.WithWakuFilter(!options.Filter.DisableFullNode, filter.WithTimeout(options.Filter.Timeout))) + } } if options.Store.Enable { @@ -233,7 +240,12 @@ func Execute(options Options) { addPeers(wakuNode, options.Store.Nodes, string(store.StoreID_v20beta4)) addPeers(wakuNode, options.LightPush.Nodes, string(lightpush.LightPushID_v20beta1)) - addPeers(wakuNode, options.Filter.Nodes, string(filter.FilterID_v20beta1)) + + if options.Filter.UseV2 { + addPeers(wakuNode, options.Filter.Nodes, string(filter.FilterID_v20beta1)) + } else { + addPeers(wakuNode, options.Filter.Nodes, string(filter.FilterID_v20beta1)) + } if err = wakuNode.Start(ctx); err != nil { logger.Fatal("starting waku node", zap.Error(err)) diff --git a/waku/options.go b/waku/options.go index d07b02e6..02efef7b 100644 --- a/waku/options.go +++ b/waku/options.go @@ -47,6 +47,7 @@ type RLNRelayOptions struct { // restricted devices. type FilterOptions struct { Enable bool + UseV2 bool DisableFullNode bool Nodes []multiaddr.Multiaddr Timeout time.Duration diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 57eadb9c..0dd198af 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -32,6 +32,7 @@ import ( "github.com/waku-org/go-waku/waku/v2/discv5" "github.com/waku-org/go-waku/waku/v2/metrics" "github.com/waku-org/go-waku/waku/v2/protocol/filter" + "github.com/waku-org/go-waku/waku/v2/protocol/filterv2" "github.com/waku-org/go-waku/waku/v2/protocol/lightpush" "github.com/waku-org/go-waku/waku/v2/protocol/pb" "github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange" @@ -78,6 +79,7 @@ type WakuNode struct { discoveryV5 Service peerExchange Service filter ReceptorService + filterV2 ReceptorService store ReceptorService rlnRelay RLNRelay @@ -208,6 +210,7 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) { w.relay = relay.NewWakuRelay(w.host, w.bcaster, w.opts.minRelayPeersToPublish, w.timesource, w.log, w.opts.wOpts...) w.filter = filter.NewWakuFilter(w.host, w.bcaster, w.opts.isFilterFullNode, w.timesource, w.log, w.opts.filterOpts...) + w.filterV2 = filterv2.NewWakuFilter(w.host, w.bcaster, w.timesource, w.log, w.opts.filterOpts...) w.lightPush = lightpush.NewWakuLightPush(w.host, w.Relay(), w.log) if w.opts.enableSwap { @@ -353,6 +356,16 @@ func (w *WakuNode) Start(ctx context.Context) error { w.bcaster.Register(nil, w.filter.MessageChannel()) } + if w.opts.enableFilterV2FullNode { + err := w.filterV2.Start(ctx) + if err != nil { + return err + } + + w.log.Info("Subscribing filterV2 to broadcaster") + w.bcaster.Register(nil, w.filterV2.MessageChannel()) + } + err = w.setupENR(ctx, w.ListenAddresses()) if err != nil { return err @@ -394,6 +407,7 @@ func (w *WakuNode) Stop() { w.lightPush.Stop() w.store.Stop() w.filter.Stop() + w.filterV2.Stop() w.peerExchange.Stop() if w.opts.enableDiscV5 { diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index 2c201d00..b0c1c377 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -60,12 +60,14 @@ type WakuNodeParameters struct { logger *zap.Logger - noDefaultWakuTopic bool - enableRelay bool - enableFilter bool - isFilterFullNode bool - filterOpts []filter.Option - wOpts []pubsub.Option + noDefaultWakuTopic bool + enableRelay bool + enableFilter bool + isFilterFullNode bool + enableFilterV2LightNode bool + enableFilterV2FullNode bool + filterOpts []filter.Option + wOpts []pubsub.Option minRelayPeersToPublish int @@ -310,7 +312,7 @@ func WithPeerExchange() WakuNodeOption { } } -// WithWakuFilter enables the Waku V2 Filter protocol. This WakuNodeOption +// WithWakuFilter enables the Waku Filter protocol. This WakuNodeOption // accepts a list of WakuFilter gossipsub options to setup the protocol func WithWakuFilter(fullNode bool, filterOpts ...filter.Option) WakuNodeOption { return func(params *WakuNodeParameters) error { @@ -321,6 +323,24 @@ func WithWakuFilter(fullNode bool, filterOpts ...filter.Option) WakuNodeOption { } } +// WithWakuFilterV2 enables the Waku Filter V2 protocol for lightnode functionality +func WithWakuFilterV2LightNode() WakuNodeOption { + return func(params *WakuNodeParameters) error { + params.enableFilterV2LightNode = true + return nil + } +} + +// WithWakuFilterV2FullNode enables the Waku Filter V2 protocol full node functionality. +// This WakuNodeOption accepts a list of WakuFilter options to setup the protocol +func WithWakuFilterV2FullNode(filterOpts ...filter.Option) WakuNodeOption { + return func(params *WakuNodeParameters) error { + params.enableFilterV2FullNode = true + params.filterOpts = filterOpts + return nil + } +} + // WithWakuStore enables the Waku V2 Store protocol and if the messages should // be stored or not in a message provider. If resumeNodes are specified, the // store will attempt to resume message history using those nodes diff --git a/waku/v2/protocol/filter/waku_filter.go b/waku/v2/protocol/filter/waku_filter.go index 7773cc2e..eb54b8f1 100644 --- a/waku/v2/protocol/filter/waku_filter.go +++ b/waku/v2/protocol/filter/waku_filter.go @@ -80,7 +80,7 @@ func NewWakuFilter(host host.Host, broadcaster v2.Broadcaster, isFullNode bool, wf.h = host wf.isFullNode = isFullNode wf.filters = NewFilterMap(broadcaster, timesource) - wf.subscribers = NewSubscribers(params.timeout) + wf.subscribers = NewSubscribers(params.Timeout) return wf } @@ -287,7 +287,7 @@ func (wf *WakuFilter) requestSubscription(ctx context.Context, filter ContentFil writer := protoio.NewDelimitedWriter(conn) filterRPC := &pb.FilterRPC{RequestId: requestID, Request: &request} - wf.log.Info("sending filterRPC", zap.Stringer("rpc", filterRPC)) + wf.log.Debug("sending filterRPC", zap.Stringer("rpc", filterRPC)) err = writer.WriteMsg(filterRPC) if err != nil { wf.log.Error("sending filterRPC", zap.Error(err)) diff --git a/waku/v2/protocol/filter/waku_filter_option.go b/waku/v2/protocol/filter/waku_filter_option.go index 653d28f8..5daac3e0 100644 --- a/waku/v2/protocol/filter/waku_filter_option.go +++ b/waku/v2/protocol/filter/waku_filter_option.go @@ -20,7 +20,7 @@ type ( FilterSubscribeOption func(*FilterSubscribeParameters) FilterParameters struct { - timeout time.Duration + Timeout time.Duration } Option func(*FilterParameters) @@ -28,7 +28,7 @@ type ( func WithTimeout(timeout time.Duration) Option { return func(params *FilterParameters) { - params.timeout = timeout + params.Timeout = timeout } } diff --git a/waku/v2/protocol/filterv2/client.go b/waku/v2/protocol/filterv2/client.go new file mode 100644 index 00000000..5f91ef2d --- /dev/null +++ b/waku/v2/protocol/filterv2/client.go @@ -0,0 +1,7 @@ +package filterv2 + +import libp2pProtocol "github.com/libp2p/go-libp2p/core/protocol" + +// FilterPushID_v20beta1 is the current Waku Filter protocol identifier used to allow +// filter service nodes to push messages matching registered subscriptions to this client. +const FilterPushID_v20beta1 = libp2pProtocol.ID("/vac/waku/filter-push/2.0.0-beta1") diff --git a/waku/v2/protocol/filterv2/server.go b/waku/v2/protocol/filterv2/server.go new file mode 100644 index 00000000..05c1bc3d --- /dev/null +++ b/waku/v2/protocol/filterv2/server.go @@ -0,0 +1,272 @@ +package filterv2 + +import ( + "context" + "errors" + "math" + "net/http" + "sync" + + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/network" + "github.com/libp2p/go-libp2p/core/peer" + libp2pProtocol "github.com/libp2p/go-libp2p/core/protocol" + "github.com/libp2p/go-msgio/protoio" + "github.com/waku-org/go-waku/logging" + v2 "github.com/waku-org/go-waku/waku/v2" + "github.com/waku-org/go-waku/waku/v2/metrics" + "github.com/waku-org/go-waku/waku/v2/protocol" + "github.com/waku-org/go-waku/waku/v2/protocol/filter" + "github.com/waku-org/go-waku/waku/v2/protocol/pb" + "github.com/waku-org/go-waku/waku/v2/timesource" + "go.opencensus.io/tag" + "go.uber.org/zap" + "golang.org/x/sync/errgroup" +) + +// FilterSubscribeID_v20beta1 is the current Waku Filter protocol identifier for servers to +// allow filter clients to subscribe, modify, refresh and unsubscribe a desired set of filter criteria +const FilterSubscribeID_v20beta1 = libp2pProtocol.ID("/vac/waku/filter-subscribe/2.0.0-beta1") + +type ( + WakuFilter struct { + cancel context.CancelFunc + h host.Host + msgC chan *protocol.Envelope + wg *sync.WaitGroup + log *zap.Logger + + subscriptions *SubscriptionMap + } +) + +// NewWakuFilter returns a new instance of Waku Filter struct setup according to the chosen parameter and options +func NewWakuFilter(host host.Host, broadcaster v2.Broadcaster, timesource timesource.Timesource, log *zap.Logger, opts ...filter.Option) *WakuFilter { + wf := new(WakuFilter) + wf.log = log.Named("filterv2-fullnode") + + params := new(filter.FilterParameters) + optList := filter.DefaultOptions() + optList = append(optList, opts...) + for _, opt := range optList { + opt(params) + } + + wf.wg = &sync.WaitGroup{} + wf.h = host + wf.subscriptions = NewSubscriptionMap(broadcaster, timesource, params.Timeout) + + return wf +} + +func (wf *WakuFilter) Start(ctx context.Context) error { + wf.wg.Wait() // Wait for any goroutines to stop + + ctx, err := tag.New(ctx, tag.Insert(metrics.KeyType, "filter")) + if err != nil { + wf.log.Error("creating tag map", zap.Error(err)) + return errors.New("could not start waku filter") + } + + ctx, cancel := context.WithCancel(ctx) + + wf.h.SetStreamHandlerMatch(FilterSubscribeID_v20beta1, protocol.PrefixTextMatch(string(FilterSubscribeID_v20beta1)), wf.onRequest(ctx)) + + wf.cancel = cancel + wf.msgC = make(chan *protocol.Envelope, 1024) + + wf.wg.Add(1) + go wf.filterListener(ctx) + + wf.log.Info("filter protocol started") + + return nil +} + +func (wf *WakuFilter) onRequest(ctx context.Context) func(s network.Stream) { + return func(s network.Stream) { + defer s.Close() + logger := wf.log.With(logging.HostID("peer", s.Conn().RemotePeer())) + + reader := protoio.NewDelimitedReader(s, math.MaxInt32) + + subscribeRequest := &pb.FilterSubscribeRequest{} + err := reader.ReadMsg(subscribeRequest) + if err != nil { + logger.Error("reading request", zap.Error(err)) + return + } + + logger = logger.With(zap.String("requestID", subscribeRequest.RequestId)) + + switch subscribeRequest.FilterSubscribeType { + case pb.FilterSubscribeRequest_SUBSCRIBE: + wf.subscribe(s, logger, subscribeRequest) + case pb.FilterSubscribeRequest_SUBSCRIBER_PING: + wf.ping(s, logger, subscribeRequest) + case pb.FilterSubscribeRequest_UNSUBSCRIBE: + wf.unsubscribe(s, logger, subscribeRequest) + case pb.FilterSubscribeRequest_UNSUBSCRIBE_ALL: + wf.unsubscribeAll(s, logger, subscribeRequest) + } + + logger.Info("received request") + } +} + +func reply(s network.Stream, logger *zap.Logger, request *pb.FilterSubscribeRequest, statusCode int, description ...string) { + response := &pb.FilterSubscribeResponse{ + RequestId: request.RequestId, + StatusCode: uint32(statusCode), + } + + if len(description) != 0 { + response.StatusDesc = description[0] + } else { + response.StatusDesc = http.StatusText(statusCode) + } + + writer := protoio.NewDelimitedWriter(s) + err := writer.WriteMsg(response) + if err != nil { + logger.Error("sending response", zap.Error(err)) + } +} + +func (wf *WakuFilter) ping(s network.Stream, logger *zap.Logger, request *pb.FilterSubscribeRequest) { + exists := wf.subscriptions.Has(s.Conn().RemotePeer()) + + if exists { + reply(s, logger, request, http.StatusOK) + } else { + reply(s, logger, request, http.StatusNotFound) + } +} + +func (wf *WakuFilter) subscribe(s network.Stream, logger *zap.Logger, request *pb.FilterSubscribeRequest) { + if request.PubsubTopic == "" { + reply(s, logger, request, http.StatusBadRequest, "pubsubtopic can't be empty") + } + + peerID := s.Conn().RemotePeer() + + wf.subscriptions.Set(peerID, request.PubsubTopic, request.ContentTopics) + + reply(s, logger, request, http.StatusOK) +} + +func (wf *WakuFilter) unsubscribe(s network.Stream, logger *zap.Logger, request *pb.FilterSubscribeRequest) { + if request.PubsubTopic == "" { + reply(s, logger, request, http.StatusBadRequest, "pubsubtopic can't be empty") + } + + err := wf.subscriptions.Delete(s.Conn().RemotePeer(), request.PubsubTopic, request.ContentTopics) + if err != nil { + reply(s, logger, request, http.StatusNotFound) + } else { + reply(s, logger, request, http.StatusOK) + } +} + +func (wf *WakuFilter) unsubscribeAll(s network.Stream, logger *zap.Logger, request *pb.FilterSubscribeRequest) { + err := wf.subscriptions.DeleteAll(s.Conn().RemotePeer()) + if err != nil { + reply(s, logger, request, http.StatusNotFound) + } else { + reply(s, logger, request, http.StatusOK) + } +} + +func (wf *WakuFilter) filterListener(ctx context.Context) { + defer wf.wg.Done() + + // This function is invoked for each message received + // on the full node in context of Waku2-Filter + handle := func(envelope *protocol.Envelope) error { + msg := envelope.Message() + pubsubTopic := envelope.PubsubTopic() + logger := wf.log.With(logging.HexBytes("envelopeHash", envelope.Hash())) + g := new(errgroup.Group) + + // Each subscriber is a light node that earlier on invoked + // a FilterRequest on this node + for subscriber := range wf.subscriptions.Items(pubsubTopic, msg.ContentTopic) { + logger := logger.With(logging.HostID("subscriber", subscriber)) + subscriber := subscriber // https://golang.org/doc/faq#closures_and_goroutines + // Do a message push to light node + logger.Info("pushing message to light node") + g.Go(func() (err error) { + err = wf.pushMessage(ctx, subscriber, envelope) + if err != nil { + logger.Error("pushing message", zap.Error(err)) + } + return err + }) + } + + return g.Wait() + } + + for m := range wf.msgC { + if err := handle(m); err != nil { + wf.log.Error("handling message", zap.Error(err)) + } + } +} + +func (wf *WakuFilter) pushMessage(ctx context.Context, peerID peer.ID, env *protocol.Envelope) error { + logger := wf.log.With(logging.HostID("peer", peerID)) + + messagePush := &pb.MessagePushV2{ + PubsubTopic: env.PubsubTopic(), + WakuMessage: env.Message(), + } + + // We connect first so dns4 addresses are resolved (NewStream does not do it) + err := wf.h.Connect(ctx, wf.h.Peerstore().PeerInfo(peerID)) + if err != nil { + wf.subscriptions.FlagAsFailure(peerID) + logger.Error("connecting to peer", zap.Error(err)) + return err + } + + conn, err := wf.h.NewStream(ctx, peerID, FilterPushID_v20beta1) + if err != nil { + wf.subscriptions.FlagAsFailure(peerID) + + logger.Error("opening peer stream", zap.Error(err)) + //waku_filter_errors.inc(labelValues = [dialFailure]) + return err + } + + defer conn.Close() + writer := protoio.NewDelimitedWriter(conn) + err = writer.WriteMsg(messagePush) + if err != nil { + logger.Error("pushing messages to peer", zap.Error(err)) + wf.subscriptions.FlagAsFailure(peerID) + return nil + } + + wf.subscriptions.FlagAsSuccess(peerID) + return nil +} + +// Stop unmounts the filter protocol +func (wf *WakuFilter) Stop() { + if wf.cancel == nil { + return + } + + wf.h.RemoveStreamHandler(FilterSubscribeID_v20beta1) + + wf.cancel() + + close(wf.msgC) + + wf.wg.Wait() +} + +func (wf *WakuFilter) MessageChannel() chan *protocol.Envelope { + return wf.msgC +} diff --git a/waku/v2/protocol/filterv2/subscription_map.go b/waku/v2/protocol/filterv2/subscription_map.go new file mode 100644 index 00000000..b19f8315 --- /dev/null +++ b/waku/v2/protocol/filterv2/subscription_map.go @@ -0,0 +1,293 @@ +package filterv2 + +import ( + "encoding/hex" + "errors" + "sync" + "time" + + "github.com/ethereum/go-ethereum/crypto" + "github.com/libp2p/go-libp2p/core/peer" + v2 "github.com/waku-org/go-waku/waku/v2" + "github.com/waku-org/go-waku/waku/v2/protocol/pb" + "github.com/waku-org/go-waku/waku/v2/timesource" +) + +var ErrNotFound = errors.New("not found") + +type ContentTopicSet map[string]struct{} + +type PeerSet map[peer.ID]struct{} + +type PubsubTopics map[string]ContentTopicSet // pubsubTopic => contentTopics + +type SubscriptionMap struct { + sync.RWMutex + timesource timesource.Timesource + + items map[peer.ID]PubsubTopics + interestMap map[string]PeerSet // key: sha256(pubsubTopic-contentTopic) => peers + + timeout time.Duration + failedPeers map[peer.ID]time.Time + + broadcaster v2.Broadcaster +} + +type SubscriptionItem struct { + Key peer.ID + Value PubsubTopics +} + +func NewSubscriptionMap(broadcaster v2.Broadcaster, timesource timesource.Timesource, timeout time.Duration) *SubscriptionMap { + return &SubscriptionMap{ + timesource: timesource, + items: make(map[peer.ID]PubsubTopics), + interestMap: make(map[string]PeerSet), + broadcaster: broadcaster, + timeout: timeout, + failedPeers: make(map[peer.ID]time.Time), + } +} + +func (sub *SubscriptionMap) Set(peerID peer.ID, pubsubTopic string, contentTopics []string) { + sub.Lock() + defer sub.Unlock() + + pubsubTopicMap, ok := sub.items[peerID] + if !ok { + pubsubTopicMap = make(PubsubTopics) + } + + contentTopicsMap, ok := pubsubTopicMap[pubsubTopic] + if !ok { + contentTopicsMap = make(ContentTopicSet) + } + + for _, c := range contentTopics { + contentTopicsMap[c] = struct{}{} + } + + pubsubTopicMap[pubsubTopic] = contentTopicsMap + + sub.items[peerID] = pubsubTopicMap + + if len(contentTopics) == 0 { + // Interested in all messages for a pubsub topic + sub.addToInterestMap(peerID, pubsubTopic, nil) + } else { + for _, c := range contentTopics { + c := c + sub.addToInterestMap(peerID, pubsubTopic, &c) + } + } +} + +func (sub *SubscriptionMap) Get(peerID peer.ID) (PubsubTopics, bool) { + sub.RLock() + defer sub.RUnlock() + + value, ok := sub.items[peerID] + + return value, ok +} + +func (sub *SubscriptionMap) Has(peerID peer.ID) bool { + sub.RLock() + defer sub.RUnlock() + + _, ok := sub.items[peerID] + + return ok +} + +func (sub *SubscriptionMap) Delete(peerID peer.ID, pubsubTopic string, contentTopics []string) error { + sub.Lock() + defer sub.Unlock() + + pubsubTopicMap, ok := sub.items[peerID] + if !ok { + return ErrNotFound + } + + contentTopicsMap, ok := pubsubTopicMap[pubsubTopic] + if !ok { + return ErrNotFound + } + + if len(contentTopics) == 0 { + // Remove all content topics related to this pubsub topic + for c := range contentTopicsMap { + c := c + delete(contentTopicsMap, c) + sub.removeFromInterestMap(peerID, pubsubTopic, &c) + } + + delete(pubsubTopicMap, pubsubTopic) + sub.removeFromInterestMap(peerID, pubsubTopic, nil) + } else { + // Removing content topics individually + for _, c := range contentTopics { + c := c + delete(contentTopicsMap, c) + sub.removeFromInterestMap(peerID, pubsubTopic, &c) + } + + // No more content topics available. Removing subscription completely + if len(contentTopicsMap) == 0 { + delete(pubsubTopicMap, pubsubTopic) + sub.removeFromInterestMap(peerID, pubsubTopic, nil) + } + } + + pubsubTopicMap[pubsubTopic] = contentTopicsMap + sub.items[peerID] = pubsubTopicMap + + return nil +} + +func (sub *SubscriptionMap) deleteAll(peerID peer.ID) error { + pubsubTopicMap, ok := sub.items[peerID] + if !ok { + return ErrNotFound + } + + for pubsubTopic, contentTopicsMap := range pubsubTopicMap { + // Remove all content topics related to this pubsub topic + for c := range contentTopicsMap { + c := c + delete(contentTopicsMap, c) + sub.removeFromInterestMap(peerID, pubsubTopic, &c) + } + + delete(pubsubTopicMap, pubsubTopic) + sub.removeFromInterestMap(peerID, pubsubTopic, nil) + } + + delete(sub.items, peerID) + + return nil +} + +func (sub *SubscriptionMap) DeleteAll(peerID peer.ID) error { + sub.Lock() + defer sub.Unlock() + + return sub.deleteAll(peerID) +} + +func (sub *SubscriptionMap) RemoveAll() { + sub.Lock() + defer sub.Unlock() + + for k /*, _ v*/ := range sub.items { + //close(v.Chan) + delete(sub.items, k) + } +} +func (sub *SubscriptionMap) Items(pubsubTopic string, contentTopic string) <-chan peer.ID { + c := make(chan peer.ID) + + onlyPubsubTopicKey := getKey(pubsubTopic, nil) + pubsubAndContentTopicKey := getKey(pubsubTopic, &contentTopic) + + f := func() { + sub.RLock() + defer sub.RUnlock() + for p := range sub.interestMap[onlyPubsubTopicKey] { + c <- p + } + for p := range sub.interestMap[pubsubAndContentTopicKey] { + c <- p + } + close(c) + } + go f() + + return c +} + +func (fm *SubscriptionMap) Notify(msg *pb.WakuMessage, peerID peer.ID) { + /*fm.RLock() + defer fm.RUnlock() + + filter, ok := fm.items[peerID] + if !ok { + return + } + + envelope := protocol.NewEnvelope(msg, fm.timesource.Now().UnixNano(), filter.Topic) + + // Broadcasting message so it's stored + fm.broadcaster.Submit(envelope) + + if msg.ContentTopic == "" { + filter.Chan <- envelope + } + + // TODO: In case of no topics we should either trigger here for all messages, + // or we should not allow such filter to exist in the first place. + for _, contentTopic := range filter.ContentFilters { + if msg.ContentTopic == contentTopic { + filter.Chan <- envelope + break + } + }*/ +} + +func (sub *SubscriptionMap) addToInterestMap(peerID peer.ID, pubsubTopic string, contentTopic *string) { + key := getKey(pubsubTopic, contentTopic) + peerSet, ok := sub.interestMap[key] + if !ok { + peerSet = make(PeerSet) + } + peerSet[peerID] = struct{}{} + sub.interestMap[key] = peerSet +} + +func (sub *SubscriptionMap) removeFromInterestMap(peerID peer.ID, pubsubTopic string, contentTopic *string) { + key := getKey(pubsubTopic, contentTopic) + delete(sub.interestMap, key) +} + +func getKey(pubsubTopic string, contentTopic *string) string { + pubsubTopicBytes := []byte(pubsubTopic) + if contentTopic == nil { + return hex.EncodeToString(crypto.Keccak256(pubsubTopicBytes)) + } else { + key := append(pubsubTopicBytes, []byte(*contentTopic)...) + return hex.EncodeToString(crypto.Keccak256(key)) + } +} + +func (sub *SubscriptionMap) IsFailedPeer(peerID peer.ID) bool { + sub.RLock() + defer sub.RUnlock() + _, ok := sub.failedPeers[peerID] + return ok +} + +func (sub *SubscriptionMap) FlagAsSuccess(peerID peer.ID) { + sub.Lock() + defer sub.Unlock() + + _, ok := sub.failedPeers[peerID] + if ok { + delete(sub.failedPeers, peerID) + } +} + +func (sub *SubscriptionMap) FlagAsFailure(peerID peer.ID) { + sub.Lock() + defer sub.Unlock() + + lastFailure, ok := sub.failedPeers[peerID] + if ok { + elapsedTime := time.Since(lastFailure) + if elapsedTime > sub.timeout { + sub.deleteAll(peerID) + } + } else { + sub.failedPeers[peerID] = time.Now() + } +} diff --git a/waku/v2/protocol/pb/generate.go b/waku/v2/protocol/pb/generate.go index dc477295..b43c68d2 100644 --- a/waku/v2/protocol/pb/generate.go +++ b/waku/v2/protocol/pb/generate.go @@ -6,3 +6,4 @@ package pb //go:generate protoc -I. --gofast_out=. ./waku_store.proto //go:generate protoc -I. --gofast_out=. ./waku_swap.proto //go:generate protoc -I. --gofast_out=. ./waku_peer_exchange.proto +//go:generate protoc -I. --gofast_out=. ./waku_filter_v2.proto diff --git a/waku/v2/protocol/pb/waku_filter_v2.pb.go b/waku/v2/protocol/pb/waku_filter_v2.pb.go new file mode 100644 index 00000000..75a84c97 --- /dev/null +++ b/waku/v2/protocol/pb/waku_filter_v2.pb.go @@ -0,0 +1,1025 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: waku_filter_v2.proto + +// 12/WAKU2-FILTER rfc: https://rfc.vac.dev/spec/12/ + +package pb + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type FilterSubscribeRequest_FilterSubscribeType int32 + +const ( + FilterSubscribeRequest_SUBSCRIBER_PING FilterSubscribeRequest_FilterSubscribeType = 0 + FilterSubscribeRequest_SUBSCRIBE FilterSubscribeRequest_FilterSubscribeType = 1 + FilterSubscribeRequest_UNSUBSCRIBE FilterSubscribeRequest_FilterSubscribeType = 2 + FilterSubscribeRequest_UNSUBSCRIBE_ALL FilterSubscribeRequest_FilterSubscribeType = 3 +) + +var FilterSubscribeRequest_FilterSubscribeType_name = map[int32]string{ + 0: "SUBSCRIBER_PING", + 1: "SUBSCRIBE", + 2: "UNSUBSCRIBE", + 3: "UNSUBSCRIBE_ALL", +} + +var FilterSubscribeRequest_FilterSubscribeType_value = map[string]int32{ + "SUBSCRIBER_PING": 0, + "SUBSCRIBE": 1, + "UNSUBSCRIBE": 2, + "UNSUBSCRIBE_ALL": 3, +} + +func (x FilterSubscribeRequest_FilterSubscribeType) String() string { + return proto.EnumName(FilterSubscribeRequest_FilterSubscribeType_name, int32(x)) +} + +func (FilterSubscribeRequest_FilterSubscribeType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_22975a4bb50808e9, []int{0, 0} +} + +// Protocol identifier: /vac/waku/filter-subscribe/2.0.0-beta1 +type FilterSubscribeRequest struct { + RequestId string `protobuf:"bytes,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` + FilterSubscribeType FilterSubscribeRequest_FilterSubscribeType `protobuf:"varint,2,opt,name=filter_subscribe_type,json=filterSubscribeType,proto3,enum=pb.FilterSubscribeRequest_FilterSubscribeType" json:"filter_subscribe_type,omitempty"` + // Filter criteria + PubsubTopic string `protobuf:"bytes,10,opt,name=pubsub_topic,json=pubsubTopic,proto3" json:"pubsub_topic,omitempty"` + ContentTopics []string `protobuf:"bytes,11,rep,name=content_topics,json=contentTopics,proto3" json:"content_topics,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *FilterSubscribeRequest) Reset() { *m = FilterSubscribeRequest{} } +func (m *FilterSubscribeRequest) String() string { return proto.CompactTextString(m) } +func (*FilterSubscribeRequest) ProtoMessage() {} +func (*FilterSubscribeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_22975a4bb50808e9, []int{0} +} +func (m *FilterSubscribeRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FilterSubscribeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FilterSubscribeRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *FilterSubscribeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_FilterSubscribeRequest.Merge(m, src) +} +func (m *FilterSubscribeRequest) XXX_Size() int { + return m.Size() +} +func (m *FilterSubscribeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_FilterSubscribeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_FilterSubscribeRequest proto.InternalMessageInfo + +func (m *FilterSubscribeRequest) GetRequestId() string { + if m != nil { + return m.RequestId + } + return "" +} + +func (m *FilterSubscribeRequest) GetFilterSubscribeType() FilterSubscribeRequest_FilterSubscribeType { + if m != nil { + return m.FilterSubscribeType + } + return FilterSubscribeRequest_SUBSCRIBER_PING +} + +func (m *FilterSubscribeRequest) GetPubsubTopic() string { + if m != nil { + return m.PubsubTopic + } + return "" +} + +func (m *FilterSubscribeRequest) GetContentTopics() []string { + if m != nil { + return m.ContentTopics + } + return nil +} + +type FilterSubscribeResponse struct { + RequestId string `protobuf:"bytes,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` + StatusCode uint32 `protobuf:"varint,10,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` + StatusDesc string `protobuf:"bytes,11,opt,name=status_desc,json=statusDesc,proto3" json:"status_desc,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *FilterSubscribeResponse) Reset() { *m = FilterSubscribeResponse{} } +func (m *FilterSubscribeResponse) String() string { return proto.CompactTextString(m) } +func (*FilterSubscribeResponse) ProtoMessage() {} +func (*FilterSubscribeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_22975a4bb50808e9, []int{1} +} +func (m *FilterSubscribeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FilterSubscribeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FilterSubscribeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *FilterSubscribeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_FilterSubscribeResponse.Merge(m, src) +} +func (m *FilterSubscribeResponse) XXX_Size() int { + return m.Size() +} +func (m *FilterSubscribeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_FilterSubscribeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_FilterSubscribeResponse proto.InternalMessageInfo + +func (m *FilterSubscribeResponse) GetRequestId() string { + if m != nil { + return m.RequestId + } + return "" +} + +func (m *FilterSubscribeResponse) GetStatusCode() uint32 { + if m != nil { + return m.StatusCode + } + return 0 +} + +func (m *FilterSubscribeResponse) GetStatusDesc() string { + if m != nil { + return m.StatusDesc + } + return "" +} + +// Protocol identifier: /vac/waku/filter-push/2.0.0-beta1 +type MessagePushV2 struct { + WakuMessage *WakuMessage `protobuf:"bytes,1,opt,name=waku_message,json=wakuMessage,proto3" json:"waku_message,omitempty"` + PubsubTopic string `protobuf:"bytes,2,opt,name=pubsub_topic,json=pubsubTopic,proto3" json:"pubsub_topic,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *MessagePushV2) Reset() { *m = MessagePushV2{} } +func (m *MessagePushV2) String() string { return proto.CompactTextString(m) } +func (*MessagePushV2) ProtoMessage() {} +func (*MessagePushV2) Descriptor() ([]byte, []int) { + return fileDescriptor_22975a4bb50808e9, []int{2} +} +func (m *MessagePushV2) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MessagePushV2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MessagePushV2.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MessagePushV2) XXX_Merge(src proto.Message) { + xxx_messageInfo_MessagePushV2.Merge(m, src) +} +func (m *MessagePushV2) XXX_Size() int { + return m.Size() +} +func (m *MessagePushV2) XXX_DiscardUnknown() { + xxx_messageInfo_MessagePushV2.DiscardUnknown(m) +} + +var xxx_messageInfo_MessagePushV2 proto.InternalMessageInfo + +func (m *MessagePushV2) GetWakuMessage() *WakuMessage { + if m != nil { + return m.WakuMessage + } + return nil +} + +func (m *MessagePushV2) GetPubsubTopic() string { + if m != nil { + return m.PubsubTopic + } + return "" +} + +func init() { + proto.RegisterEnum("pb.FilterSubscribeRequest_FilterSubscribeType", FilterSubscribeRequest_FilterSubscribeType_name, FilterSubscribeRequest_FilterSubscribeType_value) + proto.RegisterType((*FilterSubscribeRequest)(nil), "pb.FilterSubscribeRequest") + proto.RegisterType((*FilterSubscribeResponse)(nil), "pb.FilterSubscribeResponse") + proto.RegisterType((*MessagePushV2)(nil), "pb.MessagePushV2") +} + +func init() { proto.RegisterFile("waku_filter_v2.proto", fileDescriptor_22975a4bb50808e9) } + +var fileDescriptor_22975a4bb50808e9 = []byte{ + // 370 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xdd, 0x6e, 0xda, 0x30, + 0x14, 0x80, 0x49, 0x90, 0x26, 0xe5, 0x84, 0x40, 0x64, 0xf6, 0x13, 0x4d, 0x5a, 0xc6, 0x22, 0x4d, + 0xe2, 0x2a, 0x17, 0xd9, 0x13, 0x0c, 0xf6, 0x23, 0x24, 0x86, 0x90, 0x81, 0xed, 0xd2, 0x8a, 0x13, + 0xb3, 0x45, 0xac, 0xc4, 0x8d, 0xed, 0x22, 0xfa, 0x24, 0x7d, 0xa2, 0xaa, 0x97, 0x7d, 0x84, 0x8a, + 0xbe, 0x48, 0x85, 0x93, 0x16, 0xd4, 0x20, 0xf5, 0x2e, 0xf9, 0xfc, 0x9d, 0x73, 0x7c, 0xce, 0x31, + 0xbc, 0xde, 0xc4, 0x2b, 0x45, 0x96, 0xd9, 0x7f, 0xc9, 0x0a, 0x72, 0x11, 0x85, 0xbc, 0xc8, 0x65, + 0x8e, 0x4c, 0x4e, 0xdf, 0x23, 0x7d, 0x72, 0xc6, 0x84, 0x88, 0xff, 0xb2, 0x92, 0x07, 0xd7, 0x26, + 0xbc, 0xfd, 0xa1, 0xdd, 0x99, 0xa2, 0x22, 0x29, 0x32, 0xca, 0x30, 0x3b, 0x57, 0x4c, 0x48, 0xf4, + 0x01, 0xa0, 0x28, 0x3f, 0x49, 0x96, 0x7a, 0x46, 0xcf, 0xe8, 0x5b, 0xd8, 0xaa, 0xc8, 0x28, 0x45, + 0x14, 0xde, 0x54, 0x45, 0xc4, 0x63, 0x24, 0x91, 0x5b, 0xce, 0x3c, 0xb3, 0x67, 0xf4, 0xdb, 0x51, + 0x18, 0x72, 0x1a, 0x9e, 0xce, 0xfc, 0x1c, 0xcf, 0xb7, 0x9c, 0xe1, 0xee, 0xb2, 0x0e, 0xd1, 0x27, + 0x68, 0x71, 0x45, 0x85, 0xa2, 0x44, 0xe6, 0x3c, 0x4b, 0x3c, 0xd0, 0x97, 0xb0, 0x4b, 0x36, 0xdf, + 0x23, 0xf4, 0x19, 0xda, 0x49, 0xbe, 0x96, 0x6c, 0x2d, 0x4b, 0x47, 0x78, 0x76, 0xaf, 0xd9, 0xb7, + 0xb0, 0x53, 0x51, 0x6d, 0x89, 0x80, 0x40, 0xf7, 0x44, 0x55, 0xd4, 0x85, 0xce, 0x6c, 0x31, 0x98, + 0x0d, 0xf1, 0x68, 0xf0, 0x1d, 0x93, 0xe9, 0x68, 0xf2, 0xd3, 0x6d, 0x20, 0x07, 0xac, 0x27, 0xe8, + 0x1a, 0xa8, 0x03, 0xf6, 0x62, 0x72, 0x00, 0xe6, 0x3e, 0xe8, 0x08, 0x90, 0xaf, 0xe3, 0xb1, 0xdb, + 0x0c, 0x2e, 0xe1, 0x5d, 0xad, 0x5b, 0xc1, 0xf3, 0xb5, 0x60, 0x2f, 0x0d, 0xf2, 0x23, 0xd8, 0x42, + 0xc6, 0x52, 0x09, 0x92, 0xe4, 0x29, 0xd3, 0x3d, 0x3a, 0x18, 0x4a, 0x34, 0xcc, 0x53, 0x76, 0x24, + 0xa4, 0x4c, 0x24, 0x9e, 0xad, 0x13, 0x54, 0xc2, 0x37, 0x26, 0x92, 0x60, 0x09, 0xce, 0xaf, 0x72, + 0xab, 0x53, 0x25, 0xfe, 0xfd, 0x8e, 0x50, 0x04, 0xad, 0xe3, 0x5d, 0xeb, 0x9a, 0x76, 0xd4, 0xd9, + 0xaf, 0xe4, 0x4f, 0xbc, 0x52, 0x95, 0x8c, 0xed, 0xcd, 0xe1, 0xa7, 0x36, 0x6b, 0xb3, 0x36, 0xeb, + 0x81, 0x7b, 0xb3, 0xf3, 0x8d, 0xdb, 0x9d, 0x6f, 0xdc, 0xed, 0x7c, 0xe3, 0xea, 0xde, 0x6f, 0xd0, + 0x57, 0xfa, 0x15, 0x7d, 0x79, 0x08, 0x00, 0x00, 0xff, 0xff, 0xae, 0xd4, 0x6f, 0xea, 0x75, 0x02, + 0x00, 0x00, +} + +func (m *FilterSubscribeRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *FilterSubscribeRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FilterSubscribeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.ContentTopics) > 0 { + for iNdEx := len(m.ContentTopics) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ContentTopics[iNdEx]) + copy(dAtA[i:], m.ContentTopics[iNdEx]) + i = encodeVarintWakuFilterV2(dAtA, i, uint64(len(m.ContentTopics[iNdEx]))) + i-- + dAtA[i] = 0x5a + } + } + if len(m.PubsubTopic) > 0 { + i -= len(m.PubsubTopic) + copy(dAtA[i:], m.PubsubTopic) + i = encodeVarintWakuFilterV2(dAtA, i, uint64(len(m.PubsubTopic))) + i-- + dAtA[i] = 0x52 + } + if m.FilterSubscribeType != 0 { + i = encodeVarintWakuFilterV2(dAtA, i, uint64(m.FilterSubscribeType)) + i-- + dAtA[i] = 0x10 + } + if len(m.RequestId) > 0 { + i -= len(m.RequestId) + copy(dAtA[i:], m.RequestId) + i = encodeVarintWakuFilterV2(dAtA, i, uint64(len(m.RequestId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *FilterSubscribeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *FilterSubscribeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FilterSubscribeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.StatusDesc) > 0 { + i -= len(m.StatusDesc) + copy(dAtA[i:], m.StatusDesc) + i = encodeVarintWakuFilterV2(dAtA, i, uint64(len(m.StatusDesc))) + i-- + dAtA[i] = 0x5a + } + if m.StatusCode != 0 { + i = encodeVarintWakuFilterV2(dAtA, i, uint64(m.StatusCode)) + i-- + dAtA[i] = 0x50 + } + if len(m.RequestId) > 0 { + i -= len(m.RequestId) + copy(dAtA[i:], m.RequestId) + i = encodeVarintWakuFilterV2(dAtA, i, uint64(len(m.RequestId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MessagePushV2) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MessagePushV2) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MessagePushV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.XXX_unrecognized != nil { + i -= len(m.XXX_unrecognized) + copy(dAtA[i:], m.XXX_unrecognized) + } + if len(m.PubsubTopic) > 0 { + i -= len(m.PubsubTopic) + copy(dAtA[i:], m.PubsubTopic) + i = encodeVarintWakuFilterV2(dAtA, i, uint64(len(m.PubsubTopic))) + i-- + dAtA[i] = 0x12 + } + if m.WakuMessage != nil { + { + size, err := m.WakuMessage.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintWakuFilterV2(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintWakuFilterV2(dAtA []byte, offset int, v uint64) int { + offset -= sovWakuFilterV2(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *FilterSubscribeRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.RequestId) + if l > 0 { + n += 1 + l + sovWakuFilterV2(uint64(l)) + } + if m.FilterSubscribeType != 0 { + n += 1 + sovWakuFilterV2(uint64(m.FilterSubscribeType)) + } + l = len(m.PubsubTopic) + if l > 0 { + n += 1 + l + sovWakuFilterV2(uint64(l)) + } + if len(m.ContentTopics) > 0 { + for _, s := range m.ContentTopics { + l = len(s) + n += 1 + l + sovWakuFilterV2(uint64(l)) + } + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *FilterSubscribeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.RequestId) + if l > 0 { + n += 1 + l + sovWakuFilterV2(uint64(l)) + } + if m.StatusCode != 0 { + n += 1 + sovWakuFilterV2(uint64(m.StatusCode)) + } + l = len(m.StatusDesc) + if l > 0 { + n += 1 + l + sovWakuFilterV2(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func (m *MessagePushV2) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.WakuMessage != nil { + l = m.WakuMessage.Size() + n += 1 + l + sovWakuFilterV2(uint64(l)) + } + l = len(m.PubsubTopic) + if l > 0 { + n += 1 + l + sovWakuFilterV2(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + +func sovWakuFilterV2(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozWakuFilterV2(x uint64) (n int) { + return sovWakuFilterV2(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *FilterSubscribeRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: FilterSubscribeRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FilterSubscribeRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RequestId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWakuFilterV2 + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RequestId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FilterSubscribeType", wireType) + } + m.FilterSubscribeType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FilterSubscribeType |= FilterSubscribeRequest_FilterSubscribeType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubsubTopic", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWakuFilterV2 + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PubsubTopic = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContentTopics", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWakuFilterV2 + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContentTopics = append(m.ContentTopics, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipWakuFilterV2(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *FilterSubscribeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: FilterSubscribeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FilterSubscribeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RequestId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWakuFilterV2 + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RequestId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StatusCode", wireType) + } + m.StatusCode = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StatusCode |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StatusDesc", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWakuFilterV2 + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StatusDesc = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipWakuFilterV2(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MessagePushV2) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MessagePushV2: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MessagePushV2: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WakuMessage", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthWakuFilterV2 + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.WakuMessage == nil { + m.WakuMessage = &WakuMessage{} + } + if err := m.WakuMessage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubsubTopic", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthWakuFilterV2 + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PubsubTopic = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipWakuFilterV2(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthWakuFilterV2 + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipWakuFilterV2(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowWakuFilterV2 + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthWakuFilterV2 + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupWakuFilterV2 + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthWakuFilterV2 + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthWakuFilterV2 = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowWakuFilterV2 = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupWakuFilterV2 = fmt.Errorf("proto: unexpected end of group") +) diff --git a/waku/v2/protocol/pb/waku_filter_v2.proto b/waku/v2/protocol/pb/waku_filter_v2.proto new file mode 100644 index 00000000..f27d65af --- /dev/null +++ b/waku/v2/protocol/pb/waku_filter_v2.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +// 12/WAKU2-FILTER rfc: https://rfc.vac.dev/spec/12/ +package pb; + +import "waku_message.proto"; + + +// Protocol identifier: /vac/waku/filter-subscribe/2.0.0-beta1 +message FilterSubscribeRequest { + enum FilterSubscribeType { + SUBSCRIBER_PING = 0; + SUBSCRIBE = 1; + UNSUBSCRIBE = 2; + UNSUBSCRIBE_ALL = 3; + } + + string request_id = 1; + FilterSubscribeType filter_subscribe_type = 2; + + // Filter criteria + string pubsub_topic = 10; + repeated string content_topics = 11; +} + +message FilterSubscribeResponse { + string request_id = 1; + uint32 status_code = 10; + string status_desc = 11; +} + +// Protocol identifier: /vac/waku/filter-push/2.0.0-beta1 +message MessagePushV2 { + WakuMessage waku_message = 1; + string pubsub_topic = 2; +} \ No newline at end of file