mirror of https://github.com/status-im/go-waku.git
update go-waku version
This commit is contained in:
parent
997bc4f2d8
commit
b60ee0fe5c
|
@ -5,5 +5,5 @@ go 1.15
|
||||||
require (
|
require (
|
||||||
github.com/ethereum/go-ethereum v1.9.5
|
github.com/ethereum/go-ethereum v1.9.5
|
||||||
github.com/ipfs/go-log v1.0.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
|
||||||
)
|
)
|
||||||
|
|
|
@ -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-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 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-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 h1:F4UGcP80H0PGaeJ0mRMzA1Ux3DKYiyv/qu3bOR/efTg=
|
||||||
github.com/status-im/go-wakurelay-pubsub v0.4.2/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
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=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"github.com/status-im/go-waku/waku/v2/node"
|
"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")
|
var log = logging.Logger("basic2")
|
||||||
|
@ -76,7 +76,7 @@ func write(wakuNode *node.WakuNode, msgContent string) {
|
||||||
|
|
||||||
payload, err := p.Encode(version)
|
payload, err := p.Encode(version)
|
||||||
|
|
||||||
msg := &protocol.WakuMessage{
|
msg := &pb.WakuMessage{
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
Version: version,
|
Version: version,
|
||||||
ContentTopic: contentTopic,
|
ContentTopic: contentTopic,
|
||||||
|
|
|
@ -2,13 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"chat2/pb"
|
"chat2/pb"
|
||||||
"context"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
"github.com/status-im/go-waku/waku/v2/node"
|
"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
|
// 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 is a channel of messages received from other peers in the chat room
|
||||||
Messages chan *pb.Chat2Message
|
Messages chan *pb.Chat2Message
|
||||||
|
|
||||||
ctx context.Context
|
|
||||||
sub *node.Subscription
|
sub *node.Subscription
|
||||||
node *node.WakuNode
|
node *node.WakuNode
|
||||||
|
|
||||||
|
@ -28,7 +26,7 @@ type Chat struct {
|
||||||
|
|
||||||
// NewChat tries to subscribe to the PubSub topic for the room name, returning
|
// NewChat tries to subscribe to the PubSub topic for the room name, returning
|
||||||
// a ChatRoom on success.
|
// 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
|
// join the default waku topic and subscribe to it
|
||||||
sub, err := n.Subscribe(nil)
|
sub, err := n.Subscribe(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,7 +34,6 @@ func NewChat(ctx context.Context, n *node.WakuNode, selfID peer.ID, nickname str
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &Chat{
|
c := &Chat{
|
||||||
ctx: ctx,
|
|
||||||
node: n,
|
node: n,
|
||||||
sub: sub,
|
sub: sub,
|
||||||
self: selfID,
|
self: selfID,
|
||||||
|
@ -77,7 +74,7 @@ func (cr *Chat) Publish(message string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
wakuMsg := &protocol.WakuMessage{
|
wakuMsg := &wpb.WakuMessage{
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
Version: version,
|
Version: version,
|
||||||
ContentTopic: DefaultContentTopic,
|
ContentTopic: DefaultContentTopic,
|
||||||
|
@ -89,7 +86,7 @@ func (cr *Chat) Publish(message string) error {
|
||||||
return err
|
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})
|
payload, err := node.DecodePayload(wakumsg, &node.KeyInfo{Kind: node.None})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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 {
|
for _, msg := range messages {
|
||||||
cr.decodeMessage(msg)
|
cr.decodeMessage(msg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ require (
|
||||||
github.com/ipfs/go-log/v2 v2.1.1
|
github.com/ipfs/go-log/v2 v2.1.1
|
||||||
github.com/libp2p/go-libp2p-core v0.8.5
|
github.com/libp2p/go-libp2p-core v0.8.5
|
||||||
github.com/rivo/tview v0.0.0-20210312174852-ae9464cc3598
|
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
|
google.golang.org/protobuf v1.25.0
|
||||||
)
|
)
|
||||||
|
|
|
@ -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-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 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-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 h1:F4UGcP80H0PGaeJ0mRMzA1Ux3DKYiyv/qu3bOR/efTg=
|
||||||
github.com/status-im/go-wakurelay-pubsub v0.4.2/go.mod h1:LSCVYR7mnBBsxVJghrGpQ3yJAAATEe6XeQQqGCZhwrE=
|
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=
|
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
"github.com/status-im/go-waku/waku/v2/node"
|
"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"
|
var DefaultContentTopic string = "dingpu"
|
||||||
|
@ -68,7 +68,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// join the chat
|
// join the chat
|
||||||
chat, err := NewChat(ctx, wakuNode, wakuNode.Host().ID(), nick)
|
chat, err := NewChat(wakuNode, wakuNode.Host().ID(), nick)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func main() {
|
||||||
}
|
}
|
||||||
logging.SetAllLoggers(lvl)
|
logging.SetAllLoggers(lvl)
|
||||||
|
|
||||||
ui := NewChatUI(chat)
|
ui := NewChatUI(ctx, chat)
|
||||||
|
|
||||||
// Connect to a static node or use random node from fleets.status.im
|
// Connect to a static node or use random node from fleets.status.im
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -124,7 +124,8 @@ func main() {
|
||||||
time.Sleep(300 * time.Millisecond)
|
time.Sleep(300 * time.Millisecond)
|
||||||
ui.displayMessage("Querying historic messages")
|
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.WithAutomaticRequestId(),
|
||||||
store.WithPeer(*storeNodeId),
|
store.WithPeer(*storeNodeId),
|
||||||
store.WithPaging(true, 0))
|
store.WithPaging(true, 0))
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"chat2/pb"
|
"chat2/pb"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -23,11 +24,13 @@ type ChatUI struct {
|
||||||
msgW io.Writer
|
msgW io.Writer
|
||||||
inputCh chan string
|
inputCh chan string
|
||||||
doneCh chan struct{}
|
doneCh chan struct{}
|
||||||
|
|
||||||
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChatUI returns a new ChatUI struct that controls the text UI.
|
// NewChatUI returns a new ChatUI struct that controls the text UI.
|
||||||
// It won't actually do anything until you call Run().
|
// 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)
|
chatUI := new(ChatUI)
|
||||||
|
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
|
@ -137,6 +140,7 @@ Available commands:
|
||||||
chatUI.app = app
|
chatUI.app = app
|
||||||
chatUI.msgW = msgBox
|
chatUI.msgW = msgBox
|
||||||
chatUI.chat = chat
|
chatUI.chat = chat
|
||||||
|
chatUI.ctx = ctx
|
||||||
chatUI.inputCh = inputCh
|
chatUI.inputCh = inputCh
|
||||||
chatUI.doneCh = make(chan struct{}, 1)
|
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
|
// when we receive a message from the chat room, print it to the message window
|
||||||
ui.displayChatMessage(m)
|
ui.displayChatMessage(m)
|
||||||
|
|
||||||
case <-ui.chat.ctx.Done():
|
case <-ui.ctx.Done():
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-ui.doneCh:
|
case <-ui.doneCh:
|
||||||
|
|
Loading…
Reference in New Issue