dont break chronicles logging streamline connsetup (#455)
This commit is contained in:
parent
7b1e652224
commit
ca9c5c85e4
|
@ -41,10 +41,12 @@ method initStream*(s: ChronosStream) =
|
|||
proc init*(C: type ChronosStream,
|
||||
client: StreamTransport,
|
||||
dir: Direction,
|
||||
timeout = DefaultChronosStreamTimeout): ChronosStream =
|
||||
timeout = DefaultChronosStreamTimeout,
|
||||
observedAddr: MultiAddress = MultiAddress()): ChronosStream =
|
||||
result = C(client: client,
|
||||
timeout: timeout,
|
||||
dir: dir)
|
||||
dir: dir,
|
||||
observedAddr: observedAddr)
|
||||
result.initStream()
|
||||
|
||||
template withExceptions(body: untyped) =
|
||||
|
|
|
@ -110,10 +110,12 @@ proc init*(C: type Connection,
|
|||
peerInfo: PeerInfo,
|
||||
dir: Direction,
|
||||
timeout: Duration = DefaultConnectionTimeout,
|
||||
timeoutHandler: TimeoutHandler = nil): Connection =
|
||||
timeoutHandler: TimeoutHandler = nil,
|
||||
observedAddr: MultiAddress = MultiAddress()): Connection =
|
||||
result = C(peerInfo: peerInfo,
|
||||
dir: dir,
|
||||
timeout: timeout,
|
||||
timeoutHandler: timeoutHandler)
|
||||
timeoutHandler: timeoutHandler,
|
||||
observedAddr: observedAddr)
|
||||
|
||||
result.initStream()
|
||||
|
|
|
@ -60,15 +60,25 @@ proc setupTcpTransportTracker(): TcpTransportTracker =
|
|||
proc connHandler*(t: TcpTransport,
|
||||
client: StreamTransport,
|
||||
dir: Direction): Future[Connection] {.async.} =
|
||||
debug "Handling tcp connection", address = $client.remoteAddress,
|
||||
var observedAddr: MultiAddress = MultiAddress()
|
||||
try:
|
||||
observedAddr = MultiAddress.init(client.remoteAddress).tryGet()
|
||||
except CatchableError as exc:
|
||||
trace "Connection setup failed", exc = exc.msg
|
||||
if not(isNil(client) and client.closed):
|
||||
await client.closeWait()
|
||||
raise exc
|
||||
|
||||
debug "Handling tcp connection", address = $observedAddr,
|
||||
dir = $dir,
|
||||
clients = t.clients[Direction.In].len +
|
||||
t.clients[Direction.Out].len
|
||||
|
||||
let conn = Connection(
|
||||
ChronosStream.init(
|
||||
client,
|
||||
dir
|
||||
client = client,
|
||||
dir = dir,
|
||||
observedAddr = observedAddr
|
||||
))
|
||||
|
||||
proc onClose() {.async.} =
|
||||
|
@ -95,15 +105,6 @@ proc connHandler*(t: TcpTransport,
|
|||
t.clients[dir].add(client)
|
||||
asyncSpawn onClose()
|
||||
|
||||
try:
|
||||
conn.observedAddr = MultiAddress.init(client.remoteAddress).tryGet()
|
||||
except CatchableError as exc:
|
||||
trace "Connection setup failed", exc = exc.msg, conn
|
||||
if not(isNil(client) and client.closed):
|
||||
await client.closeWait()
|
||||
|
||||
raise exc
|
||||
|
||||
return conn
|
||||
|
||||
proc init*(T: type TcpTransport,
|
||||
|
|
Loading…
Reference in New Issue