Skip to content

Commit 4dea23c

Browse files
authored
Remove secio usage and cleanup exports (#519)
* cleaned up exports * remove secio use * added more useful exports * proper import
1 parent 6465575 commit 4dea23c

File tree

5 files changed

+47
-61
lines changed

5 files changed

+47
-61
lines changed

libp2p.nim

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@
88
## those terms.
99

1010
import
11-
libp2p/[daemon/daemonapi,
12-
daemon/transpool,
13-
protobuf/minprotobuf,
11+
libp2p/[protobuf/minprotobuf,
12+
muxers/muxer,
13+
muxers/mplex/mplex,
14+
stream/lpstream,
15+
stream/bufferstream,
16+
stream/connection,
17+
transports/transport,
18+
transports/tcptransport,
19+
protocols/secure/noise,
1420
varint,
1521
switch,
1622
peerid,
1723
peerinfo,
18-
stream/lpstream,
19-
stream/bufferstream,
20-
stream/connection,
2124
multiaddress,
2225
crypto/crypto]
2326

27+
import bearssl
28+
2429
export
25-
daemonapi, transpool, minprotobuf, varint,
26-
switch, peerid, peerinfo, connection,
27-
multiaddress, crypto, lpstream, bufferstream
30+
minprotobuf, varint,switch, peerid, peerinfo,
31+
connection, multiaddress, crypto, lpstream,
32+
bufferstream, bearssl, muxer, mplex, transport,
33+
tcptransport, noise

libp2p/standard_setup.nim

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import
2-
options, tables, chronos, bearssl,
3-
switch, peerid, peerinfo, stream/connection, multiaddress,
4-
crypto/crypto, transports/[transport, tcptransport],
5-
muxers/[muxer, mplex/mplex],
6-
protocols/[identify, secure/secure]
1+
import options, tables
2+
import chronos
3+
import ../libp2p
74

8-
import
9-
protocols/secure/noise,
10-
protocols/secure/secio
5+
export libp2p
116

12-
export
13-
switch, peerid, peerinfo, connection, multiaddress, crypto
7+
import connmanager
148

159
type
1610
SecureProtocol* {.pure.} = enum
1711
Noise,
18-
Secio
12+
Secio # deprecated
1913

2014
proc newStandardSwitch*(privKey = none(PrivateKey),
2115
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet(),
@@ -54,7 +48,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
5448
of SecureProtocol.Noise:
5549
secureManagerInstances &= newNoise(rng, seckey).Secure
5650
of SecureProtocol.Secio:
57-
secureManagerInstances &= newSecio(rng, seckey).Secure
51+
quit("Secio is deprecated!") # use of secio is unsafe
5852

5953
let switch = newSwitch(
6054
peerInfo,

tests/pubsub/testgossipsub.nim

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ suite "GossipSub":
324324
let
325325
nodes = generateNodes(
326326
2,
327-
gossip = true,
328-
secureManagers = [SecureProtocol.Noise])
327+
gossip = true)
329328

330329
# start switches
331330
nodesFut = await allFinished(
@@ -372,8 +371,7 @@ suite "GossipSub":
372371
let
373372
nodes = generateNodes(
374373
2,
375-
gossip = true,
376-
secureManagers = [SecureProtocol.Secio])
374+
gossip = true)
377375

378376
# start switches
379377
nodesFut = await allFinished(
@@ -437,8 +435,7 @@ suite "GossipSub":
437435
let
438436
nodes = generateNodes(
439437
2,
440-
gossip = true,
441-
secureManagers = [SecureProtocol.Secio])
438+
gossip = true)
442439

443440
# start switches
444441
nodesFut = await allFinished(
@@ -509,8 +506,7 @@ suite "GossipSub":
509506
let
510507
nodes = generateNodes(
511508
2,
512-
gossip = true,
513-
secureManagers = [SecureProtocol.Secio])
509+
gossip = true)
514510

515511
# start switches
516512
nodesFut = await allFinished(

tests/testinterop.nim

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ proc testPubSubDaemonPublish(gossip: bool = false, count: int = 1) {.async.} =
6969

7070
let daemonNode = await newDaemonApi(flags)
7171
let daemonPeer = await daemonNode.identity()
72-
let nativeNode = newStandardSwitch(
73-
secureManagers = [SecureProtocol.Noise],
74-
outTimeout = 5.minutes)
72+
let nativeNode = newStandardSwitch(outTimeout = 5.minutes)
7573

7674
let pubsub = if gossip:
7775
GossipSub.init(
@@ -135,9 +133,7 @@ proc testPubSubNodePublish(gossip: bool = false, count: int = 1) {.async.} =
135133

136134
let daemonNode = await newDaemonApi(flags)
137135
let daemonPeer = await daemonNode.identity()
138-
let nativeNode = newStandardSwitch(
139-
secureManagers = [SecureProtocol.Noise],
140-
outTimeout = 5.minutes)
136+
let nativeNode = newStandardSwitch(outTimeout = 5.minutes)
141137

142138
let pubsub = if gossip:
143139
GossipSub.init(

tests/testswitch.nim

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ suite "Switch":
140140
testProto.codec = TestCodec
141141
testProto.handler = handle
142142

143-
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
143+
let switch1 = newStandardSwitch()
144144
switch1.mount(testProto)
145145

146-
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
146+
let switch2 = newStandardSwitch()
147147
var awaiters: seq[Future[void]]
148148
awaiters.add(await switch1.start())
149149
awaiters.add(await switch2.start())
@@ -215,8 +215,8 @@ suite "Switch":
215215
asyncTest "e2e should not leak on peer disconnect":
216216
var awaiters: seq[Future[void]]
217217

218-
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
219-
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
218+
let switch1 = newStandardSwitch()
219+
let switch2 = newStandardSwitch()
220220
awaiters.add(await switch1.start())
221221
awaiters.add(await switch2.start())
222222

@@ -241,8 +241,8 @@ suite "Switch":
241241
asyncTest "e2e should trigger connection events (remote)":
242242
var awaiters: seq[Future[void]]
243243

244-
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
245-
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
244+
let switch1 = newStandardSwitch()
245+
let switch2 = newStandardSwitch()
246246

247247
var step = 0
248248
var kinds: set[ConnEventKind]
@@ -296,8 +296,8 @@ suite "Switch":
296296
asyncTest "e2e should trigger connection events (local)":
297297
var awaiters: seq[Future[void]]
298298

299-
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
300-
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
299+
let switch1 = newStandardSwitch()
300+
let switch2 = newStandardSwitch()
301301

302302
var step = 0
303303
var kinds: set[ConnEventKind]
@@ -351,8 +351,8 @@ suite "Switch":
351351
asyncTest "e2e should trigger peer events (remote)":
352352
var awaiters: seq[Future[void]]
353353

354-
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
355-
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
354+
let switch1 = newStandardSwitch()
355+
let switch2 = newStandardSwitch()
356356

357357
var step = 0
358358
var kinds: set[PeerEventKind]
@@ -405,8 +405,8 @@ suite "Switch":
405405
asyncTest "e2e should trigger peer events (local)":
406406
var awaiters: seq[Future[void]]
407407

408-
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
409-
let switch2 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
408+
let switch1 = newStandardSwitch()
409+
let switch2 = newStandardSwitch()
410410

411411
var step = 0
412412
var kinds: set[PeerEventKind]
@@ -459,20 +459,18 @@ suite "Switch":
459459
asyncTest "e2e should trigger peer events only once per peer":
460460
var awaiters: seq[Future[void]]
461461

462-
let switch1 = newStandardSwitch(secureManagers = [SecureProtocol.Secio])
462+
let switch1 = newStandardSwitch()
463463

464464
let rng = newRng()
465465
# use same private keys to emulate two connection from same peer
466466
let privKey = PrivateKey.random(rng[]).tryGet()
467467
let switch2 = newStandardSwitch(
468468
privKey = some(privKey),
469-
rng = rng,
470-
secureManagers = [SecureProtocol.Secio])
469+
rng = rng)
471470

472471
let switch3 = newStandardSwitch(
473472
privKey = some(privKey),
474-
rng = rng,
475-
secureManagers = [SecureProtocol.Secio])
473+
rng = rng)
476474

477475
var step = 0
478476
var kinds: set[PeerEventKind]
@@ -548,17 +546,15 @@ suite "Switch":
548546
done.complete()
549547

550548
switches.add(newStandardSwitch(
551-
rng = rng,
552-
secureManagers = [SecureProtocol.Secio]))
549+
rng = rng))
553550

554551
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
555552
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
556553
awaiters.add(await switches[0].start())
557554

558555
switches.add(newStandardSwitch(
559556
privKey = some(peerInfo.privateKey),
560-
rng = rng,
561-
secureManagers = [SecureProtocol.Secio]))
557+
rng = rng))
562558
onConnect = switches[1].connect(switches[0].peerInfo)
563559
await onConnect
564560

@@ -597,8 +593,7 @@ suite "Switch":
597593
conns.dec
598594

599595
switches.add(newStandardSwitch(
600-
rng = rng,
601-
secureManagers = [SecureProtocol.Secio]))
596+
rng = rng))
602597

603598
switches[0].addConnEventHandler(hook, ConnEventKind.Connected)
604599
switches[0].addConnEventHandler(hook, ConnEventKind.Disconnected)
@@ -607,8 +602,7 @@ suite "Switch":
607602
for i in 1..5:
608603
switches.add(newStandardSwitch(
609604
privKey = some(peerInfo.privateKey),
610-
rng = rng,
611-
secureManagers = [SecureProtocol.Secio]))
605+
rng = rng))
612606
onConnect = switches[i].connect(switches[0].peerInfo)
613607
await onConnect
614608

0 commit comments

Comments
 (0)