mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-14 15:54:20 +00:00
Add option to enable lightpush protocol
This commit is contained in:
parent
3d8aae5b81
commit
9138d58152
@ -95,6 +95,10 @@ func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if params.enableLightPush {
|
||||||
|
w.mountLightPush()
|
||||||
|
}
|
||||||
|
|
||||||
for _, addr := range w.ListenAddresses() {
|
for _, addr := range w.ListenAddresses() {
|
||||||
log.Info("Listening on ", addr)
|
log.Info("Listening on ", addr)
|
||||||
}
|
}
|
||||||
@ -147,6 +151,10 @@ func (w *WakuNode) mountRelay(opts ...wakurelay.Option) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WakuNode) mountLightPush() {
|
||||||
|
w.lightPush = lightpush.NewWakuLightPush(w.ctx, w.host, w.relay)
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WakuNode) startStore() error {
|
func (w *WakuNode) startStore() error {
|
||||||
_, err := w.Subscribe(nil)
|
_, err := w.Subscribe(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,6 +24,8 @@ type WakuNodeParameters struct {
|
|||||||
enableStore bool
|
enableStore bool
|
||||||
storeMsgs bool
|
storeMsgs bool
|
||||||
store *store.WakuStore
|
store *store.WakuStore
|
||||||
|
|
||||||
|
enableLightPush bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type WakuNodeOption func(*WakuNodeParameters) error
|
type WakuNodeOption func(*WakuNodeParameters) error
|
||||||
@ -107,6 +109,14 @@ func WithMessageProvider(s store.MessageProvider) WakuNodeOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLightPush is a WakuNodeOption that enables the lightpush protocol
|
||||||
|
func WithLightPush() WakuNodeOption {
|
||||||
|
return func(params *WakuNodeParameters) error {
|
||||||
|
params.enableLightPush = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Default options used in the libp2p node
|
// Default options used in the libp2p node
|
||||||
var DefaultLibP2POptions = []libp2p.Option{
|
var DefaultLibP2POptions = []libp2p.Option{
|
||||||
libp2p.DefaultTransports,
|
libp2p.DefaultTransports,
|
||||||
|
@ -36,17 +36,16 @@ type WakuLightPush struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWakuLightPush(ctx context.Context, relay *relay.WakuRelay) *WakuLightPush {
|
func NewWakuLightPush(ctx context.Context, h host.Host, relay *relay.WakuRelay) *WakuLightPush {
|
||||||
wakuLP := new(WakuLightPush)
|
wakuLP := new(WakuLightPush)
|
||||||
wakuLP.relay = relay
|
wakuLP.relay = relay
|
||||||
wakuLP.ctx = ctx
|
wakuLP.ctx = ctx
|
||||||
return wakuLP
|
|
||||||
}
|
|
||||||
|
|
||||||
func (wakuLP *WakuLightPush) Start(h host.Host) {
|
|
||||||
wakuLP.h = h
|
wakuLP.h = h
|
||||||
|
|
||||||
wakuLP.h.SetStreamHandler(WakuLightPushProtocolId, wakuLP.onRequest)
|
wakuLP.h.SetStreamHandler(WakuLightPushProtocolId, wakuLP.onRequest)
|
||||||
log.Info("Light Push protocol started")
|
log.Info("Light Push protocol started")
|
||||||
|
|
||||||
|
return wakuLP
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wakuLP *WakuLightPush) onRequest(s network.Stream) {
|
func (wakuLP *WakuLightPush) onRequest(s network.Stream) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user