status-go/wakuv2/result.go
Ivan Folgueira Bande a3bff47800
refactor_: start using nwaku
- some minor progress to add nwaku in status-go
- nwaku.go: GetNumConnectedPeers controls when passed pubsub is empty
- waku_test.go: adapt TestWakuV2Store
- add missing shard.go
- feat_: build nwaku with nix and use build tags to choose between go-waku and nwaku (#5896)
- chore_: update nwaku
- nwaku bump (#5911)
- bump: nwaku
- chore: add USE_NWAKU env flag
- fix: build libwaku only if needed
- feat: testing discovery and dialing with nwaku integration (#5940)
- message publisher and sent verifier (#5966)
- storenode requestor for missing message retrieval and result iterator impl (#5971)
- uncomment code that would allow status-go/go-waku to compile and libwaku test to run (#5986)
- supporting peer exchange with nwaku (#5983)
- store queries
- ping
- ping storenodes using AddrInfo (#6004)
- dial, drop and retrieve connected peers  (#6013)
- integrate on-demand DNS discovery and implement discoverAndConnectPeers (#6017)
- extract libwaku calls into WakuNode struct (#6027)
- async nwaku
- remove nwaku process loop
- receive messages via relay (#6185)
- extract timeout from context
- use correct port field, get free ports and uncomment some functions (#6200)
- enable filter/lightpush/px and setup rate limits
- add protected topics
2024-12-18 15:25:39 -04:00

78 lines
1.9 KiB
Go

//go:build use_nwaku
// +build use_nwaku
package wakuv2
import (
"context"
"encoding/hex"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/waku-org/go-waku/waku/v2/protocol"
"github.com/waku-org/go-waku/waku/v2/protocol/store"
storepb "github.com/waku-org/go-waku/waku/v2/protocol/store/pb"
)
type storeResultImpl struct {
done bool
node *WakuNode
storeRequest *storepb.StoreQueryRequest
storeResponse *storepb.StoreQueryResponse
peerInfo peer.AddrInfo
}
func newStoreResultImpl(node *WakuNode, peerInfo peer.AddrInfo, storeRequest *storepb.StoreQueryRequest, storeResponse *storepb.StoreQueryResponse) *storeResultImpl {
return &storeResultImpl{
node: node,
storeRequest: storeRequest,
storeResponse: storeResponse,
peerInfo: peerInfo,
}
}
func (r *storeResultImpl) Cursor() []byte {
return r.storeResponse.GetPaginationCursor()
}
func (r *storeResultImpl) IsComplete() bool {
return r.done
}
func (r *storeResultImpl) PeerID() peer.ID {
return r.peerInfo.ID
}
func (r *storeResultImpl) Query() *storepb.StoreQueryRequest {
return r.storeRequest
}
func (r *storeResultImpl) Response() *storepb.StoreQueryResponse {
return r.storeResponse
}
func (r *storeResultImpl) Next(ctx context.Context, opts ...store.RequestOption) error {
// TODO: opts is being ignored. Will require some changes in go-waku. For now using this
// is not necessary
if r.storeResponse.GetPaginationCursor() == nil {
r.done = true
return nil
}
r.storeRequest.RequestId = hex.EncodeToString(protocol.GenerateRequestID())
r.storeRequest.PaginationCursor = r.storeResponse.PaginationCursor
storeResponse, err := r.node.StoreQuery(ctx, r.storeRequest, r.peerInfo)
if err != nil {
return err
}
r.storeResponse = storeResponse
return nil
}
func (r *storeResultImpl) Messages() []*storepb.WakuMessageKeyValue {
return r.storeResponse.GetMessages()
}