mirror of https://github.com/status-im/go-waku.git
feat: Add support for multiple protocol IDs (#34)
This commit is contained in:
parent
748e738d9a
commit
c3ac5ef9c5
|
@ -950,6 +950,8 @@ github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5 h1
|
|||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f h1:/KXMnxtAe0ZrbErvgZPkKilpLCmd7g1CIKQ4x17Al5I=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4 h1:LaoaRVhtEu5kCzcEVn+l3sprDbTqpzWFsVT2lmAcHcA=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
|
||||
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw=
|
||||
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
|
||||
|
|
2
go.mod
2
go.mod
|
@ -29,7 +29,7 @@ require (
|
|||
github.com/spf13/cobra v1.1.3
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/viper v1.7.1
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4
|
||||
go.opencensus.io v0.23.0
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -838,6 +838,10 @@ github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5 h1
|
|||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210629085338-e9c89c8f00f5/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f h1:/KXMnxtAe0ZrbErvgZPkKilpLCmd7g1CIKQ4x17Al5I=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210711180556-9afd35dadd3f/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721190623-e23032977d88 h1:z8s92pjvJVGL+LonCwyHZNs5YuMpTMFn2Svhu7r81x4=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721190623-e23032977d88/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4 h1:LaoaRVhtEu5kCzcEVn+l3sprDbTqpzWFsVT2lmAcHcA=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.3-0.20210721191549-83c6a2c077f4/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/status-go/extkeys v1.0.0/go.mod h1:GdqJbrcpkNm5ZsSCpp+PdMxnXx+OcRBdm3PI0rs1FpU=
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
|
|
|
@ -199,7 +199,7 @@ func NewWakuFilter(ctx context.Context, host host.Host, handler MessagePushHandl
|
|||
wf.pushHandler = handler
|
||||
wf.peerChan = peerChan
|
||||
|
||||
wf.h.SetStreamHandler(WakuFilterProtocolId, wf.onRequest)
|
||||
wf.h.SetStreamHandlerMatch(WakuFilterProtocolId, protocol.PrefixTextMatch(WakuFilterCodec), wf.onRequest)
|
||||
go wf.FilterListener()
|
||||
go wf.peerListener()
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@ import (
|
|||
|
||||
var log = logging.Logger("waku_lightpush")
|
||||
|
||||
const WakuLightPushProtocolId = libp2pProtocol.ID("/vac/waku/lightpush/2.0.0-beta1")
|
||||
const WakuLightPushCodec = "/vac/waku/lightpush/2.0.0-beta1"
|
||||
const WakuLightPushProtocolId = libp2pProtocol.ID(WakuLightPushCodec)
|
||||
|
||||
var (
|
||||
ErrNoPeersAvailable = errors.New("no suitable remote peers")
|
||||
|
@ -39,7 +40,7 @@ func NewWakuLightPush(ctx context.Context, h host.Host, relay *relay.WakuRelay)
|
|||
wakuLP.ctx = ctx
|
||||
wakuLP.h = h
|
||||
|
||||
wakuLP.h.SetStreamHandler(WakuLightPushProtocolId, wakuLP.onRequest)
|
||||
wakuLP.h.SetStreamHandlerMatch(WakuLightPushProtocolId, protocol.PrefixTextMatch(WakuLightPushCodec), wakuLP.onRequest)
|
||||
log.Info("Light Push protocol started")
|
||||
|
||||
return wakuLP
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
logging "github.com/ipfs/go-log"
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
|
||||
"github.com/status-im/go-waku/waku/v2/protocol"
|
||||
"github.com/status-im/go-waku/waku/v2/protocol/pb"
|
||||
wakurelay "github.com/status-im/go-wakurelay-pubsub"
|
||||
)
|
||||
|
@ -36,7 +37,7 @@ func NewWakuRelay(ctx context.Context, h host.Host, opts ...wakurelay.Option) (*
|
|||
w.wakuRelayTopics = make(map[Topic]*wakurelay.Topic)
|
||||
w.relaySubs = make(map[Topic]*wakurelay.Subscription)
|
||||
|
||||
ps, err := wakurelay.NewWakuRelaySub(ctx, h, opts...)
|
||||
ps, err := wakurelay.NewWakuRelaySubWithMatcherFunc(ctx, h, protocol.PrefixTextMatch(string(wakurelay.WakuRelayID_v200)), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ import (
|
|||
|
||||
var log = logging.Logger("wakustore")
|
||||
|
||||
const WakuStoreProtocolId = libp2pProtocol.ID("/vac/waku/store/2.0.0-beta3")
|
||||
const WakuStoreCodec = "/vac/waku/store/2.0.0-beta3"
|
||||
const WakuStoreProtocolId = libp2pProtocol.ID(WakuStoreCodec)
|
||||
const MaxPageSize = 100 // Maximum number of waku messages in each page
|
||||
const DefaultContentTopic = "/waku/2/default-content/proto"
|
||||
|
||||
|
@ -247,7 +248,7 @@ func (store *WakuStore) Start(ctx context.Context, h host.Host, peerChan chan *e
|
|||
return
|
||||
}
|
||||
|
||||
store.h.SetStreamHandler(WakuStoreProtocolId, store.onRequest)
|
||||
store.h.SetStreamHandlerMatch(WakuStoreProtocolId, protocol.PrefixTextMatch(WakuStoreCodec), store.onRequest)
|
||||
|
||||
go store.storeIncomingMessages(ctx)
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package protocol
|
||||
|
||||
import "strings"
|
||||
|
||||
func FulltextMatch(expectedProtocol string) func(string) bool {
|
||||
return func(receivedProtocol string) bool {
|
||||
return receivedProtocol == expectedProtocol
|
||||
}
|
||||
}
|
||||
|
||||
func PrefixTextMatch(prefix string) func(string) bool {
|
||||
return func(receivedProtocol string) bool {
|
||||
return strings.HasPrefix(receivedProtocol, prefix)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue