Skip to content

Commit

Permalink
TCP Transport: enable NO_DELAY for clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Menduist committed Dec 16, 2022
1 parent fe7a69e commit fc5a573
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .pinned
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libp2p.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions libp2p/transports/tcptransport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions libp2p/wire.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit fc5a573

Please sign in to comment.