mirror of https://github.com/status-im/go-waku.git
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() {
|
||||
log.Info("Listening on ", addr)
|
||||
}
|
||||
|
@ -147,6 +151,10 @@ func (w *WakuNode) mountRelay(opts ...wakurelay.Option) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (w *WakuNode) mountLightPush() {
|
||||
w.lightPush = lightpush.NewWakuLightPush(w.ctx, w.host, w.relay)
|
||||
}
|
||||
|
||||
func (w *WakuNode) startStore() error {
|
||||
_, err := w.Subscribe(nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -24,6 +24,8 @@ type WakuNodeParameters struct {
|
|||
enableStore bool
|
||||
storeMsgs bool
|
||||
store *store.WakuStore
|
||||
|
||||
enableLightPush bool
|
||||
}
|
||||
|
||||
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
|
||||
var DefaultLibP2POptions = []libp2p.Option{
|
||||
libp2p.DefaultTransports,
|
||||
|
|
|
@ -36,17 +36,16 @@ type WakuLightPush struct {
|
|||
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.relay = relay
|
||||
wakuLP.ctx = ctx
|
||||
return wakuLP
|
||||
}
|
||||
|
||||
func (wakuLP *WakuLightPush) Start(h host.Host) {
|
||||
wakuLP.h = h
|
||||
|
||||
wakuLP.h.SetStreamHandler(WakuLightPushProtocolId, wakuLP.onRequest)
|
||||
log.Info("Light Push protocol started")
|
||||
|
||||
return wakuLP
|
||||
}
|
||||
|
||||
func (wakuLP *WakuLightPush) onRequest(s network.Stream) {
|
||||
|
|
Loading…
Reference in New Issue