mirror of
https://github.com/status-im/status-go.git
synced 2025-02-01 17:38:36 +00:00
a3bff47800
- 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
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
//go:build use_nwaku
|
|
// +build use_nwaku
|
|
|
|
package wakuv2
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
commonapi "github.com/waku-org/go-waku/waku/v2/api/common"
|
|
"github.com/waku-org/go-waku/waku/v2/protocol"
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
|
storepb "github.com/waku-org/go-waku/waku/v2/protocol/store/pb"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type storenodeRequestor struct {
|
|
node *WakuNode
|
|
logger *zap.Logger
|
|
}
|
|
|
|
func newStorenodeRequestor(node *WakuNode, logger *zap.Logger) commonapi.StorenodeRequestor {
|
|
return &storenodeRequestor{
|
|
node: node,
|
|
logger: logger.Named("storenodeRequestor"),
|
|
}
|
|
}
|
|
|
|
func (s *storenodeRequestor) GetMessagesByHash(ctx context.Context, peerInfo peer.AddrInfo, pageSize uint64, messageHashes []pb.MessageHash) (commonapi.StoreRequestResult, error) {
|
|
requestIDStr := hex.EncodeToString(protocol.GenerateRequestID())
|
|
|
|
logger := s.logger.With(zap.Stringer("peerID", peerInfo.ID), zap.String("requestID", requestIDStr))
|
|
|
|
logger.Debug("sending store request")
|
|
|
|
storeRequest := &storepb.StoreQueryRequest{
|
|
RequestId: requestIDStr,
|
|
MessageHashes: make([][]byte, len(messageHashes)),
|
|
IncludeData: true,
|
|
PaginationCursor: nil,
|
|
PaginationForward: false,
|
|
PaginationLimit: proto.Uint64(pageSize),
|
|
}
|
|
|
|
for i, mhash := range messageHashes {
|
|
storeRequest.MessageHashes[i] = mhash.Bytes()
|
|
}
|
|
|
|
storeResponse, err := s.node.StoreQuery(ctx, storeRequest, peerInfo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if storeResponse.GetStatusCode() != http.StatusOK {
|
|
return nil, fmt.Errorf("could not query storenode: %s %d %s", requestIDStr, storeResponse.GetStatusCode(), storeResponse.GetStatusDesc())
|
|
}
|
|
|
|
return newStoreResultImpl(s.node, peerInfo, storeRequest, storeResponse), nil
|
|
}
|
|
|
|
func (s *storenodeRequestor) Query(ctx context.Context, peerInfo peer.AddrInfo, storeRequest *storepb.StoreQueryRequest) (commonapi.StoreRequestResult, error) {
|
|
storeResponse, err := s.node.StoreQuery(ctx, storeRequest, peerInfo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if storeResponse.GetStatusCode() != http.StatusOK {
|
|
return nil, fmt.Errorf("could not query storenode: %s %d %s", storeRequest.RequestId, storeResponse.GetStatusCode(), storeResponse.GetStatusDesc())
|
|
}
|
|
|
|
return newStoreResultImpl(s.node, peerInfo, storeRequest, storeResponse), nil
|
|
}
|