2020-05-10 06:53:48 +00:00
|
|
|
# compile time options here
|
|
|
|
const
|
|
|
|
libp2p_secure {.strdefine.} = ""
|
2020-05-26 03:55:53 +00:00
|
|
|
libp2p_pubsub_sign {.booldefine.} = true
|
|
|
|
libp2p_pubsub_verify {.booldefine.} = true
|
2020-05-10 06:53:48 +00:00
|
|
|
|
|
|
|
import
|
2020-05-26 03:55:53 +00:00
|
|
|
options, tables, chronicles, chronos,
|
2020-05-10 06:53:48 +00:00
|
|
|
libp2p/[switch, peer, peerinfo, connection, multiaddress, crypto/crypto],
|
|
|
|
libp2p/transports/[transport, tcptransport],
|
|
|
|
libp2p/muxers/[muxer, mplex/mplex, mplex/types],
|
|
|
|
libp2p/protocols/[identify, secure/secure],
|
2020-05-27 04:07:11 +00:00
|
|
|
libp2p/protocols/pubsub/[pubsub, gossipsub],
|
2020-05-14 02:42:04 +00:00
|
|
|
../../waku/protocol/v2/waku_protocol
|
2020-05-10 06:53:48 +00:00
|
|
|
|
|
|
|
when libp2p_secure == "noise":
|
|
|
|
import libp2p/protocols/secure/noise
|
|
|
|
else:
|
|
|
|
import libp2p/protocols/secure/secio
|
|
|
|
|
|
|
|
export
|
|
|
|
switch, peer, peerinfo, connection, multiaddress, crypto
|
|
|
|
|
|
|
|
proc newStandardSwitch*(privKey = none(PrivateKey),
|
2020-06-01 03:15:37 +00:00
|
|
|
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
|
2020-05-10 06:53:48 +00:00
|
|
|
triggerSelf = false,
|
2020-05-26 03:55:53 +00:00
|
|
|
gossip = false,
|
|
|
|
verifySignature = libp2p_pubsub_verify,
|
|
|
|
sign = libp2p_pubsub_sign,
|
|
|
|
transportFlags: set[ServerFlags] = {}): Switch =
|
2020-05-18 06:03:15 +00:00
|
|
|
info "newStandardSwitch"
|
2020-05-10 06:53:48 +00:00
|
|
|
proc createMplex(conn: Connection): Muxer =
|
|
|
|
result = newMplex(conn)
|
|
|
|
|
|
|
|
let
|
2020-05-26 03:55:53 +00:00
|
|
|
seckey = privKey.get(otherwise = PrivateKey.random(ECDSA).tryGet())
|
2020-05-10 06:53:48 +00:00
|
|
|
peerInfo = PeerInfo.init(seckey, [address])
|
|
|
|
mplexProvider = newMuxerProvider(createMplex, MplexCodec)
|
2020-05-26 03:55:53 +00:00
|
|
|
transports = @[Transport(TcpTransport.init(transportFlags))]
|
2020-05-10 06:53:48 +00:00
|
|
|
muxers = {MplexCodec: mplexProvider}.toTable
|
|
|
|
identify = newIdentify(peerInfo)
|
|
|
|
when libp2p_secure == "noise":
|
|
|
|
let secureManagers = {NoiseCodec: newNoise(seckey).Secure}.toTable
|
|
|
|
else:
|
|
|
|
let secureManagers = {SecioCodec: newSecio(seckey).Secure}.toTable
|
|
|
|
let pubSub = if gossip:
|
|
|
|
PubSub newPubSub(GossipSub, peerInfo, triggerSelf)
|
|
|
|
else:
|
|
|
|
# Creating switch from generate node
|
2020-05-11 04:05:28 +00:00
|
|
|
# XXX: Hacky test, hijacking WakuSub here
|
2020-05-15 03:35:32 +00:00
|
|
|
debug "Using WakuSub here"
|
2020-05-14 03:18:20 +00:00
|
|
|
#PubSub newPubSub(FloodSub, peerInfo, triggerSelf)
|
|
|
|
PubSub newPubSub(WakuSub, peerInfo, triggerSelf)
|
2020-05-10 06:53:48 +00:00
|
|
|
|
|
|
|
result = newSwitch(peerInfo,
|
|
|
|
transports,
|
|
|
|
identify,
|
|
|
|
muxers,
|
|
|
|
secureManagers = secureManagers,
|
|
|
|
pubSub = some(pubSub))
|