mirror of
https://github.com/status-im/go-nwaku.git
synced 2025-02-22 10:08:09 +00:00
bump go-waku version and use context on publish
This commit is contained in:
parent
9138d58152
commit
1c4555ab32
@ -5,5 +5,5 @@ go 1.15
|
||||
require (
|
||||
github.com/ethereum/go-ethereum v1.9.5
|
||||
github.com/ipfs/go-log v1.0.5
|
||||
github.com/status-im/go-waku v0.0.0-20210422204244-4a4d0c97eced
|
||||
github.com/status-im/go-waku v0.0.0-20210428201044-3d8aae5b81b9
|
||||
)
|
||||
|
@ -615,6 +615,8 @@ github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d h1:hfCilmm5iO2Wd
|
||||
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
|
||||
github.com/status-im/go-waku v0.0.0-20210422204244-4a4d0c97eced h1:pCGlprPn/ZpMn4Czdbe5fSe+4NY2HtghQoYB6s+uV2c=
|
||||
github.com/status-im/go-waku v0.0.0-20210422204244-4a4d0c97eced/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
|
||||
github.com/status-im/go-waku v0.0.0-20210428201044-3d8aae5b81b9 h1:UiikssgV7CbL2UIPrOFfFwfV08iWxy1yTE+DwzcTxnc=
|
||||
github.com/status-im/go-waku v0.0.0-20210428201044-3d8aae5b81b9/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.2 h1:F4UGcP80H0PGaeJ0mRMzA1Ux3DKYiyv/qu3bOR/efTg=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.2/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@ -43,7 +43,7 @@ func main() {
|
||||
node.WithWakuRelay(),
|
||||
)
|
||||
|
||||
go writeLoop(wakuNode)
|
||||
go writeLoop(ctx, wakuNode)
|
||||
go readLoop(wakuNode)
|
||||
|
||||
// Wait for a SIGINT or SIGTERM signal
|
||||
@ -65,7 +65,7 @@ func randomHex(n int) (string, error) {
|
||||
return hex.EncodeToString(bytes), nil
|
||||
}
|
||||
|
||||
func write(wakuNode *node.WakuNode, msgContent string) {
|
||||
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) {
|
||||
var contentTopic string = "test"
|
||||
var version uint32 = 0
|
||||
var timestamp float64 = float64(time.Now().UnixNano())
|
||||
@ -83,16 +83,16 @@ func write(wakuNode *node.WakuNode, msgContent string) {
|
||||
Timestamp: timestamp,
|
||||
}
|
||||
|
||||
_, err = wakuNode.Publish(msg, nil)
|
||||
_, err = wakuNode.Publish(ctx, msg, nil)
|
||||
if err != nil {
|
||||
log.Error("Error sending a message: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func writeLoop(wakuNode *node.WakuNode) {
|
||||
func writeLoop(ctx context.Context, wakuNode *node.WakuNode) {
|
||||
for {
|
||||
time.Sleep(2 * time.Second)
|
||||
write(wakuNode, "Hello world!")
|
||||
write(ctx, wakuNode, "Hello world!")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"chat2/pb"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
@ -48,7 +49,7 @@ func NewChat(n *node.WakuNode, selfID peer.ID, nickname string) (*Chat, error) {
|
||||
}
|
||||
|
||||
// Publish sends a message to the pubsub topic.
|
||||
func (cr *Chat) Publish(message string) error {
|
||||
func (cr *Chat) Publish(ctx context.Context, message string) error {
|
||||
|
||||
msg := &pb.Chat2Message{
|
||||
Timestamp: uint64(time.Now().Unix()),
|
||||
@ -81,7 +82,7 @@ func (cr *Chat) Publish(message string) error {
|
||||
Timestamp: timestamp,
|
||||
}
|
||||
|
||||
_, err = cr.node.Publish(wakuMsg, nil)
|
||||
_, err = cr.node.Publish(ctx, wakuMsg, nil)
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ require (
|
||||
github.com/ipfs/go-log/v2 v2.1.1
|
||||
github.com/libp2p/go-libp2p-core v0.8.5
|
||||
github.com/rivo/tview v0.0.0-20210312174852-ae9464cc3598
|
||||
github.com/status-im/go-waku v0.0.0-20210422204244-4a4d0c97eced
|
||||
github.com/status-im/go-waku v0.0.0-20210428201044-3d8aae5b81b9
|
||||
google.golang.org/protobuf v1.25.0
|
||||
)
|
||||
|
@ -794,6 +794,8 @@ github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d h1:hfCilmm5iO2Wd
|
||||
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
|
||||
github.com/status-im/go-waku v0.0.0-20210422204244-4a4d0c97eced h1:pCGlprPn/ZpMn4Czdbe5fSe+4NY2HtghQoYB6s+uV2c=
|
||||
github.com/status-im/go-waku v0.0.0-20210422204244-4a4d0c97eced/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
|
||||
github.com/status-im/go-waku v0.0.0-20210428201044-3d8aae5b81b9 h1:UiikssgV7CbL2UIPrOFfFwfV08iWxy1yTE+DwzcTxnc=
|
||||
github.com/status-im/go-waku v0.0.0-20210428201044-3d8aae5b81b9/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.2 h1:F4UGcP80H0PGaeJ0mRMzA1Ux3DKYiyv/qu3bOR/efTg=
|
||||
github.com/status-im/go-wakurelay-pubsub v0.4.2/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
||||
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/status-im/go-waku/waku/v2/node"
|
||||
"github.com/status-im/go-waku/waku/v2/protocol/relay"
|
||||
)
|
||||
|
||||
// ChatUI is a Text User Interface (TUI) for a ChatRoom.
|
||||
@ -93,7 +93,7 @@ func NewChatUI(ctx context.Context, chat *Chat) *ChatUI {
|
||||
|
||||
// list peers
|
||||
if line == "/peers" {
|
||||
peers := chat.node.PubSub().ListPeers(string(node.DefaultWakuTopic))
|
||||
peers := chat.node.Relay().PubSub().ListPeers(string(relay.DefaultWakuTopic))
|
||||
if len(peers) == 0 {
|
||||
chatUI.displayMessage("No peers available")
|
||||
}
|
||||
@ -188,7 +188,7 @@ func (ui *ChatUI) handleEvents() {
|
||||
for {
|
||||
select {
|
||||
case input := <-ui.inputCh:
|
||||
err := ui.chat.Publish(input)
|
||||
err := ui.chat.Publish(ui.ctx, input)
|
||||
if err != nil {
|
||||
printErr("publish error: %s", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user