Revert "enhancement/integrate-store-chat (#208)"

This reverts commit 5c338ba731.

Breaks chat2
This commit is contained in:
Oskar Thoren 2020-10-15 13:06:09 +08:00
parent 5c338ba731
commit e3099f1ab3
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
3 changed files with 12 additions and 32 deletions

View File

@ -2,13 +2,11 @@
## Basic chat usage
> The chat app requires that the remote peer connected to is supports the WakuStore protocol. For Dingpu this is already the case.
Start two chat apps:
```
./build/chat2 --ports-shift:0 --storenode:/ip4/134.209.139.210/tcp/60000/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS
./build/chat2 --ports-shift:1 --storenode:/ip4/134.209.139.210/tcp/60000/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS
./build/chat2 --ports-shift=0
./build/chat2 --ports-shift=1
```
Type `/connect` then paste address of other node.

View File

@ -19,7 +19,7 @@ import libp2p/[switch, # manage transports, a single entry poi
muxers/muxer, # define an interface for stream multiplexing, allowing peers to offer many protocols over a single connection
muxers/mplex/mplex] # define some contants and message types for stream multiplexing
import ../../waku/node/v2/[config, wakunode2, waku_types],
../../waku/protocol/v2/[waku_relay, waku_store],
../../waku/protocol/v2/waku_relay,
../../waku/node/common
const Help = """
@ -55,23 +55,21 @@ proc initAddress(T: type MultiAddress, str: string): T =
raise newException(ValueError,
"Invalid bootstrap node multi-address")
proc parsePeer(address: string): PeerInfo =
# NOTE Dialing on WakuRelay specifically
proc dialPeer(c: Chat, address: string) {.async.} =
let multiAddr = MultiAddress.initAddress(address)
let parts = address.split("/")
result = PeerInfo.init(parts[^1], [multiAddr])
let remotePeer = PeerInfo.init(parts[^1], [multiAddr])
# NOTE Dialing on WakuRelay specifically
proc dialPeer(c: Chat, peer: PeerInfo) {.async.} =
echo &"dialing peer: {peer.peerId}"
echo &"dialing peer: {multiAddr}"
# XXX Discarding conn, do we want to keep this here?
discard await c.node.switch.dial(peer, WakuRelayCodec)
discard await c.node.switch.dial(remotePeer, WakuRelayCodec)
c.connected = true
proc connectToNodes(c: Chat, nodes: openArray[string]) =
echo "Connecting to nodes"
for nodeId in nodes:
let peer = parsePeer(nodeId)
discard dialPeer(c, peer)
discard dialPeer(c, nodeId)
proc publish(c: Chat, line: string) =
let payload = cast[seq[byte]](line)
@ -115,8 +113,7 @@ proc writeAndPrint(c: Chat) {.async.} =
echo "enter address of remote peer"
let address = await c.transp.readLine()
if address.len > 0:
let peer = parsePeer(address)
await c.dialPeer(peer)
await c.dialPeer(address)
# elif line.startsWith("/exit"):
# if p.connected and p.conn.closed.not:
@ -134,8 +131,7 @@ proc writeAndPrint(c: Chat) {.async.} =
else:
try:
if line.startsWith("/") and "p2p" in line:
let peer = parsePeer(line)
await c.dialPeer(peer)
await c.dialPeer(line)
except:
echo &"unable to dial remote peer {line}"
echo getCurrentExceptionMsg()
@ -176,23 +172,10 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
let listenStr = $peerInfo.addrs[0] & "/p2p/" & $peerInfo.peerId
echo &"Listening on\n {listenStr}"
let topic = cast[Topic](DefaultContentTopic)
let multiAddr = MultiAddress.initAddress(conf.storenode)
let parts = conf.storenode.split("/")
node.wakuStore.setPeer(PeerInfo.init(parts[^1], [multiAddr]))
proc storeHandler(response: HistoryResponse) {.gcsafe.} =
for msg in response.messages:
let payload = cast[string](msg.payload)
echo &"{payload}"
info "Hit store handler"
await node.query(HistoryQuery(topics: @[topic]), storeHandler)
# Subscribe to a topic
# TODO To get end to end sender would require more information in payload
# We could possibly indicate the relayer point with connection somehow probably (?)
let topic = cast[Topic](DefaultTopic)
proc handler(topic: Topic, data: seq[byte]) {.async, gcsafe.} =
let message = WakuMessage.init(data).value
let payload = cast[string](message.payload)

View File

@ -133,7 +133,6 @@ proc start*(node: WakuNode) {.async.} =
let msg = WakuMessage.init(data)
if msg.isOk():
node.filters.notify(msg.value(), "")
await node.subscriptions.notify(topic, msg.value())
await node.wakuRelay.subscribe("waku", relayHandler)