Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rest/store): allow local queries #1088

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/waku/server/rest/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions waku/v2/protocol/lightpush/waku_lightpush.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions waku/v2/protocol/store/waku_store_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions waku/v2/protocol/store/waku_store_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions waku/v2/protocol/store/waku_store_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading