update go-waku version

This commit is contained in:
Richard Ramos 2021-04-21 20:12:51 -04:00
parent 997bc4f2d8
commit b60ee0fe5c
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
8 changed files with 25 additions and 18 deletions

View File

@ -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-20210419000316-ef67ff356f7e
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d
)

View File

@ -611,6 +611,8 @@ github.com/status-im/go-waku v0.0.0-20210415175540-7ba8c51bcafe h1:yGtEg5EzBpSLe
github.com/status-im/go-waku v0.0.0-20210415175540-7ba8c51bcafe/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
github.com/status-im/go-waku v0.0.0-20210419000316-ef67ff356f7e h1:bb/99wDRvUQpKQQFGa4lxhJY3LRx821rqv0D4txuD1M=
github.com/status-im/go-waku v0.0.0-20210419000316-ef67ff356f7e/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d h1:hfCilmm5iO2Wd2rix3x9OkEmgIGHnkEkEcyy0D7ng2k=
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d/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=

View File

@ -14,7 +14,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
logging "github.com/ipfs/go-log"
"github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol"
"github.com/status-im/go-waku/waku/v2/protocol/pb"
)
var log = logging.Logger("basic2")
@ -76,7 +76,7 @@ func write(wakuNode *node.WakuNode, msgContent string) {
payload, err := p.Encode(version)
msg := &protocol.WakuMessage{
msg := &pb.WakuMessage{
Payload: payload,
Version: version,
ContentTopic: contentTopic,

View File

@ -2,13 +2,12 @@ package main
import (
"chat2/pb"
"context"
"time"
"github.com/golang/protobuf/proto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol"
wpb "github.com/status-im/go-waku/waku/v2/protocol/pb"
)
// Chat represents a subscription to a single PubSub topic. Messages
@ -18,7 +17,6 @@ type Chat struct {
// Messages is a channel of messages received from other peers in the chat room
Messages chan *pb.Chat2Message
ctx context.Context
sub *node.Subscription
node *node.WakuNode
@ -28,7 +26,7 @@ type Chat struct {
// NewChat tries to subscribe to the PubSub topic for the room name, returning
// a ChatRoom on success.
func NewChat(ctx context.Context, n *node.WakuNode, selfID peer.ID, nickname string) (*Chat, error) {
func NewChat(n *node.WakuNode, selfID peer.ID, nickname string) (*Chat, error) {
// join the default waku topic and subscribe to it
sub, err := n.Subscribe(nil)
if err != nil {
@ -36,7 +34,6 @@ func NewChat(ctx context.Context, n *node.WakuNode, selfID peer.ID, nickname str
}
c := &Chat{
ctx: ctx,
node: n,
sub: sub,
self: selfID,
@ -77,7 +74,7 @@ func (cr *Chat) Publish(message string) error {
return err
}
wakuMsg := &protocol.WakuMessage{
wakuMsg := &wpb.WakuMessage{
Payload: payload,
Version: version,
ContentTopic: DefaultContentTopic,
@ -89,7 +86,7 @@ func (cr *Chat) Publish(message string) error {
return err
}
func (cr *Chat) decodeMessage(wakumsg *protocol.WakuMessage) {
func (cr *Chat) decodeMessage(wakumsg *wpb.WakuMessage) {
payload, err := node.DecodePayload(wakumsg, &node.KeyInfo{Kind: node.None})
if err != nil {
return
@ -111,7 +108,7 @@ func (cr *Chat) readLoop() {
}
}
func (cr *Chat) displayMessages(messages []*protocol.WakuMessage) {
func (cr *Chat) displayMessages(messages []*wpb.WakuMessage) {
for _, msg := range messages {
cr.decodeMessage(msg)
}

View File

@ -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-20210420214635-287a54aca716
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d
google.golang.org/protobuf v1.25.0
)

View File

@ -789,6 +789,9 @@ github.com/status-im/go-waku v0.0.0-20210415175540-7ba8c51bcafe h1:yGtEg5EzBpSLe
github.com/status-im/go-waku v0.0.0-20210415175540-7ba8c51bcafe/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
github.com/status-im/go-waku v0.0.0-20210419000316-ef67ff356f7e h1:bb/99wDRvUQpKQQFGa4lxhJY3LRx821rqv0D4txuD1M=
github.com/status-im/go-waku v0.0.0-20210419000316-ef67ff356f7e/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
github.com/status-im/go-waku v0.0.0-20210420214635-287a54aca716/go.mod h1:GjrbwNCdtae7sFmvFyXJPSRgnrcmJp3wVSjDZWOG8+s=
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d h1:hfCilmm5iO2Wd2rix3x9OkEmgIGHnkEkEcyy0D7ng2k=
github.com/status-im/go-waku v0.0.0-20210422000937-997bc4f2d86d/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=

View File

@ -19,7 +19,7 @@ import (
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/status-im/go-waku/waku/v2/node"
store "github.com/status-im/go-waku/waku/v2/protocol/waku_store"
"github.com/status-im/go-waku/waku/v2/protocol/store"
)
var DefaultContentTopic string = "dingpu"
@ -68,7 +68,7 @@ func main() {
}
// join the chat
chat, err := NewChat(ctx, wakuNode, wakuNode.Host().ID(), nick)
chat, err := NewChat(wakuNode, wakuNode.Host().ID(), nick)
if err != nil {
panic(err)
}
@ -80,7 +80,7 @@ func main() {
}
logging.SetAllLoggers(lvl)
ui := NewChatUI(chat)
ui := NewChatUI(ctx, chat)
// Connect to a static node or use random node from fleets.status.im
go func() {
@ -124,7 +124,8 @@ func main() {
time.Sleep(300 * time.Millisecond)
ui.displayMessage("Querying historic messages")
response, err := wakuNode.Query([]string{DefaultContentTopic}, 0, 0,
tCtx, _ := context.WithTimeout(ctx, 1*time.Second)
response, err := wakuNode.Query(tCtx, []string{DefaultContentTopic}, 0, 0,
store.WithAutomaticRequestId(),
store.WithPeer(*storeNodeId),
store.WithPaging(true, 0))

View File

@ -2,6 +2,7 @@ package main
import (
"chat2/pb"
"context"
"fmt"
"io"
"strings"
@ -23,11 +24,13 @@ type ChatUI struct {
msgW io.Writer
inputCh chan string
doneCh chan struct{}
ctx context.Context
}
// NewChatUI returns a new ChatUI struct that controls the text UI.
// It won't actually do anything until you call Run().
func NewChatUI(chat *Chat) *ChatUI {
func NewChatUI(ctx context.Context, chat *Chat) *ChatUI {
chatUI := new(ChatUI)
app := tview.NewApplication()
@ -137,6 +140,7 @@ Available commands:
chatUI.app = app
chatUI.msgW = msgBox
chatUI.chat = chat
chatUI.ctx = ctx
chatUI.inputCh = inputCh
chatUI.doneCh = make(chan struct{}, 1)
@ -193,7 +197,7 @@ func (ui *ChatUI) handleEvents() {
// when we receive a message from the chat room, print it to the message window
ui.displayChatMessage(m)
case <-ui.chat.ctx.Done():
case <-ui.ctx.Done():
return
case <-ui.doneCh: