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,
|
proc init*(C: type ChronosStream,
|
||||||
client: StreamTransport,
|
client: StreamTransport,
|
||||||
dir: Direction,
|
dir: Direction,
|
||||||
timeout = DefaultChronosStreamTimeout): ChronosStream =
|
timeout = DefaultChronosStreamTimeout,
|
||||||
|
observedAddr: MultiAddress = MultiAddress()): ChronosStream =
|
||||||
result = C(client: client,
|
result = C(client: client,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
dir: dir)
|
dir: dir,
|
||||||
|
observedAddr: observedAddr)
|
||||||
result.initStream()
|
result.initStream()
|
||||||
|
|
||||||
template withExceptions(body: untyped) =
|
template withExceptions(body: untyped) =
|
||||||
|
|
|
@ -110,10 +110,12 @@ proc init*(C: type Connection,
|
||||||
peerInfo: PeerInfo,
|
peerInfo: PeerInfo,
|
||||||
dir: Direction,
|
dir: Direction,
|
||||||
timeout: Duration = DefaultConnectionTimeout,
|
timeout: Duration = DefaultConnectionTimeout,
|
||||||
timeoutHandler: TimeoutHandler = nil): Connection =
|
timeoutHandler: TimeoutHandler = nil,
|
||||||
|
observedAddr: MultiAddress = MultiAddress()): Connection =
|
||||||
result = C(peerInfo: peerInfo,
|
result = C(peerInfo: peerInfo,
|
||||||
dir: dir,
|
dir: dir,
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
timeoutHandler: timeoutHandler)
|
timeoutHandler: timeoutHandler,
|
||||||
|
observedAddr: observedAddr)
|
||||||
|
|
||||||
result.initStream()
|
result.initStream()
|
||||||
|
|
|
@ -60,15 +60,25 @@ proc setupTcpTransportTracker(): TcpTransportTracker =
|
||||||
proc connHandler*(t: TcpTransport,
|
proc connHandler*(t: TcpTransport,
|
||||||
client: StreamTransport,
|
client: StreamTransport,
|
||||||
dir: Direction): Future[Connection] {.async.} =
|
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,
|
dir = $dir,
|
||||||
clients = t.clients[Direction.In].len +
|
clients = t.clients[Direction.In].len +
|
||||||
t.clients[Direction.Out].len
|
t.clients[Direction.Out].len
|
||||||
|
|
||||||
let conn = Connection(
|
let conn = Connection(
|
||||||
ChronosStream.init(
|
ChronosStream.init(
|
||||||
client,
|
client = client,
|
||||||
dir
|
dir = dir,
|
||||||
|
observedAddr = observedAddr
|
||||||
))
|
))
|
||||||
|
|
||||||
proc onClose() {.async.} =
|
proc onClose() {.async.} =
|
||||||
|
@ -95,15 +105,6 @@ proc connHandler*(t: TcpTransport,
|
||||||
t.clients[dir].add(client)
|
t.clients[dir].add(client)
|
||||||
asyncSpawn onClose()
|
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
|
return conn
|
||||||
|
|
||||||
proc init*(T: type TcpTransport,
|
proc init*(T: type TcpTransport,
|
||||||
|
|
Loading…
Reference in New Issue