diff --git a/libp2p/switch.nim b/libp2p/switch.nim index de1c67c18..182e66b33 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -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) diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index 321b74b98..4746f2361 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -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 diff --git a/libp2p/transports/transport.nim b/libp2p/transports/transport.nim index 72b01ebae..ef40839b2 100644 --- a/libp2p/transports/transport.nim +++ b/libp2p/transports/transport.nim @@ -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