mirror of https://github.com/vacp2p/nim-libp2p.git
use set[ServerFlags] params instead of hardcoded flags
This commit is contained in:
parent
125843af7d
commit
c480e65055
|
@ -22,6 +22,8 @@ import connection,
|
|||
errors,
|
||||
peer
|
||||
|
||||
export ServerFlags
|
||||
|
||||
logScope:
|
||||
topic = "Switch"
|
||||
|
||||
|
@ -282,7 +284,7 @@ proc mount*[T: LPProtocol](s: Switch, proto: T) {.gcsafe.} =
|
|||
|
||||
s.ms.addHandler(proto.codec, proto)
|
||||
|
||||
proc start*(s: Switch): Future[seq[Future[void]]] {.async, gcsafe.} =
|
||||
proc start*(s: Switch, serverFlags: set[ServerFlags] = {}): Future[seq[Future[void]]] {.async, gcsafe.} =
|
||||
trace "starting switch"
|
||||
|
||||
proc handle(conn: Connection): Future[void] {.async, closure, gcsafe.} =
|
||||
|
@ -298,7 +300,7 @@ proc start*(s: Switch): Future[seq[Future[void]]] {.async, gcsafe.} =
|
|||
for t in s.transports: # for each transport
|
||||
for i, a in s.peerInfo.addrs:
|
||||
if t.handles(a): # check if it handles the multiaddr
|
||||
var server = await t.listen(a, handle)
|
||||
var server = await t.listen(a, handle, serverFlags)
|
||||
s.peerInfo.addrs[i] = t.ma # update peer's address
|
||||
startFuts.add(server)
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ import transport,
|
|||
../multicodec,
|
||||
../stream/chronosstream
|
||||
|
||||
export ServerFlags
|
||||
|
||||
logScope:
|
||||
topic = "TcpTransport"
|
||||
|
||||
|
@ -122,12 +124,13 @@ method close*(t: TcpTransport) {.async, gcsafe.} =
|
|||
|
||||
method listen*(t: TcpTransport,
|
||||
ma: MultiAddress,
|
||||
handler: ConnHandler):
|
||||
handler: ConnHandler,
|
||||
serverFlags: set[ServerFlags] = {}):
|
||||
Future[Future[void]] {.async, gcsafe.} =
|
||||
discard await procCall Transport(t).listen(ma, handler) # call base
|
||||
|
||||
## listen on the transport
|
||||
t.server = createStreamServer(t.ma, connCb, {ReuseAddr}, t)
|
||||
t.server = createStreamServer(t.ma, connCb, serverFlags, t)
|
||||
t.server.start()
|
||||
|
||||
# always get the resolved address in case we're bound to 0.0.0.0:0
|
||||
|
|
|
@ -14,6 +14,8 @@ import ../connection,
|
|||
../multicodec,
|
||||
../errors
|
||||
|
||||
export ServerFlags
|
||||
|
||||
type
|
||||
ConnHandler* = proc (conn: Connection): Future[void] {.gcsafe.}
|
||||
|
||||
|
@ -39,7 +41,8 @@ method close*(t: Transport) {.base, async, gcsafe.} =
|
|||
|
||||
method listen*(t: Transport,
|
||||
ma: MultiAddress,
|
||||
handler: ConnHandler):
|
||||
handler: ConnHandler,
|
||||
serverFlags: set[ServerFlags] = {}):
|
||||
Future[Future[void]] {.base, async, gcsafe.} =
|
||||
## listen for incoming connections
|
||||
t.ma = ma
|
||||
|
|
Loading…
Reference in New Issue