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

Adding store files #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions waku/nwaku_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/cenkalti/backoff/v3"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
"github.com/waku-org/waku-go-bindings/waku/common"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -215,3 +216,42 @@ func SubscribeNodesToTopic(nodes []*WakuNode, topic string) error {
}
return nil
}

func (n *WakuNode) GetStoredMessages(storeNode *WakuNode, storeRequest *common.StoreQueryRequest) (*common.StoreQueryResponse, error) {
Debug("Starting store query request")

if storeRequest == nil {
Debug("Using DefaultStoreQueryRequest")
storeRequest = &DefaultStoreQueryRequest
}

storeMultiaddr, err := storeNode.ListenAddresses()
if err != nil {
Error("Failed to retrieve listen addresses for store node: %v", err)
return nil, err
}

if len(storeMultiaddr) == 0 {
Error("Store node has no available listen addresses")
return nil, fmt.Errorf("store node has no available listen addresses")
}

storeNodeAddrInfo, err := peer.AddrInfoFromString(storeMultiaddr[0].String())
if err != nil {
Error("Failed to convert store node address to AddrInfo: %v", err)
return nil, err
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

Debug("Querying store node for messages")
res, err := n.StoreQuery(ctx, storeRequest, *storeNodeAddrInfo)
if err != nil {
Error("StoreQuery failed: %v", err)
return nil, err
}

Debug("Store query successful, retrieved %d messages", len(*res.Messages))
return res, nil
}
Loading