mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-02-26 15:10:49 +00:00
remove Chronos type from public API
This commit is contained in:
parent
313f9b0952
commit
268253ea18
@ -6,7 +6,6 @@ const
|
|||||||
|
|
||||||
import
|
import
|
||||||
options, tables,
|
options, tables,
|
||||||
chronos,
|
|
||||||
switch, peer, peerinfo, connection, multiaddress,
|
switch, peer, peerinfo, connection, multiaddress,
|
||||||
crypto/crypto, transports/[transport, tcptransport],
|
crypto/crypto, transports/[transport, tcptransport],
|
||||||
muxers/[muxer, mplex/mplex, mplex/types],
|
muxers/[muxer, mplex/mplex, mplex/types],
|
||||||
@ -19,7 +18,7 @@ else:
|
|||||||
import protocols/secure/secio
|
import protocols/secure/secio
|
||||||
|
|
||||||
export
|
export
|
||||||
switch, peer, peerinfo, connection, multiaddress, crypto, ServerFlags
|
switch, peer, peerinfo, connection, multiaddress, crypto
|
||||||
|
|
||||||
proc newStandardSwitch*(privKey = none(PrivateKey),
|
proc newStandardSwitch*(privKey = none(PrivateKey),
|
||||||
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0"),
|
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0"),
|
||||||
@ -27,7 +26,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
|||||||
gossip = false,
|
gossip = false,
|
||||||
verifySignature = libp2p_pubsub_verify,
|
verifySignature = libp2p_pubsub_verify,
|
||||||
sign = libp2p_pubsub_sign,
|
sign = libp2p_pubsub_sign,
|
||||||
serverFlags: set[ServerFlags] = {}): Switch =
|
transportFlags: TransportFlags = {}): Switch =
|
||||||
proc createMplex(conn: Connection): Muxer =
|
proc createMplex(conn: Connection): Muxer =
|
||||||
result = newMplex(conn)
|
result = newMplex(conn)
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
|||||||
seckey = privKey.get(otherwise = PrivateKey.random(ECDSA))
|
seckey = privKey.get(otherwise = PrivateKey.random(ECDSA))
|
||||||
peerInfo = PeerInfo.init(seckey, [address])
|
peerInfo = PeerInfo.init(seckey, [address])
|
||||||
mplexProvider = newMuxerProvider(createMplex, MplexCodec)
|
mplexProvider = newMuxerProvider(createMplex, MplexCodec)
|
||||||
transports = @[Transport(newTransport(TcpTransport, serverFlags))]
|
transports = @[Transport(newTransport(TcpTransport, transportFlags))]
|
||||||
muxers = {MplexCodec: mplexProvider}.toTable
|
muxers = {MplexCodec: mplexProvider}.toTable
|
||||||
identify = newIdentify(peerInfo)
|
identify = newIdentify(peerInfo)
|
||||||
when libp2p_secure == "noise":
|
when libp2p_secure == "noise":
|
||||||
|
@ -127,7 +127,7 @@ method listen*(t: TcpTransport,
|
|||||||
discard await procCall Transport(t).listen(ma, handler) # call base
|
discard await procCall Transport(t).listen(ma, handler) # call base
|
||||||
|
|
||||||
## listen on the transport
|
## listen on the transport
|
||||||
t.server = createStreamServer(t.ma, connCb, t.serverFlags, t)
|
t.server = createStreamServer(t.ma, connCb, transportFlagsToServerFlags(t.flags), t)
|
||||||
t.server.start()
|
t.server.start()
|
||||||
|
|
||||||
# always get the resolved address in case we're bound to 0.0.0.0:0
|
# always get the resolved address in case we're bound to 0.0.0.0:0
|
||||||
|
@ -7,32 +7,43 @@
|
|||||||
## This file may not be copied, modified, or distributed except according to
|
## This file may not be copied, modified, or distributed except according to
|
||||||
## those terms.
|
## those terms.
|
||||||
|
|
||||||
import sequtils
|
import sequtils, tables
|
||||||
import chronos, chronicles
|
import chronos, chronicles
|
||||||
import ../connection,
|
import ../connection,
|
||||||
../multiaddress,
|
../multiaddress,
|
||||||
../multicodec,
|
../multicodec,
|
||||||
../errors
|
../errors
|
||||||
|
|
||||||
export ServerFlags
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ConnHandler* = proc (conn: Connection): Future[void] {.gcsafe.}
|
ConnHandler* = proc (conn: Connection): Future[void] {.gcsafe.}
|
||||||
|
|
||||||
|
TransportFlag* {.pure.} = enum
|
||||||
|
ReuseAddr
|
||||||
|
|
||||||
|
TransportFlags* = set[TransportFlag]
|
||||||
|
|
||||||
Transport* = ref object of RootObj
|
Transport* = ref object of RootObj
|
||||||
ma*: Multiaddress
|
ma*: Multiaddress
|
||||||
connections*: seq[Connection]
|
connections*: seq[Connection]
|
||||||
handler*: ConnHandler
|
handler*: ConnHandler
|
||||||
multicodec*: MultiCodec
|
multicodec*: MultiCodec
|
||||||
serverFlags*: set[ServerFlags]
|
flags*: TransportFlags
|
||||||
|
|
||||||
|
proc transportFlagsToServerFlags*(flags: TransportFlags): set[ServerFlags] {.gcsafe.} =
|
||||||
|
let transportFlagToServerFlagMapping = {
|
||||||
|
TransportFlag.ReuseAddr: ServerFlags.ReuseAddr,
|
||||||
|
}.toTable()
|
||||||
|
|
||||||
|
for flag in flags:
|
||||||
|
result.incl(transportFlagToServerFlagMapping[flag])
|
||||||
|
|
||||||
method init*(t: Transport) {.base, gcsafe.} =
|
method init*(t: Transport) {.base, gcsafe.} =
|
||||||
## perform protocol initialization
|
## perform protocol initialization
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc newTransport*(t: typedesc[Transport], serverFlags: set[ServerFlags] = {}): t {.gcsafe.} =
|
proc newTransport*(t: typedesc[Transport], flags: TransportFlags = {}): t {.gcsafe.} =
|
||||||
new result
|
new result
|
||||||
result.serverFlags = serverFlags
|
result.flags = flags
|
||||||
result.init()
|
result.init()
|
||||||
|
|
||||||
method close*(t: Transport) {.base, async, gcsafe.} =
|
method close*(t: Transport) {.base, async, gcsafe.} =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user