mirror of https://github.com/status-im/go-waku.git
fix: content topic usage on the examples
This commit is contained in:
parent
f9179cd116
commit
e66f0e3b9c
|
@ -21,9 +21,15 @@ 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() {
|
||||||
|
var cTopic, err = protocol.NewContentTopic("basic2", 1, "test", "proto")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Invalid contentTopic")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
contentTopic := cTopic.String()
|
||||||
|
|
||||||
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
||||||
key, err := randomHex(32)
|
key, err := randomHex(32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -54,8 +60,8 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go writeLoop(ctx, wakuNode)
|
go writeLoop(ctx, wakuNode, contentTopic)
|
||||||
go readLoop(ctx, wakuNode)
|
go readLoop(ctx, wakuNode, contentTopic)
|
||||||
|
|
||||||
// Wait for a SIGINT or SIGTERM signal
|
// Wait for a SIGINT or SIGTERM signal
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
|
@ -76,7 +82,7 @@ func randomHex(n int) (string, error) {
|
||||||
return hex.EncodeToString(bytes), nil
|
return hex.EncodeToString(bytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
|
func write(ctx context.Context, wakuNode *node.WakuNode, contentTopic string, msgContent string) {
|
||||||
var version uint32 = 0
|
var version uint32 = 0
|
||||||
var timestamp int64 = utils.GetUnixEpoch(wakuNode.Timesource())
|
var timestamp int64 = utils.GetUnixEpoch(wakuNode.Timesource())
|
||||||
|
|
||||||
|
@ -103,14 +109,14 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeLoop(ctx context.Context, wakuNode *node.WakuNode) {
|
func writeLoop(ctx context.Context, wakuNode *node.WakuNode, contentTopic string) {
|
||||||
for {
|
for {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
write(ctx, wakuNode, "Hello world!")
|
write(ctx, wakuNode, contentTopic, "Hello world!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readLoop(ctx context.Context, wakuNode *node.WakuNode) {
|
func readLoop(ctx context.Context, wakuNode *node.WakuNode, contentTopic string) {
|
||||||
sub, err := wakuNode.Relay().Subscribe(ctx)
|
sub, err := wakuNode.Relay().Subscribe(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not subscribe", zap.Error(err))
|
log.Error("Could not subscribe", zap.Error(err))
|
||||||
|
|
|
@ -34,7 +34,12 @@ func getFlags() []cli.Flag {
|
||||||
// Defaults
|
// Defaults
|
||||||
options.Fleet = fleetProd
|
options.Fleet = fleetProd
|
||||||
|
|
||||||
testnetContentTopic := protocol.NewContentTopic("toy-chat", 3, "mingde", "proto").String()
|
testCT, err := protocol.NewContentTopic("toy-chat", 3, "mingde", "proto")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Invalid contentTopic")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
testnetContentTopic := testCT.String()
|
||||||
|
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.GenericFlag{
|
&cli.GenericFlag{
|
||||||
|
|
Loading…
Reference in New Issue