remove Chronos type from public API
This commit is contained in:
parent
313f9b0952
commit
268253ea18
|
@ -6,7 +6,6 @@ const
|
|||
|
||||
import
|
||||
options, tables,
|
||||
chronos,
|
||||
switch, peer, peerinfo, connection, multiaddress,
|
||||
crypto/crypto, transports/[transport, tcptransport],
|
||||
muxers/[muxer, mplex/mplex, mplex/types],
|
||||
|
@ -19,7 +18,7 @@ else:
|
|||
import protocols/secure/secio
|
||||
|
||||
export
|
||||
switch, peer, peerinfo, connection, multiaddress, crypto, ServerFlags
|
||||
switch, peer, peerinfo, connection, multiaddress, crypto
|
||||
|
||||
proc newStandardSwitch*(privKey = none(PrivateKey),
|
||||
address = MultiAddress.init("/ip4/127.0.0.1/tcp/0"),
|
||||
|
@ -27,7 +26,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
|||
gossip = false,
|
||||
verifySignature = libp2p_pubsub_verify,
|
||||
sign = libp2p_pubsub_sign,
|
||||
serverFlags: set[ServerFlags] = {}): Switch =
|
||||
transportFlags: TransportFlags = {}): Switch =
|
||||
proc createMplex(conn: Connection): Muxer =
|
||||
result = newMplex(conn)
|
||||
|
||||
|
@ -35,7 +34,7 @@ proc newStandardSwitch*(privKey = none(PrivateKey),
|
|||
seckey = privKey.get(otherwise = PrivateKey.random(ECDSA))
|
||||
peerInfo = PeerInfo.init(seckey, [address])
|
||||
mplexProvider = newMuxerProvider(createMplex, MplexCodec)
|
||||
transports = @[Transport(newTransport(TcpTransport, serverFlags))]
|
||||
transports = @[Transport(newTransport(TcpTransport, transportFlags))]
|
||||
muxers = {MplexCodec: mplexProvider}.toTable
|
||||
identify = newIdentify(peerInfo)
|
||||
when libp2p_secure == "noise":
|
||||
|
|
|
@ -127,7 +127,7 @@ method listen*(t: TcpTransport,
|
|||
discard await procCall Transport(t).listen(ma, handler) # call base
|
||||
|
||||
## 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()
|
||||
|
||||
# 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
|
||||
## those terms.
|
||||
|
||||
import sequtils
|
||||
import sequtils, tables
|
||||
import chronos, chronicles
|
||||
import ../connection,
|
||||
../multiaddress,
|
||||
../multicodec,
|
||||
../errors
|
||||
|
||||
export ServerFlags
|
||||
|
||||
type
|
||||
ConnHandler* = proc (conn: Connection): Future[void] {.gcsafe.}
|
||||
|
||||
TransportFlag* {.pure.} = enum
|
||||
ReuseAddr
|
||||
|
||||
TransportFlags* = set[TransportFlag]
|
||||
|
||||
Transport* = ref object of RootObj
|
||||
ma*: Multiaddress
|
||||
connections*: seq[Connection]
|
||||
handler*: ConnHandler
|
||||
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.} =
|
||||
## perform protocol initialization
|
||||
discard
|
||||
|
||||
proc newTransport*(t: typedesc[Transport], serverFlags: set[ServerFlags] = {}): t {.gcsafe.} =
|
||||
proc newTransport*(t: typedesc[Transport], flags: TransportFlags = {}): t {.gcsafe.} =
|
||||
new result
|
||||
result.serverFlags = serverFlags
|
||||
result.flags = flags
|
||||
result.init()
|
||||
|
||||
method close*(t: Transport) {.base, async, gcsafe.} =
|
||||
|
|
Loading…
Reference in New Issue