-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: using msg hash in hex and adding store test #16
Open
gabrielmer
wants to merge
10
commits into
master
Choose a base branch
from
chore-using-msg-hash-in-hex
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3873229
initial changes
gabrielmer 1222d12
adding sample test
gabrielmer fc57ed9
checkpoint
gabrielmer 7cc330f
making struct public
gabrielmer 50f1854
improving test
gabrielmer b1cebf2
improving store test
gabrielmer 26ae261
renaming test
gabrielmer f9c54f0
improving types
gabrielmer be664cd
removing debug logs
gabrielmer 9dd3b09
applying feedback
gabrielmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package common | ||
|
||
import ( | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// MessageHash represents an unique identifier for a message within a pubsub topic | ||
type MessageHash string | ||
|
||
func ToMessageHash(val string) (MessageHash, error) { | ||
if len(val) == 0 { | ||
return "", errors.New("empty string not allowed") | ||
} | ||
|
||
if len(val) < 2 || val[:2] != "0x" { | ||
return "", errors.New("string must start with 0x") | ||
} | ||
|
||
// Remove "0x" prefix for hex decoding | ||
hexStr := val[2:] | ||
|
||
// Verify the remaining string is valid hex | ||
_, err := hex.DecodeString(hexStr) | ||
if err != nil { | ||
return "", fmt.Errorf("invalid hex string: %v", err) | ||
} | ||
|
||
return MessageHash(val), nil | ||
} | ||
|
||
func (h MessageHash) String() string { | ||
return string(h) | ||
} | ||
|
||
func (h MessageHash) Bytes() ([]byte, error) { | ||
return hex.DecodeString(string(h)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package common | ||
|
||
type StoreQueryRequest struct { | ||
RequestId string `json:"request_id"` | ||
IncludeData bool `json:"include_data"` | ||
PubsubTopic string `json:"pubsub_topic,omitempty"` | ||
ContentTopics *[]string `json:"content_topics,omitempty"` | ||
TimeStart *int64 `json:"time_start,omitempty"` | ||
TimeEnd *int64 `json:"time_end,omitempty"` | ||
MessageHashes *[]MessageHash `json:"message_hashes,omitempty"` | ||
PaginationCursor *MessageHash `json:"pagination_cursor,omitempty"` | ||
PaginationForward bool `json:"pagination_forward"` | ||
PaginationLimit *uint64 `json:"pagination_limit,omitempty"` | ||
} | ||
|
||
type StoreMessageResponse struct { | ||
WakuMessage *tmpWakuMessageJson `json:"message"` | ||
PubsubTopic string `json:"pubsubTopic"` | ||
MessageHash MessageHash `json:"messageHash"` | ||
} | ||
|
||
type StoreQueryResponse struct { | ||
RequestId string `json:"requestId,omitempty"` | ||
StatusCode *uint32 `json:"statusCode,omitempty"` | ||
StatusDesc string `json:"statusDesc,omitempty"` | ||
Messages *[]StoreMessageResponse `json:"messages,omitempty"` | ||
PaginationCursor MessageHash `json:"paginationCursor,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,15 +323,13 @@ import ( | |
"time" | ||
"unsafe" | ||
|
||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/p2p/enode" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
libp2pproto "github.com/libp2p/go-libp2p/core/protocol" | ||
"github.com/multiformats/go-multiaddr" | ||
"github.com/waku-org/go-waku/waku/v2/protocol/pb" | ||
storepb "github.com/waku-org/go-waku/waku/v2/protocol/store/pb" | ||
"github.com/waku-org/go-waku/waku/v2/utils" | ||
"github.com/waku-org/waku-go-bindings/waku/common" | ||
"go.uber.org/zap" | ||
|
@@ -347,6 +345,7 @@ type WakuConfig struct { | |
Nodekey string `json:"nodekey,omitempty"` | ||
Relay bool `json:"relay,omitempty"` | ||
Store bool `json:"store,omitempty"` | ||
LegacyStore bool `json:"legacyStore"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I didn't add the |
||
Storenode string `json:"storenode,omitempty"` | ||
StoreMessageRetentionPolicy string `json:"storeMessageRetentionPolicy,omitempty"` | ||
StoreMessageDbUrl string `json:"storeMessageDbUrl,omitempty"` | ||
|
@@ -827,7 +826,7 @@ func (n *WakuNode) Version() (string, error) { | |
return "", errors.New(errMsg) | ||
} | ||
|
||
func (n *WakuNode) StoreQuery(ctx context.Context, storeRequest *storepb.StoreQueryRequest, peerInfo peer.AddrInfo) (*storepb.StoreQueryResponse, error) { | ||
func (n *WakuNode) StoreQuery(ctx context.Context, storeRequest *common.StoreQueryRequest, peerInfo peer.AddrInfo) (*common.StoreQueryResponse, error) { | ||
timeoutMs := getContextTimeoutMilliseconds(ctx) | ||
|
||
b, err := json.Marshal(storeRequest) | ||
|
@@ -856,24 +855,24 @@ func (n *WakuNode) StoreQuery(ctx context.Context, storeRequest *storepb.StoreQu | |
|
||
if C.getRet(resp) == C.RET_OK { | ||
jsonResponseStr := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))) | ||
storeQueryResponse := &storepb.StoreQueryResponse{} | ||
err = json.Unmarshal([]byte(jsonResponseStr), storeQueryResponse) | ||
storeQueryResponse := common.StoreQueryResponse{} | ||
err = json.Unmarshal([]byte(jsonResponseStr), &storeQueryResponse) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return storeQueryResponse, nil | ||
return &storeQueryResponse, nil | ||
} | ||
errMsg := "error WakuStoreQuery: " + | ||
C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))) | ||
return nil, errors.New(errMsg) | ||
} | ||
|
||
func (n *WakuNode) RelayPublish(ctx context.Context, message *pb.WakuMessage, pubsubTopic string) (pb.MessageHash, error) { | ||
func (n *WakuNode) RelayPublish(ctx context.Context, message *pb.WakuMessage, pubsubTopic string) (common.MessageHash, error) { | ||
timeoutMs := getContextTimeoutMilliseconds(ctx) | ||
|
||
jsonMsg, err := json.Marshal(message) | ||
if err != nil { | ||
return pb.MessageHash{}, err | ||
return common.MessageHash(""), err | ||
} | ||
|
||
wg := sync.WaitGroup{} | ||
|
@@ -890,14 +889,14 @@ func (n *WakuNode) RelayPublish(ctx context.Context, message *pb.WakuMessage, pu | |
wg.Wait() | ||
if C.getRet(resp) == C.RET_OK { | ||
msgHash := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))) | ||
msgHashBytes, err := hexutil.Decode(msgHash) | ||
parsedMsgHash, err := common.ToMessageHash(msgHash) | ||
if err != nil { | ||
return pb.MessageHash{}, err | ||
return common.MessageHash(""), err | ||
} | ||
return pb.ToMessageHash(msgHashBytes), nil | ||
return parsedMsgHash, nil | ||
} | ||
errMsg := "WakuRelayPublish: " + C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))) | ||
return pb.MessageHash{}, errors.New(errMsg) | ||
return common.MessageHash(""), errors.New(errMsg) | ||
} | ||
|
||
func (n *WakuNode) DnsDiscovery(ctx context.Context, enrTreeUrl string, nameDnsServer string) ([]multiaddr.Multiaddr, error) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not strictly correct. A message hash is
array[byte, 32]
I'd happier if we rename it a little ;P