mirror of https://github.com/status-im/go-waku.git
fix: basic2 example
This commit is contained in:
parent
c55a979af4
commit
2f009cb69f
|
@ -21,6 +21,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = utils.Logger().Named("basic2")
|
var log = utils.Logger().Named("basic2")
|
||||||
|
var contentTopic = protocol.NewContentTopic("basic2", 1, "test", "proto").String()
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
||||||
|
@ -76,8 +77,6 @@ func randomHex(n int) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
|
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
|
||||||
contentTopic := protocol.NewContentTopic("basic2", 1, "test", "proto")
|
|
||||||
|
|
||||||
var version uint32 = 0
|
var version uint32 = 0
|
||||||
var timestamp int64 = utils.GetUnixEpoch(wakuNode.Timesource())
|
var timestamp int64 = utils.GetUnixEpoch(wakuNode.Timesource())
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
|
||||||
msg := &pb.WakuMessage{
|
msg := &pb.WakuMessage{
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
Version: version,
|
Version: version,
|
||||||
ContentTopic: contentTopic.String(),
|
ContentTopic: contentTopic,
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +117,15 @@ func readLoop(ctx context.Context, wakuNode *node.WakuNode) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for value := range sub.C {
|
for envelope := range sub.C {
|
||||||
payload, err := payload.DecodePayload(value.Message(), &payload.KeyInfo{Kind: payload.None})
|
if envelope.Message().ContentTopic != contentTopic {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, err := payload.DecodePayload(envelope.Message(), &payload.KeyInfo{Kind: payload.None})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Error("Error decoding payload", zap.Error(err))
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Received msg, ", zap.String("data", string(payload.Data)))
|
log.Info("Received msg, ", zap.String("data", string(payload.Data)))
|
||||||
|
|
Loading…
Reference in New Issue