dont break chronicles logging streamline connsetup (#455)

This commit is contained in:
Dmitriy Ryajov 2020-11-25 13:34:48 -06:00 committed by GitHub
parent 7b1e652224
commit ca9c5c85e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 16 deletions

View File

@ -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) =

View File

@ -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()

View File

@ -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,