mirror of https://github.com/vacp2p/nim-libp2p.git
fixes after building with 0.20.2
This commit is contained in:
parent
bb277d4b56
commit
3194e3ac5b
|
@ -102,7 +102,7 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} =
|
||||||
if size > 0.uint:
|
if size > 0.uint:
|
||||||
await s.readExactly(addr result[0], int(size))
|
await s.readExactly(addr result[0], int(size))
|
||||||
except LPStreamIncompleteError, LPStreamReadError:
|
except LPStreamIncompleteError, LPStreamReadError:
|
||||||
warn "readLp: could not read from remote, this is usually ok", exception = getCurrentExceptionMsg()
|
trace "remote connection closed", exc = getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc writeLp*(s: Connection, msg: string | seq[byte]): Future[void] {.gcsafe.} =
|
proc writeLp*(s: Connection, msg: string | seq[byte]): Future[void] {.gcsafe.} =
|
||||||
## write lenght prefixed
|
## write lenght prefixed
|
||||||
|
|
|
@ -22,11 +22,10 @@ const
|
||||||
Codec* = "/multistream/1.0.0"
|
Codec* = "/multistream/1.0.0"
|
||||||
|
|
||||||
MSCodec* = "\x13" & Codec & "\n"
|
MSCodec* = "\x13" & Codec & "\n"
|
||||||
Na = "\x03na\n"
|
Na* = "\x03na\n"
|
||||||
Ls = "\x03ls\n"
|
Ls* = "\x03ls\n"
|
||||||
|
|
||||||
type
|
type
|
||||||
MultisteamSelectException = object of CatchableError
|
|
||||||
Matcher* = proc (proto: string): bool {.gcsafe.}
|
Matcher* = proc (proto: string): bool {.gcsafe.}
|
||||||
|
|
||||||
HandlerHolder* = object
|
HandlerHolder* = object
|
||||||
|
|
|
@ -32,9 +32,6 @@ type
|
||||||
currentId*: uint
|
currentId*: uint
|
||||||
maxChannels*: uint
|
maxChannels*: uint
|
||||||
|
|
||||||
proc newMplexUnknownMsgError(): ref MplexUnknownMsgError =
|
|
||||||
result = newException(MplexUnknownMsgError, "Unknown mplex message type")
|
|
||||||
|
|
||||||
proc getChannelList(m: Mplex, initiator: bool): var Table[uint, LPChannel] =
|
proc getChannelList(m: Mplex, initiator: bool): var Table[uint, LPChannel] =
|
||||||
if initiator:
|
if initiator:
|
||||||
result = m.remote
|
result = m.remote
|
||||||
|
@ -102,7 +99,6 @@ method handle*(m: Mplex) {.async, gcsafe.} =
|
||||||
trace "handle: resetting channel ", id = id
|
trace "handle: resetting channel ", id = id
|
||||||
await channel.resetByRemote()
|
await channel.resetByRemote()
|
||||||
break
|
break
|
||||||
else: raise newMplexUnknownMsgError()
|
|
||||||
except:
|
except:
|
||||||
error "exception occurred", exception = getCurrentExceptionMsg()
|
error "exception occurred", exception = getCurrentExceptionMsg()
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -16,7 +16,6 @@ const MplexCodec* = "/mplex/6.7.0"
|
||||||
const MaxReadWriteTime* = 5.seconds
|
const MaxReadWriteTime* = 5.seconds
|
||||||
|
|
||||||
type
|
type
|
||||||
MplexUnknownMsgError* = object of CatchableError
|
|
||||||
MplexNoSuchChannel* = object of CatchableError
|
MplexNoSuchChannel* = object of CatchableError
|
||||||
|
|
||||||
MessageType* {.pure.} = enum
|
MessageType* {.pure.} = enum
|
||||||
|
|
|
@ -100,5 +100,4 @@ method close*(s: ChronosStream) {.async, gcsafe.} =
|
||||||
await s.writer.closeWait()
|
await s.writer.closeWait()
|
||||||
await s.reader.closeWait()
|
await s.reader.closeWait()
|
||||||
await s.client.closeWait()
|
await s.client.closeWait()
|
||||||
|
|
||||||
s.closed = true
|
s.closed = true
|
||||||
|
|
|
@ -57,7 +57,7 @@ proc newTestSelectStream(): TestSelectStream =
|
||||||
|
|
||||||
## Mock stream for handles `ls` test
|
## Mock stream for handles `ls` test
|
||||||
type
|
type
|
||||||
LsHandler = proc(procs: seq[byte]): Future[void]
|
LsHandler = proc(procs: seq[byte]): Future[void] {.gcsafe.}
|
||||||
|
|
||||||
TestLsStream = ref object of LPStream
|
TestLsStream = ref object of LPStream
|
||||||
step*: int
|
step*: int
|
||||||
|
@ -66,7 +66,7 @@ type
|
||||||
method readExactly*(s: TestLsStream,
|
method readExactly*(s: TestLsStream,
|
||||||
pbytes: pointer,
|
pbytes: pointer,
|
||||||
nbytes: int):
|
nbytes: int):
|
||||||
Future[void] {.async, gcsafe.} =
|
Future[void] {.async.} =
|
||||||
case s.step:
|
case s.step:
|
||||||
of 1:
|
of 1:
|
||||||
var buf = newSeq[byte](1)
|
var buf = newSeq[byte](1)
|
||||||
|
@ -86,7 +86,7 @@ method readExactly*(s: TestLsStream,
|
||||||
var buf = "ls\n"
|
var buf = "ls\n"
|
||||||
copyMem(pbytes, addr buf[0], buf.len())
|
copyMem(pbytes, addr buf[0], buf.len())
|
||||||
else:
|
else:
|
||||||
copyMem(pbytes, cstring("\0x3na\n"), "\0x3na\n".len())
|
copyMem(pbytes, cstring(Na), Na.len())
|
||||||
|
|
||||||
method write*(s: TestLsStream, msg: seq[byte], msglen = -1) {.async, gcsafe.} =
|
method write*(s: TestLsStream, msg: seq[byte], msglen = -1) {.async, gcsafe.} =
|
||||||
if s.step == 4:
|
if s.step == 4:
|
||||||
|
@ -97,14 +97,14 @@ method write*(s: TestLsStream, msg: string, msglen = -1)
|
||||||
|
|
||||||
method close(s: TestLsStream) {.async, gcsafe.} = s.closed = true
|
method close(s: TestLsStream) {.async, gcsafe.} = s.closed = true
|
||||||
|
|
||||||
proc newTestLsStream(ls: LsHandler): TestLsStream =
|
proc newTestLsStream(ls: LsHandler): TestLsStream {.gcsafe.} =
|
||||||
new result
|
new result
|
||||||
result.ls = ls
|
result.ls = ls
|
||||||
result.step = 1
|
result.step = 1
|
||||||
|
|
||||||
## Mock stream for handles `na` test
|
## Mock stream for handles `na` test
|
||||||
type
|
type
|
||||||
NaHandler = proc(procs: string): Future[void]
|
NaHandler = proc(procs: string): Future[void] {.gcsafe.}
|
||||||
|
|
||||||
TestNaStream = ref object of LPStream
|
TestNaStream = ref object of LPStream
|
||||||
step*: int
|
step*: int
|
||||||
|
@ -185,10 +185,9 @@ suite "Multistream select":
|
||||||
proc testLs(): Future[bool] {.async.} =
|
proc testLs(): Future[bool] {.async.} =
|
||||||
let ms = newMultistream()
|
let ms = newMultistream()
|
||||||
|
|
||||||
proc testLs(proto: seq[byte]): Future[void] {.async.}
|
proc testLsHandler(proto: seq[byte]) {.async, gcsafe.} # forward declaration
|
||||||
let conn = newConnection(newTestLsStream(testLs))
|
let conn = newConnection(newTestLsStream(testLsHandler))
|
||||||
|
proc testLsHandler(proto: seq[byte]) {.async, gcsafe.} =
|
||||||
proc testLs(proto: seq[byte]): Future[void] {.async.} =
|
|
||||||
var strProto: string = cast[string](proto)
|
var strProto: string = cast[string](proto)
|
||||||
check strProto == "\x26/test/proto1/1.0.0\n/test/proto2/1.0.0\n"
|
check strProto == "\x26/test/proto1/1.0.0\n/test/proto2/1.0.0\n"
|
||||||
await conn.close()
|
await conn.close()
|
||||||
|
@ -198,8 +197,8 @@ suite "Multistream select":
|
||||||
peerInfo.peerId = some(PeerID.init(seckey))
|
peerInfo.peerId = some(PeerID.init(seckey))
|
||||||
var protocol: LPProtocol = new LPProtocol
|
var protocol: LPProtocol = new LPProtocol
|
||||||
proc testHandler(conn: Connection,
|
proc testHandler(conn: Connection,
|
||||||
proto: string):
|
proto: string):
|
||||||
Future[void] {.async, gcsafe.} = discard
|
Future[void] {.async, gcsafe.} = discard
|
||||||
protocol.handler = testHandler
|
protocol.handler = testHandler
|
||||||
ms.addHandler("/test/proto1/1.0.0", protocol)
|
ms.addHandler("/test/proto1/1.0.0", protocol)
|
||||||
ms.addHandler("/test/proto2/1.0.0", protocol)
|
ms.addHandler("/test/proto2/1.0.0", protocol)
|
||||||
|
@ -213,11 +212,11 @@ suite "Multistream select":
|
||||||
proc testNa(): Future[bool] {.async.} =
|
proc testNa(): Future[bool] {.async.} =
|
||||||
let ms = newMultistream()
|
let ms = newMultistream()
|
||||||
|
|
||||||
proc testNa(msg: string): Future[void] {.async.}
|
proc testNaHandler(msg: string): Future[void] {.async, gcsafe.}
|
||||||
let conn = newConnection(newTestNaStream(testNa))
|
let conn = newConnection(newTestNaStream(testNaHandler))
|
||||||
|
|
||||||
proc testNa(msg: string): Future[void] {.async.} =
|
proc testNaHandler(msg: string): Future[void] {.async, gcsafe.} =
|
||||||
check cast[string](msg) == "\x3na\n"
|
check cast[string](msg) == Na
|
||||||
await conn.close()
|
await conn.close()
|
||||||
|
|
||||||
let seckey = PrivateKey.random(RSA)
|
let seckey = PrivateKey.random(RSA)
|
||||||
|
@ -238,7 +237,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
test "e2e - handle":
|
test "e2e - handle":
|
||||||
proc endToEnd(): Future[bool] {.async.} =
|
proc endToEnd(): Future[bool] {.async.} =
|
||||||
let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53350")
|
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
|
||||||
|
|
||||||
let seckey = PrivateKey.random(RSA)
|
let seckey = PrivateKey.random(RSA)
|
||||||
var peerInfo: PeerInfo
|
var peerInfo: PeerInfo
|
||||||
|
@ -263,7 +262,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
let msDial = newMultistream()
|
let msDial = newMultistream()
|
||||||
let transport2: TcpTransport = newTransport(TcpTransport)
|
let transport2: TcpTransport = newTransport(TcpTransport)
|
||||||
let conn = await transport2.dial(ma)
|
let conn = await transport2.dial(transport1.ma)
|
||||||
|
|
||||||
check (await msDial.select(conn, "/test/proto/1.0.0")) == true
|
check (await msDial.select(conn, "/test/proto/1.0.0")) == true
|
||||||
|
|
||||||
|
@ -276,7 +275,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
test "e2e - ls":
|
test "e2e - ls":
|
||||||
proc endToEnd(): Future[bool] {.async.} =
|
proc endToEnd(): Future[bool] {.async.} =
|
||||||
let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53351")
|
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
|
||||||
|
|
||||||
let msListen = newMultistream()
|
let msListen = newMultistream()
|
||||||
let seckey = PrivateKey.random(RSA)
|
let seckey = PrivateKey.random(RSA)
|
||||||
|
@ -299,7 +298,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
let msDial = newMultistream()
|
let msDial = newMultistream()
|
||||||
let transport2: TcpTransport = newTransport(TcpTransport)
|
let transport2: TcpTransport = newTransport(TcpTransport)
|
||||||
let conn = await transport2.dial(ma)
|
let conn = await transport2.dial(transport1.ma)
|
||||||
|
|
||||||
let ls = await msDial.list(conn)
|
let ls = await msDial.list(conn)
|
||||||
let protos: seq[string] = @["/test/proto1/1.0.0", "/test/proto2/1.0.0"]
|
let protos: seq[string] = @["/test/proto1/1.0.0", "/test/proto2/1.0.0"]
|
||||||
|
@ -311,7 +310,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
test "e2e - select one from a list with unsupported protos":
|
test "e2e - select one from a list with unsupported protos":
|
||||||
proc endToEnd(): Future[bool] {.async.} =
|
proc endToEnd(): Future[bool] {.async.} =
|
||||||
let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53352")
|
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
|
||||||
|
|
||||||
let seckey = PrivateKey.random(RSA)
|
let seckey = PrivateKey.random(RSA)
|
||||||
var peerInfo: PeerInfo
|
var peerInfo: PeerInfo
|
||||||
|
@ -336,7 +335,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
let msDial = newMultistream()
|
let msDial = newMultistream()
|
||||||
let transport2: TcpTransport = newTransport(TcpTransport)
|
let transport2: TcpTransport = newTransport(TcpTransport)
|
||||||
let conn = await transport2.dial(ma)
|
let conn = await transport2.dial(transport1.ma)
|
||||||
|
|
||||||
check (await msDial.select(conn,
|
check (await msDial.select(conn,
|
||||||
@["/test/proto/1.0.0", "/test/no/proto/1.0.0"])) == "/test/proto/1.0.0"
|
@["/test/proto/1.0.0", "/test/no/proto/1.0.0"])) == "/test/proto/1.0.0"
|
||||||
|
@ -350,7 +349,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
test "e2e - select one with both valid":
|
test "e2e - select one with both valid":
|
||||||
proc endToEnd(): Future[bool] {.async.} =
|
proc endToEnd(): Future[bool] {.async.} =
|
||||||
let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53353")
|
let ma: MultiAddress = Multiaddress.init("/ip4/0.0.0.0/tcp/0")
|
||||||
|
|
||||||
let seckey = PrivateKey.random(RSA)
|
let seckey = PrivateKey.random(RSA)
|
||||||
var peerInfo: PeerInfo
|
var peerInfo: PeerInfo
|
||||||
|
@ -375,7 +374,7 @@ suite "Multistream select":
|
||||||
|
|
||||||
let msDial = newMultistream()
|
let msDial = newMultistream()
|
||||||
let transport2: TcpTransport = newTransport(TcpTransport)
|
let transport2: TcpTransport = newTransport(TcpTransport)
|
||||||
let conn = await transport2.dial(ma)
|
let conn = await transport2.dial(transport1.ma)
|
||||||
|
|
||||||
check (await msDial.select(conn, @["/test/proto2/1.0.0", "/test/proto1/1.0.0"])) == "/test/proto2/1.0.0"
|
check (await msDial.select(conn, @["/test/proto2/1.0.0", "/test/proto1/1.0.0"])) == "/test/proto2/1.0.0"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue