mirror of https://github.com/waku-org/nwaku.git
Dial other static node hacky
This commit is contained in:
parent
bab6420650
commit
e227959a34
|
@ -20,7 +20,20 @@ let node1 = newRpcHttpClient()
|
||||||
#let node2 = newRpcHttpClient()
|
#let node2 = newRpcHttpClient()
|
||||||
|
|
||||||
# Where do we connect nodes here? Protocol so not RPC based, maybe?
|
# Where do we connect nodes here? Protocol so not RPC based, maybe?
|
||||||
# Could hack it I suppose
|
# Using with static nodes, hardcoded "works":
|
||||||
|
# /ip4/127.0.0.1/tcp/55505/ipfs/16Uiu2HAkufRTzUnYCMggjPaAMbC3ss1bkrjewPcjwSeqK9WgUKYu
|
||||||
|
|
||||||
|
# static node parsing ignored for now
|
||||||
|
#./build/wakunode2 --staticnode:/ip4/hallibaba/foo --ports-shift:1
|
||||||
|
|
||||||
|
# node 1:
|
||||||
|
# WRN 2020-05-01 12:20:13+08:00 no handlers for tid=24636 protocol=/vac/waku/2.0.0-alpha0 topic=Multistream
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Need to figure out rw stuff as well, perhaps we can start a few nodes and see if we get some pingpong
|
||||||
|
# Unclear how to mount waku on top of gossipsub tho
|
||||||
|
|
||||||
info "Hello there"
|
info "Hello there"
|
||||||
# Hello world
|
# Hello world
|
||||||
|
|
|
@ -7,6 +7,7 @@ import
|
||||||
# TODO remove me
|
# TODO remove me
|
||||||
../../vendor/nimbus/nimbus/rpc/[wakusim, key_storage],
|
../../vendor/nimbus/nimbus/rpc/[wakusim, key_storage],
|
||||||
../../vendor/nim-libp2p/libp2p/standard_setup,
|
../../vendor/nim-libp2p/libp2p/standard_setup,
|
||||||
|
../../vendor/nim-libp2p/libp2p/multiaddress,
|
||||||
../../vendor/nim-libp2p/libp2p/crypto/crypto,
|
../../vendor/nim-libp2p/libp2p/crypto/crypto,
|
||||||
../../vendor/nim-libp2p/libp2p/protocols/protocol,
|
../../vendor/nim-libp2p/libp2p/protocols/protocol,
|
||||||
../../vendor/nim-libp2p/libp2p/peerinfo,
|
../../vendor/nim-libp2p/libp2p/peerinfo,
|
||||||
|
@ -48,12 +49,35 @@ proc setBootNodes(nodes: openArray[string]): seq[ENode] =
|
||||||
# TODO: something more user friendly than an expect
|
# TODO: something more user friendly than an expect
|
||||||
result.add(ENode.fromString(nodeId).expect("correct node"))
|
result.add(ENode.fromString(nodeId).expect("correct node"))
|
||||||
|
|
||||||
proc connectToNodes(node: EthereumNode, nodes: openArray[string]) =
|
proc initAddress(T: type MultiAddress, str: string): T =
|
||||||
for nodeId in nodes:
|
let address = MultiAddress.init(str)
|
||||||
# TODO: something more user friendly than an assert
|
if IPFS.match(address) and matchPartial(multiaddress.TCP, address):
|
||||||
let whisperENode = ENode.fromString(nodeId).expect("correct node")
|
result = address
|
||||||
|
else:
|
||||||
|
raise newException(MultiAddressError,
|
||||||
|
"Invalid bootstrap node multi-address")
|
||||||
|
|
||||||
traceAsyncErrors node.peerPool.connectToNode(newNode(whisperENode))
|
proc dialPeer(p: WakuProto, address: string) {.async.} =
|
||||||
|
let multiAddr = MultiAddress.initAddress(address)
|
||||||
|
let parts = address.split("/")
|
||||||
|
let remotePeer = PeerInfo.init(parts[^1], [multiAddr])
|
||||||
|
|
||||||
|
info "Dialing peer", multiAddr
|
||||||
|
p.conn = await p.switch.dial(remotePeer, WakuCodec)
|
||||||
|
# Isn't there just one p instance? Why connected here?
|
||||||
|
p.connected = true
|
||||||
|
|
||||||
|
proc connectToNodes(p: WakuProto, nodes: openArray[string]) =
|
||||||
|
info "connectToNodes", nodes
|
||||||
|
# XXX: Hardcoded here
|
||||||
|
let peerInfoStr = "/ip4/127.0.0.1/tcp/55505/ipfs/16Uiu2HAkufRTzUnYCMggjPaAMbC3ss1bkrjewPcjwSeqK9WgUKYu"
|
||||||
|
discard dialPeer(p, peerInfoStr)
|
||||||
|
# for nodeId in nodes:
|
||||||
|
# info "connectToNodes nodeid", nodeId
|
||||||
|
# # TODO: something more user friendly than an assert
|
||||||
|
# let whisperENode = ENode.fromString(nodeId).expect("correct node")
|
||||||
|
#
|
||||||
|
# traceAsyncErrors node.peerPool.connectToNode(newNode(whisperENode))
|
||||||
|
|
||||||
# NOTE: Looks almost identical to beacon_chain/eth2_network.nim
|
# NOTE: Looks almost identical to beacon_chain/eth2_network.nim
|
||||||
proc setupNat(conf: WakuNodeConf): tuple[ip: IpAddress,
|
proc setupNat(conf: WakuNodeConf): tuple[ip: IpAddress,
|
||||||
|
@ -180,8 +204,13 @@ proc run(config: WakuNodeConf) =
|
||||||
let id = peerInfo.peerId.pretty
|
let id = peerInfo.peerId.pretty
|
||||||
info "PeerInfo", id = id, addrs = peerInfo.addrs
|
info "PeerInfo", id = id, addrs = peerInfo.addrs
|
||||||
let listenStr = $peerInfo.addrs[0] & "/ipfs/" & id
|
let listenStr = $peerInfo.addrs[0] & "/ipfs/" & id
|
||||||
|
# XXX: this should be /ip4..., / stripped?
|
||||||
info "Listening on", full = listenStr
|
info "Listening on", full = listenStr
|
||||||
|
|
||||||
|
# XXX: So doing this _after_ other setup
|
||||||
|
# Optionally direct connect with a set of nodes
|
||||||
|
if config.staticnodes.len > 0: connectToNodes(wakuProto, config.staticnodes)
|
||||||
|
|
||||||
# Here directchat uses rwLoop for protocol
|
# Here directchat uses rwLoop for protocol
|
||||||
# What if we dial here? How dial?
|
# What if we dial here? How dial?
|
||||||
# Feels very ghetto, this hookup
|
# Feels very ghetto, this hookup
|
||||||
|
|
Loading…
Reference in New Issue