-
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
base: master
Are you sure you want to change the base?
Changes from 9 commits
3873229
1222d12
fc57ed9
7cc330f
50f1854
b1cebf2
26ae261
f9c54f0
be664cd
9dd3b09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package common | ||
|
||
import ( | ||
"encoding/hex" | ||
"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 "", fmt.Errorf("empty string not allowed") | ||
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. If no formatting is being used, you can use 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. Oooh good catch! It was either a copy-paste mistake, or it was written by AI and didn't notice that mistake - don't remember lol |
||
} | ||
|
||
if len(val) < 2 || val[:2] != "0x" { | ||
return "", fmt.Errorf("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)) | ||
} |
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"` | ||
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. Should it be 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. True! Forgot that it was optional. Updated it :) |
||
PaginationForward bool `json:"pagination_forward"` | ||
PaginationLimit *uint64 `json:"pagination_limit,omitempty"` | ||
} | ||
|
||
type StoreMessageResponse struct { | ||
WakuMessage tmpWakuMessageJson `json:"message"` | ||
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. The messages are optional and only included if 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. True! Changed it :) |
||
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"` | ||
} |
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) { | ||
|
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