From 78216aecdbab060ad2264cc0370e53f1545ee943 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 16 Dec 2022 15:25:40 +0100 Subject: [PATCH 1/3] TCP Transport: enable NO_DELAY for clients --- .pinned | 4 ++-- libp2p.nimble | 2 +- libp2p/transports/tcptransport.nim | 8 +++++++- libp2p/wire.nim | 5 +++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.pinned b/.pinned index d54a1d4b31..e7d75a5662 100644 --- a/.pinned +++ b/.pinned @@ -1,6 +1,6 @@ bearssl;https://github.com/status-im/nim-bearssl@#a647994910904b0103a05db3a5ec1ecfc4d91a88 chronicles;https://github.com/status-im/nim-chronicles@#32ac8679680ea699f7dbc046e8e0131cac97d41a -chronos;https://github.com/status-im/nim-chronos@#75d030ff71264513fb9701c75a326cd36fcb4692 +chronos;https://github.com/status-im/nim-chronos@#8b44843d416961f57786579533677c12a9876976 dnsclient;https://github.com/ba0f3/dnsclient.nim@#fcd7443634b950eaea574e5eaa00a628ae029823 faststreams;https://github.com/status-im/nim-faststreams@#b42daf41d8eb4fbce40add6836bed838f8d85b6f httputils;https://github.com/status-im/nim-http-utils@#a85bd52ae0a956983ca6b3267c72961d2ec0245f @@ -9,7 +9,7 @@ metrics;https://github.com/status-im/nim-metrics@#21e99a2e9d9f80e68bef65c80ef781 nimcrypto;https://github.com/cheatfate/nimcrypto@#24e006df85927f64916e60511620583b11403178 secp256k1;https://github.com/status-im/nim-secp256k1@#fd173fdff863ce2e211cf64c9a03bc7539fe40b0 serialization;https://github.com/status-im/nim-serialization@#d77417cba6896c26287a68e6a95762e45a1b87e5 -stew;https://github.com/status-im/nim-stew@#7184d2424dc3945657884646a72715d494917aad +stew;https://github.com/status-im/nim-stew@#f5846de7b2bacecd7dbff9e89d81b4f34385eb31 testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34 unittest2;https://github.com/status-im/nim-unittest2@#da8398c45cafd5bd7772da1fc96e3924a18d3823 websock;https://github.com/status-im/nim-websock@#691f069b209d372b1240d5ae1f57fb7bbafeaba7 diff --git a/libp2p.nimble b/libp2p.nimble index 85ba6bf918..e45bd46399 100644 --- a/libp2p.nimble +++ b/libp2p.nimble @@ -8,11 +8,11 @@ license = "MIT" skipDirs = @["tests", "examples", "Nim", "tools", "scripts", "docs"] requires "nim >= 1.2.0", + "chronos#8b44843", "nimcrypto >= 0.4.1", "dnsclient >= 0.3.0 & < 0.4.0", "bearssl >= 0.1.4", "chronicles >= 0.10.2", - "chronos >= 3.0.6", "metrics", "secp256k1", "stew#head", diff --git a/libp2p/transports/tcptransport.nim b/libp2p/transports/tcptransport.nim index 6d0d321820..e02fb0a56d 100644 --- a/libp2p/transports/tcptransport.nim +++ b/libp2p/transports/tcptransport.nim @@ -42,6 +42,7 @@ type servers*: seq[StreamServer] clients: array[Direction, seq[StreamTransport]] flags: set[ServerFlags] + clientFlags: set[TransportFlags] acceptFuts: seq[Future[StreamTransport]] TcpTransportTracker* = ref object of TrackerBase @@ -131,6 +132,11 @@ proc new*( let transport = T( flags: flags, + clientFlags: + if ServerFlags.TcpNoDelay in flags: + {TransportFlags.TcpNoDelay} + else: + default(set[TransportFlags]), upgrader: upgrade) return transport @@ -252,7 +258,7 @@ method dial*( trace "Dialing remote peer", address = $address - let transp = await connect(address) + let transp = await connect(address, flags = self.clientFlags) try: let observedAddr = await getObservedAddr(transp) return await self.connHandler(transp, Opt.some(observedAddr), Direction.Out) diff --git a/libp2p/wire.nim b/libp2p/wire.nim index 61c0010af5..61ebff64c5 100644 --- a/libp2p/wire.nim +++ b/libp2p/wire.nim @@ -76,7 +76,8 @@ proc initTAddress*(ma: MultiAddress): MaResult[TransportAddress] = proc connect*( ma: MultiAddress, bufferSize = DefaultStreamBufferSize, - child: StreamTransport = nil): Future[StreamTransport] + child: StreamTransport = nil, + flags = default(set[TransportFlags])): Future[StreamTransport] {.raises: [Defect, LPError, MaInvalidAddress].} = ## Open new connection to remote peer with address ``ma`` and create ## new transport object ``StreamTransport`` for established connection. @@ -86,7 +87,7 @@ proc connect*( if not(RTRANSPMA.match(ma)): raise newException(MaInvalidAddress, "Incorrect or unsupported address!") - return connect(initTAddress(ma).tryGet(), bufferSize, child) + return connect(initTAddress(ma).tryGet(), bufferSize, child, flags) proc createStreamServer*[T](ma: MultiAddress, cbproc: StreamCallback, From 0c55c2a8261dda9b86b877297e0f1d6f6fa8ac80 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Tue, 24 Jan 2023 17:05:43 +0100 Subject: [PATCH 2/3] Add stub for old chronos versions --- .pinned | 10 +++++----- libp2p.nimble | 2 +- libp2p/utility.nim | 6 ++++++ libp2p/wire.nim | 9 +++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.pinned b/.pinned index e7d75a5662..8f193c68f4 100644 --- a/.pinned +++ b/.pinned @@ -1,15 +1,15 @@ -bearssl;https://github.com/status-im/nim-bearssl@#a647994910904b0103a05db3a5ec1ecfc4d91a88 +bearssl;https://github.com/status-im/nim-bearssl@#acf9645e328bdcab481cfda1c158e07ecd46bd7b chronicles;https://github.com/status-im/nim-chronicles@#32ac8679680ea699f7dbc046e8e0131cac97d41a -chronos;https://github.com/status-im/nim-chronos@#8b44843d416961f57786579533677c12a9876976 +chronos;https://github.com/status-im/nim-chronos@#8fcbe716b2f069480277aa6781782d3e311ee2c0 dnsclient;https://github.com/ba0f3/dnsclient.nim@#fcd7443634b950eaea574e5eaa00a628ae029823 -faststreams;https://github.com/status-im/nim-faststreams@#b42daf41d8eb4fbce40add6836bed838f8d85b6f +faststreams;https://github.com/status-im/nim-faststreams@#814f8927e1f356f39219f37f069b83066bcc893a httputils;https://github.com/status-im/nim-http-utils@#a85bd52ae0a956983ca6b3267c72961d2ec0245f json_serialization;https://github.com/status-im/nim-json-serialization@#a7d815ed92f200f490c95d3cfd722089cc923ce6 metrics;https://github.com/status-im/nim-metrics@#21e99a2e9d9f80e68bef65c80ef781613005fccb -nimcrypto;https://github.com/cheatfate/nimcrypto@#24e006df85927f64916e60511620583b11403178 +nimcrypto;https://github.com/cheatfate/nimcrypto@#4014ef939b51e02053c2e16dd3481d47bc9267dd secp256k1;https://github.com/status-im/nim-secp256k1@#fd173fdff863ce2e211cf64c9a03bc7539fe40b0 serialization;https://github.com/status-im/nim-serialization@#d77417cba6896c26287a68e6a95762e45a1b87e5 -stew;https://github.com/status-im/nim-stew@#f5846de7b2bacecd7dbff9e89d81b4f34385eb31 +stew;https://github.com/status-im/nim-stew@#447b23d3bf6eb7be6531385e4db9124772c98068 testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34 unittest2;https://github.com/status-im/nim-unittest2@#da8398c45cafd5bd7772da1fc96e3924a18d3823 websock;https://github.com/status-im/nim-websock@#691f069b209d372b1240d5ae1f57fb7bbafeaba7 diff --git a/libp2p.nimble b/libp2p.nimble index dff30c1a67..2644f6fef3 100644 --- a/libp2p.nimble +++ b/libp2p.nimble @@ -8,11 +8,11 @@ license = "MIT" skipDirs = @["tests", "examples", "Nim", "tools", "scripts", "docs"] requires "nim >= 1.2.0", - "chronos#8b44843", "nimcrypto >= 0.4.1", "dnsclient >= 0.3.0 & < 0.4.0", "bearssl >= 0.1.4", "chronicles >= 0.10.2", + "chronos >= 3.0.6", "metrics", "secp256k1", "stew#head", diff --git a/libp2p/utility.nim b/libp2p/utility.nim index 3a02a25d36..1000394ae7 100644 --- a/libp2p/utility.nim +++ b/libp2p/utility.nim @@ -19,6 +19,12 @@ template public* {.pragma.} const ShortDumpMax = 12 +template compilesOr*(a, b: untyped): untyped = + when compiles(a): + a + else: + b + func shortLog*(item: openArray[byte]): string = if item.len <= ShortDumpMax: result = item.toHex() diff --git a/libp2p/wire.nim b/libp2p/wire.nim index ca172f49b2..ba7109d134 100644 --- a/libp2p/wire.nim +++ b/libp2p/wire.nim @@ -14,7 +14,7 @@ else: ## This module implements wire network connection procedures. import chronos, stew/endians2 -import multiaddress, multicodec, errors +import multiaddress, multicodec, errors, utility when defined(windows): import winlean @@ -87,7 +87,12 @@ proc connect*( if not(RTRANSPMA.match(ma)): raise newException(MaInvalidAddress, "Incorrect or unsupported address!") - return connect(initTAddress(ma).tryGet(), bufferSize, child, flags) + let transportAddress = initTAddress(ma).tryGet() + + compilesOr: + return connect(transportAddress, bufferSize, child, flags) + do: + return connect(transportAddress, bufferSize, child) proc createStreamServer*[T](ma: MultiAddress, cbproc: StreamCallback, From e792bedca71da40a50a5f8bebea7253d54024ef8 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Mon, 13 Feb 2023 15:34:20 +0100 Subject: [PATCH 3/3] add comment --- .pinned | 10 +++++----- libp2p/wire.nim | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.pinned b/.pinned index 8f193c68f4..a9b5e63f5a 100644 --- a/.pinned +++ b/.pinned @@ -1,6 +1,6 @@ bearssl;https://github.com/status-im/nim-bearssl@#acf9645e328bdcab481cfda1c158e07ecd46bd7b chronicles;https://github.com/status-im/nim-chronicles@#32ac8679680ea699f7dbc046e8e0131cac97d41a -chronos;https://github.com/status-im/nim-chronos@#8fcbe716b2f069480277aa6781782d3e311ee2c0 +chronos;https://github.com/status-im/nim-chronos@#5d3da66e563d21277b57a9b601744273c083a01b dnsclient;https://github.com/ba0f3/dnsclient.nim@#fcd7443634b950eaea574e5eaa00a628ae029823 faststreams;https://github.com/status-im/nim-faststreams@#814f8927e1f356f39219f37f069b83066bcc893a httputils;https://github.com/status-im/nim-http-utils@#a85bd52ae0a956983ca6b3267c72961d2ec0245f @@ -8,9 +8,9 @@ json_serialization;https://github.com/status-im/nim-json-serialization@#a7d815ed metrics;https://github.com/status-im/nim-metrics@#21e99a2e9d9f80e68bef65c80ef781613005fccb nimcrypto;https://github.com/cheatfate/nimcrypto@#4014ef939b51e02053c2e16dd3481d47bc9267dd secp256k1;https://github.com/status-im/nim-secp256k1@#fd173fdff863ce2e211cf64c9a03bc7539fe40b0 -serialization;https://github.com/status-im/nim-serialization@#d77417cba6896c26287a68e6a95762e45a1b87e5 -stew;https://github.com/status-im/nim-stew@#447b23d3bf6eb7be6531385e4db9124772c98068 +serialization;https://github.com/status-im/nim-serialization@#5b7cea55efeb074daa8abd8146a03a34adb4521a +stew;https://github.com/status-im/nim-stew@#407a59883691d362db2fe8eab7f7c3b1f75112ff testutils;https://github.com/status-im/nim-testutils@#dfc4c1b39f9ded9baf6365014de2b4bfb4dafc34 unittest2;https://github.com/status-im/nim-unittest2@#da8398c45cafd5bd7772da1fc96e3924a18d3823 -websock;https://github.com/status-im/nim-websock@#691f069b209d372b1240d5ae1f57fb7bbafeaba7 -zlib;https://github.com/status-im/nim-zlib@#6a6670afba6b97b29b920340e2641978c05ab4d8 \ No newline at end of file +websock;https://github.com/status-im/nim-websock@#fea05cde8b123b38d1a0a8524b77efbc84daa848 +zlib;https://github.com/status-im/nim-zlib@#826e2fc013f55b4478802d4f2e39f187c50d520a \ No newline at end of file diff --git a/libp2p/wire.nim b/libp2p/wire.nim index ba7109d134..6c3671f2d2 100644 --- a/libp2p/wire.nim +++ b/libp2p/wire.nim @@ -92,6 +92,7 @@ proc connect*( compilesOr: return connect(transportAddress, bufferSize, child, flags) do: + # support for older chronos versions return connect(transportAddress, bufferSize, child) proc createStreamServer*[T](ma: MultiAddress,