Support TCP Fast Open
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Feature
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- linux, macos, rust
- Bereich
- networking
Rechercherichtung
Überprüfen Sie zuerst die Abschnitte zu TcpListener und TcpStream und vergleichen Sie anschließend die in diesem Issue beschriebenen plattformspezifischen APIs setsockopt, sendto, connectx und ConnectEx. Eine vollständige Umsetzung würde eine festgelegte plattformübergreifende API und eine Implementierungsstrategie für das Senden des ersten Datenpakets erfordern; das Issue nennt keine auszuführenden Dateien oder Tests.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
TcpListener
All of Linux, OS X and Windows are the same, call setsockopt with TCP_FASTOPEN option
// For Linux, value is the queue length of pending packets
int opt = 5;
// For the others, just a boolean value for enable and disable
int opt = 1;
// Call it before listen()
int ret = setsockopt(socket, IPPROTO_TCP, TCP_FASTOPEN, &opt, sizeof(opt));
TcpStream
This is a bit more complicated than TcpListener, because we have to send SYN with the first data packet to make TFO works. APIs are completely different on different platforms:
Linux
Before 4.11, Linux uses MSG_FASTOPEN flag for sendto(), doesn't need to call connect()
// Send SYN with data in buf
ssize_t n = sendto(socket, buf, buf_length, MSG_FASTOPEN, saddr, saddr_len);
After 4.11, Linux provides a TCP_FASTOPEN_CONNECT option
int enable = 1;
// Enable it before connect()
int ret = setsockopt(socket, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &enable, sizeof(enable));
// Call connect as usual
int ret = connect(socket, saddr, saddr_len);
BSDs (except Darwin)
Uses sendto() as Linux without MSG_FASTOPEN flag
// Set before sendto()
int ret = setsockopt(socket, IPPROTO_TCP, TCP_FASTOPEN, &opt, sizeof(opt));
// Call sendto() without flags
ssize_t n = sendto(socket, buf, buf_length, 0, saddr, saddr_len);
Darwin (OS X)
Darwin supports TFO after OS X 10.11, iOS 9.0, tvOS 9.0 and watchOS 2.0.
It supports with a new syscall connectx.
sa_endpoints_t endpoints;
memset(&endpoints, 0, sizeof(endpoints));
endpoints.sae_dstaddr = &saddr;
endpoints.sae_dstaddrlen = saddr_len;
int ret = connectx(socket,
&endpoints,
SAE_ASSOCID_ANY,
CONNECT_DATA_IDEMPOTENT | CONNECT_RESUME_ON_READ_WRITE,
NULL,
0,
NULL,
NULL);
SYN will be sent with the first write or send.
Windows
Windows supports with ConnectEx, since Windows 10. https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nc-mswsock-lpfn_connectex
// TCP_FASTOPEN is required
int ret = setsockopt(socket, IPPROTO_TCP, TCP_FASTOPEN, &opt, sizeof(opt));
// Get LPFN_CONNECTEX
LPFN_CONNECTEX ConnectEx = ...;
// Call it with the first packet of data, SYN will send with this packet's data
LPDWORD bytesSent = 0;
int ret = ConnectEx(socket, saddr, saddr_len, buf, buf_length, &bytesSent, &overlapped);
Challenge
As we can see for those OSes' APIs, (except OS X and Linux > 4.10) connections are made with the first write(), which means that if we want to support TFO, we have to put those code in the first call of std::io::Write::write or tokio::AsyncWrite::poll_write.
There is no other way except customizing a TcpStream from socket() and call different APIs on different OSes while sending the first data packet.
I want to open a discussion here for how in Rust's world to support TFO gracefully.
Related API PRs
connectxfor OS X: https://github.com/rust-lang/libc/pull/1635TCP_FASTOPEN_CONNECTfor Linux: https://github.com/rust-lang/libc/pull/1634TCP_FASTOPENfor Windows: https://github.com/retep998/winapi-rs/issues/856
- Vorherrschende Sprache
- Rust
- Sterne
- 885
- Forks
- 328
- Ø Merge
- 6 T. 12 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus rust-lang/socket2
-
Commit lockfileOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
rust-lang/socket2#703 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
windows-sys 0.101.0Evtl. vergeben @xtqqczze hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
SockAddr::path_len doesn't bound the length by sun_path: as_pathname panics since #691, as_abstract_namespace slices past itEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
`from_timeval` overflows on a non-normalised `tv_usec`Evtl. vergeben @pederbe hat das vor 18 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Build fails on 32-bit glibc (i686, armv7) with libc's `--cfg=libc_unstable_time64`: `tv_usec` is cast to `suseconds_t` (i32) for an i64 fieldEvtl. vergeben @omrzk hat das vor 28 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
rust-lang/socket2#684 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in rust-lang/socket2
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
infra
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
available bug good first issue tooling
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Nixitov/Riptide-Native#817 ·
Maintainer antworten meist innerhalb von 1 Tag