@@ -17,6 +17,7 @@ import { Multiaddr, multiaddr } from "multiaddr";
1717import PeerId from "peer-id" ;
1818
1919import { Bootstrap , BootstrapOptions } from "./discovery" ;
20+ import { FilterCodec , WakuFilter } from "./waku_filter" ;
2021import { LightPushCodec , WakuLightPush } from "./waku_light_push" ;
2122import { DecryptionMethod , WakuMessage } from "./waku_message" ;
2223import { RelayCodecs , WakuRelay } from "./waku_relay" ;
@@ -39,6 +40,7 @@ export enum Protocols {
3940 Relay = "relay" ,
4041 Store = "store" ,
4142 LightPush = "lightpush" ,
43+ Filter = "filter" ,
4244}
4345
4446export interface CreateOptions {
@@ -102,6 +104,7 @@ export class Waku {
102104 public libp2p : Libp2p ;
103105 public relay : WakuRelay ;
104106 public store : WakuStore ;
107+ public filter : WakuFilter ;
105108 public lightPush : WakuLightPush ;
106109
107110 private pingKeepAliveTimers : {
@@ -115,11 +118,13 @@ export class Waku {
115118 options : CreateOptions ,
116119 libp2p : Libp2p ,
117120 store : WakuStore ,
118- lightPush : WakuLightPush
121+ lightPush : WakuLightPush ,
122+ filter : WakuFilter
119123 ) {
120124 this . libp2p = libp2p ;
121125 this . relay = libp2p . pubsub as unknown as WakuRelay ;
122126 this . store = store ;
127+ this . filter = filter ;
123128 this . lightPush = lightPush ;
124129 this . pingKeepAliveTimers = { } ;
125130 this . relayKeepAliveTimers = { } ;
@@ -220,10 +225,17 @@ export class Waku {
220225 pubSubTopic : options ?. pubSubTopic ,
221226 } ) ;
222227 const wakuLightPush = new WakuLightPush ( libp2p ) ;
228+ const wakuFilter = new WakuFilter ( libp2p ) ;
223229
224230 await libp2p . start ( ) ;
225231
226- return new Waku ( options ? options : { } , libp2p , wakuStore , wakuLightPush ) ;
232+ return new Waku (
233+ options ? options : { } ,
234+ libp2p ,
235+ wakuStore ,
236+ wakuLightPush ,
237+ wakuFilter
238+ ) ;
227239 }
228240
229241 /**
@@ -253,6 +265,9 @@ export class Waku {
253265 if ( _protocols . includes ( Protocols . LightPush ) ) {
254266 codecs . push ( LightPushCodec ) ;
255267 }
268+ if ( _protocols . includes ( Protocols . Filter ) ) {
269+ codecs . push ( FilterCodec ) ;
270+ }
256271
257272 return this . libp2p . dialProtocol ( peer , codecs ) ;
258273 }
@@ -297,6 +312,7 @@ export class Waku {
297312 ) : void {
298313 this . relay . addDecryptionKey ( key , options ) ;
299314 this . store . addDecryptionKey ( key , options ) ;
315+ this . filter . addDecryptionKey ( key , options ) ;
300316 }
301317
302318 /**
@@ -308,6 +324,7 @@ export class Waku {
308324 deleteDecryptionKey ( key : Uint8Array | string ) : void {
309325 this . relay . deleteDecryptionKey ( key ) ;
310326 this . store . deleteDecryptionKey ( key ) ;
327+ this . filter . deleteDecryptionKey ( key ) ;
311328 }
312329
313330 /**
@@ -381,6 +398,16 @@ export class Waku {
381398 promises . push ( lightPushPromise ) ;
382399 }
383400
401+ if ( protocols . includes ( Protocols . Filter ) ) {
402+ const filterPromise = ( async ( ) : Promise < void > => {
403+ for await ( const peer of this . filter . peers ) {
404+ dbg ( "Filter peer found" , peer . id . toB58String ( ) ) ;
405+ break ;
406+ }
407+ } ) ( ) ;
408+ promises . push ( filterPromise ) ;
409+ }
410+
384411 if ( timeoutMs ) {
385412 await rejectOnTimeout (
386413 Promise . all ( promises ) ,
0 commit comments