diff --git a/cmd/waku/server/rest/store.go b/cmd/waku/server/rest/store.go index 8e8ac87b2..723acabfd 100644 --- a/cmd/waku/server/rest/store.go +++ b/cmd/waku/server/rest/store.go @@ -67,7 +67,13 @@ func getStoreParams(r *http.Request) (*store.Query, []store.HistoryRequestOption return nil, nil, err } options = append(options, store.WithPeerAddr(m)) + } else { + // The user didn't specify a peer address and self-node is configured as a store node. + // In this case we assume that the user is willing to retrieve the messages stored by + // the local/self store node. + options = append(options, store.WithLocalQuery()) } + query.PubsubTopic = r.URL.Query().Get("pubsubTopic") contentTopics := r.URL.Query().Get("contentTopics") diff --git a/waku/v2/protocol/lightpush/waku_lightpush.go b/waku/v2/protocol/lightpush/waku_lightpush.go index 00a2ca8ab..fe65ed047 100644 --- a/waku/v2/protocol/lightpush/waku_lightpush.go +++ b/waku/v2/protocol/lightpush/waku_lightpush.go @@ -63,10 +63,6 @@ func NewWakuLightPush(relay *relay.WakuRelay, pm *peermanager.PeerManager, reg p wakuLP.limiter = params.limiter - if pm != nil { - wakuLP.pm.RegisterWakuProtocol(LightPushID_v20beta1, LightPushENRField) - } - return wakuLP } @@ -81,6 +77,10 @@ func (wakuLP *WakuLightPush) Start(ctx context.Context) error { return errors.New("relay is required, without it, it is only a client and cannot be started") } + if wakuLP.pm != nil { + wakuLP.pm.RegisterWakuProtocol(LightPushID_v20beta1, LightPushENRField) + } + ctx, cancel := context.WithCancel(ctx) wakuLP.cancel = cancel diff --git a/waku/v2/protocol/store/waku_store_client.go b/waku/v2/protocol/store/waku_store_client.go index d66defbd3..f1612a1c6 100644 --- a/waku/v2/protocol/store/waku_store_client.go +++ b/waku/v2/protocol/store/waku_store_client.go @@ -275,6 +275,10 @@ func (store *WakuStore) localQuery(historyQuery *pb.HistoryRPC) (*pb.HistoryResp return historyResponseRPC.Response, nil } +func (store *WakuStore) isLocalQuery(p *HistoryRequestParameters) bool { + return p.localQuery && store.started +} + func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryRequestOption) (*Result, error) { params := new(HistoryRequestParameters) params.s = store @@ -288,7 +292,7 @@ func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryR } } - if !params.localQuery { + if !store.isLocalQuery(params) { pubsubTopics := []string{} if query.PubsubTopic == "" { for _, cTopic := range query.ContentTopics { @@ -343,7 +347,7 @@ func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryR historyRequest.Query.ContentFilters = append(historyRequest.Query.ContentFilters, &pb.ContentFilter{ContentTopic: cf}) } - if !params.localQuery && params.selectedPeer == "" { + if !store.isLocalQuery(params) && params.selectedPeer == "" { store.metrics.RecordError(peerNotFoundFailure) return nil, ErrNoPeersAvailable } @@ -373,7 +377,7 @@ func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryR var response *pb.HistoryResponse - if params.localQuery { + if store.isLocalQuery(params) { response, err = store.localQuery(historyRequest) } else { response, err = store.queryFrom(ctx, historyRequest, params.selectedPeer) diff --git a/waku/v2/protocol/store/waku_store_common.go b/waku/v2/protocol/store/waku_store_common.go index 82e369cfd..929e58e1f 100644 --- a/waku/v2/protocol/store/waku_store_common.go +++ b/waku/v2/protocol/store/waku_store_common.go @@ -67,8 +67,5 @@ func NewWakuStore(p MessageProvider, pm *peermanager.PeerManager, timesource tim wakuStore.pm = pm wakuStore.metrics = newMetrics(reg) - if pm != nil { - pm.RegisterWakuProtocol(StoreID_v20beta4, StoreENRField) - } return wakuStore } diff --git a/waku/v2/protocol/store/waku_store_protocol.go b/waku/v2/protocol/store/waku_store_protocol.go index 76e3983fe..e40abe7ef 100644 --- a/waku/v2/protocol/store/waku_store_protocol.go +++ b/waku/v2/protocol/store/waku_store_protocol.go @@ -119,6 +119,10 @@ func (store *WakuStore) Start(ctx context.Context, sub *relay.Subscription) erro return err } + if store.pm != nil { + store.pm.RegisterWakuProtocol(StoreID_v20beta4, StoreENRField) + } + store.started = true store.ctx, store.cancel = context.WithCancel(ctx) store.MsgC = sub