Remove secio usage and cleanup exports (#519)
* cleaned up exports * remove secio use * added more useful exports * proper import
This commit is contained in:
parent
646557597d
commit
4dea23c394
24
libp2p.nim
24
libp2p.nim
|
@ -8,20 +8,26 @@
|
||||||
## those terms.
|
## those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
libp2p/[daemon/daemonapi,
|
libp2p/[protobuf/minprotobuf,
|
||||||
daemon/transpool,
|
muxers/muxer,
|
||||||
protobuf/minprotobuf,
|
muxers/mplex/mplex,
|
||||||
|
stream/lpstream,
|
||||||
|
stream/bufferstream,
|
||||||
|
stream/connection,
|
||||||
|
transports/transport,
|
||||||
|
transports/tcptransport,
|
||||||
|
protocols/secure/noise,
|
||||||
varint,
|
varint,
|
||||||
switch,
|
switch,
|
||||||
peerid,
|
peerid,
|
||||||
peerinfo,
|
peerinfo,
|
||||||
stream/lpstream,
|
|
||||||
stream/bufferstream,
|
|
||||||
stream/connection,
|
|
||||||
multiaddress,
|
multiaddress,
|
||||||
crypto/crypto]
|
crypto/crypto]
|
||||||
|
|
||||||
|
import bearssl
|
||||||
|
|
||||||
export
|
export
|
||||||
daemonapi, transpool, minprotobuf, varint,
|
minprotobuf, varint,switch, peerid, peerinfo,
|
||||||
switch, peerid, peerinfo, connection,
|
connection, multiaddress, crypto, lpstream,
|
||||||
multiaddress, crypto, lpstream, bufferstream
|
bufferstream, bearssl, muxer, mplex, transport,
|
||||||
|
tcptransport, noise
|
||||||
|
|
|
@ -1,21 +1,15 @@
|
||||||
import
|
import options, tables
|
||||||
options, tables, chronos, bearssl,
|
import chronos
|
||||||
switch, peerid, peerinfo, stream/connection, multiaddress,
|
import ../libp2p
|
||||||
crypto/crypto, transports/[transport, tcptransport],
|
|
||||||
muxers/[muxer, mplex/mplex],
|
|
||||||
protocols/[identify, secure/secure]
|
|
||||||
|
|
||||||
import
|
export libp2p
|
||||||
protocols/secure/noise,
|
|
||||||
protocols/secure/secio
|
|
||||||
|
|
||||||
export
|
import connmanager
|
||||||
switch, peerid, peerinfo, connection, multiaddress, crypto
|
|
||||||
|
|
||||||
type
|
type
|
||||||
SecureProtocol* {.pure.} = enum
|
SecureProtocol* {.pure.} = enum
|
||||||
Noise,
|
Noise,
|
||||||
Secio
|
Secio # deprecated
|
||||||
|
|
||||||
proc newStandardSwitch*(privKey = none(PrivateKey),
|
proc newStandardSwitch*(privKey = none(PrivateKey),
|
||||||
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
|
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
|
||||||
|
@ -54,7 +48,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
||||||
of SecureProtocol.Noise:
|
of SecureProtocol.Noise:
|
||||||
secureManagerInstances &= newNoise(rng, seckey).Secure
|
secureManagerInstances &= newNoise(rng, seckey).Secure
|
||||||
of SecureProtocol.Secio:
|
of SecureProtocol.Secio:
|
||||||
secureManagerInstances &= newSecio(rng, seckey).Secure
|
quit("Secio is deprecated!") # use of secio is unsafe
|
||||||
|
|
||||||
let switch = newSwitch(
|
let switch = newSwitch(
|
||||||
peerInfo,
|
peerInfo,
|
||||||
|
|
|
@ -324,8 +324,7 @@ suite "GossipSub":
|
||||||
let
|
let
|
||||||
nodes = generateNodes(
|
nodes = generateNodes(
|
||||||
2,
|
2,
|
||||||
gossip = true,
|
gossip = true)
|
||||||
secureManagers = [SecureProtocol.Noise])
|
|
||||||
|
|
||||||
# start switches
|
# start switches
|
||||||
nodesFut = await allFinished(
|
nodesFut = await allFinished(
|
||||||
|
@ -372,8 +371,7 @@ suite "GossipSub":
|
||||||
let
|
let
|
||||||
nodes = generateNodes(
|
nodes = generateNodes(
|
||||||
2,
|
2,
|
||||||
gossip = true,
|
gossip = true)
|
||||||
secureManagers = [SecureProtocol.Secio])
|
|
||||||
|
|
||||||
# start switches
|
# start switches
|
||||||
nodesFut = await allFinished(
|
nodesFut = await allFinished(
|
||||||
|
@ -437,8 +435,7 @@ suite "GossipSub":
|
||||||
let
|
let
|
||||||
nodes = generateNodes(
|
nodes = generateNodes(
|
||||||
2,
|
2,
|
||||||
gossip = true,
|
gossip = true)
|
||||||
secureManagers = [SecureProtocol.Secio])
|
|
||||||
|
|
||||||
# start switches
|
# start switches
|
||||||
nodesFut = await allFinished(
|
nodesFut = await allFinished(
|
||||||
|
@ -509,8 +506,7 @@ suite "GossipSub":
|
||||||
let
|
let
|
||||||
nodes = generateNodes(
|
nodes = generateNodes(
|
||||||
2,
|
2,
|
||||||
gossip = true,
|
gossip = true)
|
||||||
secureManagers = [SecureProtocol.Secio])
|
|
||||||
|
|
||||||
# start switches
|
# start switches
|
||||||
nodesFut = await allFinished(
|
nodesFut = await allFinished(
|
||||||
|
|
|
@ -69,9 +69,7 @@ proc testPubSubDaemonPublish(gossip: bool = false, count: int = 1) {.async.} =
|
||||||
|
|
||||||
let daemonNode = await newDaemonApi(flags)
|
let daemonNode = await newDaemonApi(flags)
|
||||||
let daemonPeer = await daemonNode.identity()
|
let daemonPeer = await daemonNode.identity()
|
||||||
let nativeNode = newStandardSwitch(
|
let nativeNode = newStandardSwitch(outTimeout = 5.minutes)
|
||||||
secureManagers = [SecureProtocol.Noise],
|
|
||||||
outTimeout = 5.minutes)
|
|
||||||
|
|
||||||
let pubsub = if gossip:
|
let pubsub = if gossip:
|
||||||
GossipSub.init(
|
GossipSub.init(
|
||||||
|
@ -135,9 +133,7 @@ proc testPubSubNodePublish(gossip: bool = false, count: int = 1) {.async.} =
|
||||||
|
|
||||||
let daemonNode = await newDaemonApi(flags)
|
let daemonNode = await newDaemonApi(flags)
|
||||||
let daemonPeer = await daemonNode.identity()
|
let daemonPeer = await daemonNode.identity()
|
||||||
let nativeNode = newStandardSwitch(
|
let nativeNode = newStandardSwitch(outTimeout = 5.minutes)
|
||||||
secureManagers = [SecureProtocol.Noise],
|
|
||||||
outTimeout = 5.minutes)
|
|
||||||
|
|
||||||
let pubsub = if gossip:
|
let pubsub = if gossip:
|
||||||
GossipSub.init(
|
GossipSub.init(
|
||||||
|
|
|
@ -140,10 +140,10 @@ suite "Switch":
|
||||||
testProto.codec = TestCodec
|
testProto.codec = TestCodec
|
||||||
testProto.handler = handle
|
testProto.handler = handle
|
||||||
|
|
||||||
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch1 = newStandardSwitch()
|
||||||
switch1.mount(testProto)
|
switch1.mount(testProto)
|
||||||
|
|
||||||
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch2 = newStandardSwitch()
|
||||||
var awaiters: seq[Future[void]]
|
var awaiters: seq[Future[void]]
|
||||||
awaiters.add(await switch1.start())
|
awaiters.add(await switch1.start())
|
||||||
awaiters.add(await switch2.start())
|
awaiters.add(await switch2.start())
|
||||||
|
@ -215,8 +215,8 @@ suite "Switch":
|
||||||
asyncTest "e2e should not leak on peer disconnect":
|
asyncTest "e2e should not leak on peer disconnect":
|
||||||
var awaiters: seq[Future[void]]
|
var awaiters: seq[Future[void]]
|
||||||
|
|
||||||
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch1 = newStandardSwitch()
|
||||||
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch2 = newStandardSwitch()
|
||||||
awaiters.add(await switch1.start())
|
awaiters.add(await switch1.start())
|
||||||
awaiters.add(await switch2.start())
|
awaiters.add(await switch2.start())
|
||||||
|
|
||||||
|
@ -241,8 +241,8 @@ suite "Switch":
|
||||||
asyncTest "e2e should trigger connection events (remote)":
|
asyncTest "e2e should trigger connection events (remote)":
|
||||||
var awaiters: seq[Future[void]]
|
var awaiters: seq[Future[void]]
|
||||||
|
|
||||||
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch1 = newStandardSwitch()
|
||||||
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch2 = newStandardSwitch()
|
||||||
|
|
||||||
var step = 0
|
var step = 0
|
||||||
var kinds: set[ConnEventKind]
|
var kinds: set[ConnEventKind]
|
||||||
|
@ -296,8 +296,8 @@ suite "Switch":
|
||||||
asyncTest "e2e should trigger connection events (local)":
|
asyncTest "e2e should trigger connection events (local)":
|
||||||
var awaiters: seq[Future[void]]
|
var awaiters: seq[Future[void]]
|
||||||
|
|
||||||
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch1 = newStandardSwitch()
|
||||||
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch2 = newStandardSwitch()
|
||||||
|
|
||||||
var step = 0
|
var step = 0
|
||||||
var kinds: set[ConnEventKind]
|
var kinds: set[ConnEventKind]
|
||||||
|
@ -351,8 +351,8 @@ suite "Switch":
|
||||||
asyncTest "e2e should trigger peer events (remote)":
|
asyncTest "e2e should trigger peer events (remote)":
|
||||||
var awaiters: seq[Future[void]]
|
var awaiters: seq[Future[void]]
|
||||||
|
|
||||||
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch1 = newStandardSwitch()
|
||||||
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch2 = newStandardSwitch()
|
||||||
|
|
||||||
var step = 0
|
var step = 0
|
||||||
var kinds: set[PeerEventKind]
|
var kinds: set[PeerEventKind]
|
||||||
|
@ -405,8 +405,8 @@ suite "Switch":
|
||||||
asyncTest "e2e should trigger peer events (local)":
|
asyncTest "e2e should trigger peer events (local)":
|
||||||
var awaiters: seq[Future[void]]
|
var awaiters: seq[Future[void]]
|
||||||
|
|
||||||
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch1 = newStandardSwitch()
|
||||||
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch2 = newStandardSwitch()
|
||||||
|
|
||||||
var step = 0
|
var step = 0
|
||||||
var kinds: set[PeerEventKind]
|
var kinds: set[PeerEventKind]
|
||||||
|
@ -459,20 +459,18 @@ suite "Switch":
|
||||||
asyncTest "e2e should trigger peer events only once per peer":
|
asyncTest "e2e should trigger peer events only once per peer":
|
||||||
var awaiters: seq[Future[void]]
|
var awaiters: seq[Future[void]]
|
||||||
|
|
||||||
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
|
let switch1 = newStandardSwitch()
|
||||||
|
|
||||||
let rng = newRng()
|
let rng = newRng()
|
||||||
# use same private keys to emulate two connection from same peer
|
# use same private keys to emulate two connection from same peer
|
||||||
let privKey = PrivateKey.random(rng[]).tryGet()
|
let privKey = PrivateKey.random(rng[]).tryGet()
|
||||||
let switch2 = newStandardSwitch(
|
let switch2 = newStandardSwitch(
|
||||||
privKey = some(privKey),
|
privKey = some(privKey),
|
||||||
rng = rng,
|
rng = rng)
|
||||||
secureManagers = [SecureProtocol.Secio])
|
|
||||||
|
|
||||||
let switch3 = newStandardSwitch(
|
let switch3 = newStandardSwitch(
|
||||||
privKey = some(privKey),
|
privKey = some(privKey),
|
||||||
rng = rng,
|
rng = rng)
|
||||||
secureManagers = [SecureProtocol.Secio])
|
|
||||||
|
|
||||||
var step = 0
|
var step = 0
|
||||||
var kinds: set[PeerEventKind]
|
var kinds: set[PeerEventKind]
|
||||||
|
@ -548,8 +546,7 @@ suite "Switch":
|
||||||
done.complete()
|
done.complete()
|
||||||
|
|
||||||
switches.add(newStandardSwitch(
|
switches.add(newStandardSwitch(
|
||||||
rng = rng,
|
rng = rng))
|
||||||
secureManagers = [SecureProtocol.Secio]))
|
|
||||||
|
|
||||||
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
|
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
|
||||||
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
|
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
|
||||||
|
@ -557,8 +554,7 @@ suite "Switch":
|
||||||
|
|
||||||
switches.add(newStandardSwitch(
|
switches.add(newStandardSwitch(
|
||||||
privKey = some(peerInfo.privateKey),
|
privKey = some(peerInfo.privateKey),
|
||||||
rng = rng,
|
rng = rng))
|
||||||
secureManagers = [SecureProtocol.Secio]))
|
|
||||||
onConnect = switches[1].connect(switches[0].peerInfo)
|
onConnect = switches[1].connect(switches[0].peerInfo)
|
||||||
await onConnect
|
await onConnect
|
||||||
|
|
||||||
|
@ -597,8 +593,7 @@ suite "Switch":
|
||||||
conns.dec
|
conns.dec
|
||||||
|
|
||||||
switches.add(newStandardSwitch(
|
switches.add(newStandardSwitch(
|
||||||
rng = rng,
|
rng = rng))
|
||||||
secureManagers = [SecureProtocol.Secio]))
|
|
||||||
|
|
||||||
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
|
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
|
||||||
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
|
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
|
||||||
|
@ -607,8 +602,7 @@ suite "Switch":
|
||||||
for i in 1..5:
|
for i in 1..5:
|
||||||
switches.add(newStandardSwitch(
|
switches.add(newStandardSwitch(
|
||||||
privKey = some(peerInfo.privateKey),
|
privKey = some(peerInfo.privateKey),
|
||||||
rng = rng,
|
rng = rng))
|
||||||
secureManagers = [SecureProtocol.Secio]))
|
|
||||||
onConnect = switches[i].connect(switches[0].peerInfo)
|
onConnect = switches[i].connect(switches[0].peerInfo)
|
||||||
await onConnect
|
await onConnect
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue