mirror of https://github.com/vacp2p/nim-libp2p.git
Observedaddr (#217)
* send correct observerAddr * run tests with info log level * set observedaddr for channels
This commit is contained in:
parent
f97e2deec7
commit
85b56d0b3a
|
@ -17,7 +17,7 @@ requires "nim >= 1.2.0",
|
||||||
"stew >= 0.1.0"
|
"stew >= 0.1.0"
|
||||||
|
|
||||||
proc runTest(filename: string, verify: bool = true, sign: bool = true) =
|
proc runTest(filename: string, verify: bool = true, sign: bool = true) =
|
||||||
var excstr: string = "nim c -r --opt:speed -d:debug --verbosity:0 --hints:off"
|
var excstr: string = "nim c -r --opt:speed -d:debug --verbosity:0 --hints:off -d:chronicles_log_level=info"
|
||||||
excstr.add(" ")
|
excstr.add(" ")
|
||||||
excstr.add("-d:libp2p_pubsub_sign=" & $sign)
|
excstr.add("-d:libp2p_pubsub_sign=" & $sign)
|
||||||
excstr.add(" ")
|
excstr.add(" ")
|
||||||
|
|
|
@ -29,7 +29,7 @@ type
|
||||||
Connection* = ref object of LPStream
|
Connection* = ref object of LPStream
|
||||||
peerInfo*: PeerInfo
|
peerInfo*: PeerInfo
|
||||||
stream*: LPStream
|
stream*: LPStream
|
||||||
observedAddrs*: Multiaddress
|
observedAddr*: Multiaddress
|
||||||
|
|
||||||
ConnectionTracker* = ref object of TrackerBase
|
ConnectionTracker* = ref object of TrackerBase
|
||||||
opened*: uint64
|
opened*: uint64
|
||||||
|
@ -117,8 +117,8 @@ method close*(s: Connection) {.async, gcsafe.} =
|
||||||
s.isClosed = true
|
s.isClosed = true
|
||||||
|
|
||||||
trace "about to close connection", closed = s.closed,
|
trace "about to close connection", closed = s.closed,
|
||||||
conn = $s,
|
conn = $s,
|
||||||
oid = s.oid
|
oid = s.oid
|
||||||
|
|
||||||
|
|
||||||
if not isNil(s.stream) and not s.stream.closed:
|
if not isNil(s.stream) and not s.stream.closed:
|
||||||
|
@ -137,7 +137,3 @@ method close*(s: Connection) {.async, gcsafe.} =
|
||||||
libp2p_open_connection.dec()
|
libp2p_open_connection.dec()
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "exception closing connections", exc = exc.msg
|
trace "exception closing connections", exc = exc.msg
|
||||||
|
|
||||||
method getObservedAddrs*(c: Connection): Future[MultiAddress] {.base, async, gcsafe.} =
|
|
||||||
## get resolved multiaddresses for the connection
|
|
||||||
result = c.observedAddrs
|
|
||||||
|
|
|
@ -100,6 +100,7 @@ method handle*(m: Mplex) {.async, gcsafe.} =
|
||||||
let stream = newConnection(channel)
|
let stream = newConnection(channel)
|
||||||
m.conns.add(stream)
|
m.conns.add(stream)
|
||||||
stream.peerInfo = m.connection.peerInfo
|
stream.peerInfo = m.connection.peerInfo
|
||||||
|
stream.observedAddr = m.connection.observedAddr
|
||||||
|
|
||||||
var fut = newFuture[void]()
|
var fut = newFuture[void]()
|
||||||
proc handler() {.async.} =
|
proc handler() {.async.} =
|
||||||
|
@ -191,6 +192,7 @@ method newStream*(m: Mplex,
|
||||||
await channel.open()
|
await channel.open()
|
||||||
result = newConnection(channel)
|
result = newConnection(channel)
|
||||||
result.peerInfo = m.connection.peerInfo
|
result.peerInfo = m.connection.peerInfo
|
||||||
|
result.observedAddr = m.connection.observedAddr
|
||||||
|
|
||||||
asyncCheck m.cleanupChann(channel)
|
asyncCheck m.cleanupChann(channel)
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ type
|
||||||
Identify* = ref object of LPProtocol
|
Identify* = ref object of LPProtocol
|
||||||
peerInfo*: PeerInfo
|
peerInfo*: PeerInfo
|
||||||
|
|
||||||
proc encodeMsg*(peerInfo: PeerInfo, observedAddrs: Multiaddress): ProtoBuffer =
|
proc encodeMsg*(peerInfo: PeerInfo, observedAddr: Multiaddress): ProtoBuffer =
|
||||||
result = initProtoBuffer()
|
result = initProtoBuffer()
|
||||||
|
|
||||||
result.write(initProtoField(1, peerInfo.publicKey.get().getBytes().tryGet()))
|
result.write(initProtoField(1, peerInfo.publicKey.get().getBytes().tryGet()))
|
||||||
|
@ -55,7 +55,7 @@ proc encodeMsg*(peerInfo: PeerInfo, observedAddrs: Multiaddress): ProtoBuffer =
|
||||||
for proto in peerInfo.protocols:
|
for proto in peerInfo.protocols:
|
||||||
result.write(initProtoField(3, proto))
|
result.write(initProtoField(3, proto))
|
||||||
|
|
||||||
result.write(initProtoField(4, observedAddrs.data.buffer))
|
result.write(initProtoField(4, observedAddr.data.buffer))
|
||||||
|
|
||||||
let protoVersion = ProtoVersion
|
let protoVersion = ProtoVersion
|
||||||
result.write(initProtoField(5, protoVersion))
|
result.write(initProtoField(5, protoVersion))
|
||||||
|
@ -114,10 +114,11 @@ method init*(p: Identify) =
|
||||||
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
trace "handling identify request"
|
trace "handling identify request", oid = conn.oid
|
||||||
var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs())
|
var pb = encodeMsg(p.peerInfo, conn.observedAddr)
|
||||||
await conn.writeLp(pb.buffer)
|
await conn.writeLp(pb.buffer)
|
||||||
finally:
|
finally:
|
||||||
|
trace "exiting identify handler", oid = conn.oid
|
||||||
await conn.close()
|
await conn.close()
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
trace "exception in identify handler", exc = exc.msg
|
trace "exception in identify handler", exc = exc.msg
|
||||||
|
@ -148,10 +149,9 @@ proc identify*(p: Identify,
|
||||||
remote = peer.pretty(),
|
remote = peer.pretty(),
|
||||||
local = remotePeerInfo.id
|
local = remotePeerInfo.id
|
||||||
|
|
||||||
raise newException(IdentityNoMatchError,
|
raise newException(IdentityNoMatchError, "Peer ids don't match")
|
||||||
"Peer ids don't match")
|
|
||||||
|
|
||||||
proc push*(p: Identify, conn: Connection) {.async.} =
|
proc push*(p: Identify, conn: Connection) {.async.} =
|
||||||
await conn.write(IdentifyPushCodec)
|
await conn.write(IdentifyPushCodec)
|
||||||
var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs())
|
var pb = encodeMsg(p.peerInfo, conn.observedAddr)
|
||||||
await conn.writeLp(pb.buffer)
|
await conn.writeLp(pb.buffer)
|
||||||
|
|
|
@ -32,6 +32,7 @@ proc handleConn*(s: Secure, conn: Connection, initiator: bool): Future[Connectio
|
||||||
var sconn = await s.handshake(conn, initiator)
|
var sconn = await s.handshake(conn, initiator)
|
||||||
|
|
||||||
result = sconn
|
result = sconn
|
||||||
|
result.observedAddr = conn.observedAddr
|
||||||
|
|
||||||
if not isNil(sconn.peerInfo) and sconn.peerInfo.publicKey.isSome:
|
if not isNil(sconn.peerInfo) and sconn.peerInfo.publicKey.isSome:
|
||||||
result.peerInfo = PeerInfo.init(sconn.peerInfo.publicKey.get())
|
result.peerInfo = PeerInfo.init(sconn.peerInfo.publicKey.get())
|
||||||
|
|
|
@ -64,7 +64,7 @@ proc connHandler*(t: TcpTransport,
|
||||||
initiator: bool): Connection =
|
initiator: bool): Connection =
|
||||||
trace "handling connection", address = $client.remoteAddress
|
trace "handling connection", address = $client.remoteAddress
|
||||||
let conn: Connection = newConnection(newChronosStream(client))
|
let conn: Connection = newConnection(newChronosStream(client))
|
||||||
conn.observedAddrs = MultiAddress.init(client.remoteAddress).tryGet()
|
conn.observedAddr = MultiAddress.init(client.remoteAddress).tryGet()
|
||||||
if not initiator:
|
if not initiator:
|
||||||
if not isNil(t.handler):
|
if not isNil(t.handler):
|
||||||
t.handlers &= t.handler(conn)
|
t.handlers &= t.handler(conn)
|
||||||
|
|
Loading…
Reference in New Issue