kobako 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.githooks/linux-tests.sh +29 -0
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +125 -0
- data/Cargo.lock +457 -494
- data/README.md +2 -3
- data/ROADMAP.md +0 -1
- data/crates/kobako-runtime/CHANGELOG.md +90 -0
- data/crates/kobako-runtime/Cargo.toml +14 -15
- data/crates/kobako-runtime/README.md +1 -1
- data/crates/kobako-runtime/src/cred.rs +32 -20
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +56 -22
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +33 -14
- data/crates/kobako-runtime/src/filesystem/bind.rs +393 -220
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +2 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +9 -10
- data/crates/kobako-runtime/src/filesystem/overlay.rs +277 -46
- data/crates/kobako-runtime/src/filesystem/rdir.rs +8 -27
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +47 -13
- data/crates/kobako-runtime/src/filesystem.rs +2 -0
- data/crates/kobako-runtime/src/fork.rs +239 -16
- data/crates/kobako-runtime/src/limits.rs +17 -41
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +508 -113
- data/crates/kobako-runtime/src/memcg.rs +83 -160
- data/crates/kobako-runtime/src/mount.rs +0 -30
- data/crates/kobako-runtime/src/net/connections.rs +53 -13
- data/crates/kobako-runtime/src/net/egress.rs +44 -24
- data/crates/kobako-runtime/src/net/http.rs +888 -456
- data/crates/kobako-runtime/src/net/lookup.rs +150 -50
- data/crates/kobako-runtime/src/net/namespace.rs +97 -95
- data/crates/kobako-runtime/src/net/reactor.rs +298 -203
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +8 -3
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +50 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +29 -23
- data/crates/kobako-runtime/src/net/resolv/windows.rs +14 -44
- data/crates/kobako-runtime/src/net/resolv.rs +39 -15
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +51 -52
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +410 -158
- data/crates/kobako-runtime/src/net/tls.rs +65 -3
- data/crates/kobako-runtime/src/net/transport.rs +72 -47
- data/crates/kobako-runtime/src/net/udp.rs +231 -129
- data/crates/kobako-runtime/src/net.rs +3 -0
- data/crates/kobako-runtime/src/sched.rs +244 -58
- data/crates/kobako-runtime/src/security.rs +27 -16
- data/crates/kobako-runtime/src/vfs/dentry.rs +80 -41
- data/crates/kobako-runtime/src/vfs/file.rs +52 -53
- data/crates/kobako-runtime/src/vfs/kern_path.rs +24 -11
- data/crates/kobako-runtime/src/vfs/namei.rs +399 -184
- data/crates/kobako-runtime/src/vfs/namespace.rs +123 -40
- data/crates/kobako-runtime/src/vfs/stat.rs +105 -16
- data/crates/kobako-runtime/src/vfs.rs +1 -0
- data/crates/kobako-runtime/src/wait.rs +75 -50
- data/crates/kobako-transport/CHANGELOG.md +7 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +1 -1
- data/crates/kobako-wasmtime/CHANGELOG.md +47 -0
- data/crates/kobako-wasmtime/Cargo.toml +27 -6
- data/crates/kobako-wasmtime/README.md +3 -3
- data/crates/kobako-wasmtime/src/abi.rs +2 -1
- data/crates/kobako-wasmtime/src/ambient.rs +11 -2
- data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
- data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
- data/crates/kobako-wasmtime/src/cache.rs +88 -103
- data/crates/kobako-wasmtime/src/driver.rs +40 -27
- data/crates/kobako-wasmtime/src/invocation.rs +21 -7
- data/crates/kobako-wasmtime/src/lib.rs +2 -0
- data/crates/kobako-wasmtime/src/limiter.rs +78 -25
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +13 -17
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +4 -5
- data/crates/kobako-wasmtime/src/preview1/differential.rs +1 -1
- data/crates/kobako-wasmtime/src/preview1/fd.rs +23 -19
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +130 -197
- data/crates/kobako-wasmtime/src/preview1/path.rs +3 -3
- data/crates/kobako-wasmtime/src/preview1/poll.rs +28 -22
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1.rs +85 -9
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +2 -2
- data/crates/kobako-wasmtime/src/preview2/host.rs +609 -249
- data/crates/kobako-wasmtime/src/preview2/http.rs +299 -215
- data/crates/kobako-wasmtime/src/preview2/io.rs +17 -4
- data/crates/kobako-wasmtime/src/preview2/table.rs +24 -72
- data/crates/kobako-wasmtime/src/trap.rs +68 -23
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +91 -10
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +13 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +6 -2
- data/ext/kobako/src/escape.rs +332 -26
- data/ext/kobako/src/filesystem/grants.rs +5 -7
- data/ext/kobako/src/filesystem/ruby.rs +10 -3
- data/ext/kobako/src/filesystem.rs +47 -8
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +499 -76
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +10 -0
- data/ext/kobako/src/network.rs +5 -3
- data/ext/kobako/src/pinned_value.rs +28 -15
- data/ext/kobako/src/runtime/bridge.rs +32 -25
- data/ext/kobako/src/runtime.rs +74 -43
- data/lib/kobako/catalog/handles.rb +9 -5
- data/lib/kobako/codec/decoder.rb +1 -1
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +4 -4
- data/lib/kobako/codec.rb +5 -6
- data/lib/kobako/errors.rb +4 -7
- data/lib/kobako/filesystem.rb +1 -1
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +1 -2
- data/lib/kobako/sandbox.rb +17 -36
- data/lib/kobako/sandbox_options.rb +7 -9
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +2 -2
- data/sig/kobako/catalog/handles.rbs +2 -0
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +1 -1
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/errors.rbs +0 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/runtime.rbs +2 -2
- data/sig/kobako/sandbox.rbs +3 -12
- data/sig/kobako/sandbox_options.rbs +0 -2
- metadata +15 -4
- data/lib/kobako/pool.rb +0 -162
- data/sig/core/thread.rbs +0 -6
- data/sig/kobako/pool.rbs +0 -46
|
@@ -4,17 +4,79 @@
|
|
|
4
4
|
|
|
5
5
|
use std::sync::{Arc, OnceLock};
|
|
6
6
|
|
|
7
|
+
use rustls::client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
|
|
7
8
|
use rustls::crypto::CryptoProvider;
|
|
8
|
-
use rustls::
|
|
9
|
+
use rustls::pki_types::{CertificateDer, ServerName, UnixTime};
|
|
10
|
+
use rustls::{ClientConfig, DigitallySignedStruct, DistinguishedName, SignatureScheme};
|
|
9
11
|
use rustls_platform_verifier::Verifier;
|
|
10
12
|
|
|
11
13
|
static PLATFORM: OnceLock<Option<(Arc<CryptoProvider>, Arc<Verifier>)>> = OnceLock::new();
|
|
12
14
|
|
|
15
|
+
/// The server whose certificate the system first verified in this process,
|
|
16
|
+
/// which a forked child inherits as it inherits what verifying left behind.
|
|
17
|
+
static FIRST_TRUSTED: OnceLock<String> = OnceLock::new();
|
|
18
|
+
|
|
19
|
+
/// The server whose certificate macOS first verified in this process, `None`
|
|
20
|
+
/// before then and on every other system. From then on a forked child that
|
|
21
|
+
/// touches the system's certificate services crashes, as the threads serving
|
|
22
|
+
/// them did not come along; Linux reads its certificates from files.
|
|
23
|
+
pub fn first_trusted_host() -> Option<&'static str> {
|
|
24
|
+
FIRST_TRUSTED.get().map(String::as_str)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// The platform's verifier, recording the first server it had the system
|
|
28
|
+
/// verify.
|
|
29
|
+
#[derive(Debug)]
|
|
30
|
+
struct FirstTrustRecording(Arc<Verifier>);
|
|
31
|
+
|
|
32
|
+
impl ServerCertVerifier for FirstTrustRecording {
|
|
33
|
+
fn verify_server_cert(
|
|
34
|
+
&self,
|
|
35
|
+
end_entity: &CertificateDer<'_>,
|
|
36
|
+
intermediates: &[CertificateDer<'_>],
|
|
37
|
+
server_name: &ServerName<'_>,
|
|
38
|
+
ocsp_response: &[u8],
|
|
39
|
+
now: UnixTime,
|
|
40
|
+
) -> Result<ServerCertVerified, rustls::Error> {
|
|
41
|
+
if cfg!(target_os = "macos") {
|
|
42
|
+
FIRST_TRUSTED.get_or_init(|| server_name.to_str().into_owned());
|
|
43
|
+
}
|
|
44
|
+
self.0
|
|
45
|
+
.verify_server_cert(end_entity, intermediates, server_name, ocsp_response, now)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fn verify_tls12_signature(
|
|
49
|
+
&self,
|
|
50
|
+
message: &[u8],
|
|
51
|
+
cert: &CertificateDer<'_>,
|
|
52
|
+
dss: &DigitallySignedStruct,
|
|
53
|
+
) -> Result<HandshakeSignatureValid, rustls::Error> {
|
|
54
|
+
self.0.verify_tls12_signature(message, cert, dss)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fn verify_tls13_signature(
|
|
58
|
+
&self,
|
|
59
|
+
message: &[u8],
|
|
60
|
+
cert: &CertificateDer<'_>,
|
|
61
|
+
dss: &DigitallySignedStruct,
|
|
62
|
+
) -> Result<HandshakeSignatureValid, rustls::Error> {
|
|
63
|
+
self.0.verify_tls13_signature(message, cert, dss)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn supported_verify_schemes(&self) -> Vec<SignatureScheme> {
|
|
67
|
+
self.0.supported_verify_schemes()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fn root_hint_subjects(&self) -> Option<&[DistinguishedName]> {
|
|
71
|
+
self.0.root_hint_subjects()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
13
75
|
/// The OS's store and the provider verifying against it, built once per
|
|
14
76
|
/// process, `None` where the platform offers no store. Its first build reads
|
|
15
77
|
/// the environment, `SSL_CERT_FILE` on Linux among it, so it is built as the
|
|
16
78
|
/// first network entry is made, on the Host App's thread building its
|
|
17
|
-
/// Sandbox, rather than
|
|
79
|
+
/// Sandbox, rather than within a handshake beside another reading it; a later
|
|
18
80
|
/// change to that environment is not seen.
|
|
19
81
|
pub(crate) fn load_platform_verifier() -> Option<&'static (Arc<CryptoProvider>, Arc<Verifier>)> {
|
|
20
82
|
PLATFORM
|
|
@@ -35,7 +97,7 @@ pub fn new_platform_tls() -> Option<Arc<ClientConfig>> {
|
|
|
35
97
|
.with_safe_default_protocol_versions()
|
|
36
98
|
.ok()?
|
|
37
99
|
.dangerous()
|
|
38
|
-
.with_custom_certificate_verifier(verifier.clone())
|
|
100
|
+
.with_custom_certificate_verifier(Arc::new(FirstTrustRecording(verifier.clone())))
|
|
39
101
|
.with_no_client_auth();
|
|
40
102
|
Some(Arc::new(config))
|
|
41
103
|
}
|
|
@@ -2,27 +2,28 @@
|
|
|
2
2
|
//! authority a request named, and the connection it opened. The connector
|
|
3
3
|
//! dials through a TCP socket of the Invocation's own, as an egress proxy
|
|
4
4
|
//! dials through the kernel, so its upstream passes the socket layer's
|
|
5
|
-
//! filter, holds a virtual port, and
|
|
6
|
-
//!
|
|
5
|
+
//! filter, holds a virtual port, and queues within its buffers, as a guest's
|
|
6
|
+
//! socket does.
|
|
7
7
|
|
|
8
|
+
use std::cell::Cell;
|
|
8
9
|
use std::fmt;
|
|
9
10
|
use std::future::poll_fn;
|
|
10
11
|
use std::io;
|
|
11
12
|
use std::net::{IpAddr, Shutdown, SocketAddr};
|
|
12
13
|
use std::pin::Pin;
|
|
13
14
|
use std::sync::{Arc, OnceLock};
|
|
14
|
-
use std::task::{Context, Poll};
|
|
15
|
+
use std::task::{ready, Context, Poll};
|
|
15
16
|
use std::time::Instant;
|
|
16
17
|
|
|
17
18
|
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
|
18
19
|
|
|
19
|
-
use super::connections::Place;
|
|
20
|
+
use super::connections::{ConnectionBudget, Place};
|
|
20
21
|
use super::http::HttpError;
|
|
21
22
|
use super::lookup::NameLookup;
|
|
22
23
|
use super::namespace::TcpSockets;
|
|
23
24
|
use super::socket::{BindHash, Destination};
|
|
25
|
+
use super::task::PollBudget;
|
|
24
26
|
use super::{Namespace, ProtoOps, ProtocolFamily, SockOpt, TcpSock};
|
|
25
|
-
use crate::cred::Cred;
|
|
26
27
|
use crate::errno::CarriedErrno;
|
|
27
28
|
use crate::network::{Host, Protocol, Ruleset};
|
|
28
29
|
use crate::wait::WaitQueueHead;
|
|
@@ -39,28 +40,36 @@ pub struct Connector {
|
|
|
39
40
|
target: Target,
|
|
40
41
|
ports: Arc<BindHash>,
|
|
41
42
|
tcp_sockets: Arc<TcpSockets>,
|
|
42
|
-
cred: Arc<Cred>,
|
|
43
43
|
/// The request's place, which a lookup of the authority holds too.
|
|
44
44
|
place: Arc<Place>,
|
|
45
|
+
/// The Invocation's connection budget, which each address past the
|
|
46
|
+
/// first spends.
|
|
47
|
+
budget: Arc<ConnectionBudget>,
|
|
45
48
|
/// When a connect opened, which its exchange's wait for the head starts
|
|
46
49
|
/// from.
|
|
47
50
|
pub(crate) connected: Arc<OnceLock<Instant>>,
|
|
48
51
|
/// The queue its exchange's waiters sleep on, woken as the connect opens,
|
|
49
52
|
/// so a wait bound by the connect's timeout takes the head's.
|
|
50
53
|
pub(crate) wait: Option<Arc<WaitQueueHead>>,
|
|
54
|
+
/// What one poll of the exchange's task may move on the connection.
|
|
55
|
+
pub(crate) poll_budget: Arc<PollBudget>,
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
impl Connector {
|
|
54
|
-
/// The connector for `host` at `port` in `net`,
|
|
55
|
-
///
|
|
56
|
-
///
|
|
59
|
+
/// The connector for `host` at `port` in `net`, holding the request's
|
|
60
|
+
/// `place`, which a lookup of a named host holds too. It spends one of the
|
|
61
|
+
/// connection budget before its lookup or first dial leaves, as a Worker
|
|
62
|
+
/// counts a `fetch` once; a spent budget answers `ConnectionLimitReached`.
|
|
57
63
|
pub(crate) fn new(
|
|
58
64
|
net: &Namespace,
|
|
59
|
-
cred: &Arc<Cred>,
|
|
60
65
|
host: Host,
|
|
61
66
|
port: u16,
|
|
62
67
|
place: Arc<Place>,
|
|
63
|
-
) -> Self {
|
|
68
|
+
) -> Result<Self, HttpError> {
|
|
69
|
+
let budget = net.connection_budget().clone();
|
|
70
|
+
budget
|
|
71
|
+
.spend()
|
|
72
|
+
.map_err(|_| HttpError::ConnectionLimitReached)?;
|
|
64
73
|
let target = match host {
|
|
65
74
|
Host::Address(ip) => Target::Address(ip),
|
|
66
75
|
Host::Name(name) => Target::Named {
|
|
@@ -68,23 +77,23 @@ impl Connector {
|
|
|
68
77
|
net.resolver().clone(),
|
|
69
78
|
name.clone(),
|
|
70
79
|
place.clone(),
|
|
71
|
-
)
|
|
72
|
-
.map_err(|_| HttpError::ConnectionLimitReached),
|
|
80
|
+
),
|
|
73
81
|
name,
|
|
74
82
|
},
|
|
75
83
|
};
|
|
76
|
-
Self {
|
|
84
|
+
Ok(Self {
|
|
77
85
|
port,
|
|
78
86
|
ruleset: net.ruleset().clone(),
|
|
79
87
|
family: net.family().clone(),
|
|
80
88
|
target,
|
|
81
89
|
ports: net.ports_of(Protocol::Http).clone(),
|
|
82
90
|
tcp_sockets: net.tcp_sockets().clone(),
|
|
83
|
-
cred: cred.clone(),
|
|
84
91
|
place,
|
|
92
|
+
budget,
|
|
85
93
|
connected: Arc::default(),
|
|
86
94
|
wait: None,
|
|
87
|
-
|
|
95
|
+
poll_budget: Arc::default(),
|
|
96
|
+
})
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
/// The host and port the request named.
|
|
@@ -100,34 +109,40 @@ impl Connector {
|
|
|
100
109
|
/// connector tries each real address in turn, as an HTTP client's
|
|
101
110
|
/// connector does, while a guest's TCP socket keeps a loop of its own; an
|
|
102
111
|
/// address the filter refuses is passed over, and none admitted is
|
|
103
|
-
/// denied.
|
|
112
|
+
/// denied. Each address dialed past the first spends one of the
|
|
113
|
+
/// connection budget as it is about to leave, and a spent budget ends the
|
|
114
|
+
/// dial with `ConnectionLimitReached`.
|
|
104
115
|
pub async fn dial(&self) -> Result<Transport, HttpError> {
|
|
105
116
|
let dests = match &self.target {
|
|
106
117
|
Target::Address(ip) => vec![Destination::Literal(SocketAddr::new(*ip, self.port))],
|
|
107
|
-
Target::Named { lookup, .. } =>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
.collect()
|
|
119
|
-
}
|
|
118
|
+
Target::Named { lookup, .. } => poll_fn(|cx| lookup.poll_answer(cx))
|
|
119
|
+
.await
|
|
120
|
+
.map_err(|_| HttpError::DnsError)?
|
|
121
|
+
.into_iter()
|
|
122
|
+
.map(|real| Destination::Named {
|
|
123
|
+
name: lookup.name().to_string(),
|
|
124
|
+
real,
|
|
125
|
+
port: self.port,
|
|
126
|
+
})
|
|
127
|
+
.collect(),
|
|
120
128
|
};
|
|
121
129
|
let mut last = HttpError::Denied;
|
|
130
|
+
// The request spent one already, which its first dial takes.
|
|
131
|
+
let prepaid = Cell::new(true);
|
|
122
132
|
for dest in &dests {
|
|
123
|
-
let sock = TcpSock::create_kern(&self.family, &self.tcp_sockets
|
|
124
|
-
.map_err(|err| HttpError::from_errno(&err))?;
|
|
133
|
+
let sock = TcpSock::create_kern(&self.family, &self.tcp_sockets);
|
|
125
134
|
// Set before the dial, so the host socket takes it as it is
|
|
126
135
|
// made, as an HTTP client writes each request whole; a guest's
|
|
127
136
|
// own socket keeps Linux's default.
|
|
128
137
|
sock.setsockopt(SockOpt::NoDelay, 1)
|
|
129
138
|
.map_err(|err| HttpError::from_errno(&err))?;
|
|
130
|
-
|
|
139
|
+
let exhausted = Cell::new(false);
|
|
140
|
+
let spend = || match prepaid.replace(false) {
|
|
141
|
+
true => Ok(()),
|
|
142
|
+
false => self.budget.spend().inspect_err(|_| exhausted.set(true)),
|
|
143
|
+
};
|
|
144
|
+
match sock.connect_upstream(&self.ports, &self.ruleset, dest, &self.place, spend) {
|
|
145
|
+
Err(_) if exhausted.get() => return Err(HttpError::ConnectionLimitReached),
|
|
131
146
|
Err(Errno::PermissionDenied) => continue,
|
|
132
147
|
Err(err) => {
|
|
133
148
|
last = HttpError::from_errno(&err);
|
|
@@ -135,7 +150,10 @@ impl Connector {
|
|
|
135
150
|
}
|
|
136
151
|
Ok(()) => {}
|
|
137
152
|
}
|
|
138
|
-
let connection = Transport {
|
|
153
|
+
let connection = Transport {
|
|
154
|
+
sock,
|
|
155
|
+
poll_budget: self.poll_budget.clone(),
|
|
156
|
+
};
|
|
139
157
|
match connection.wait_for_connect().await {
|
|
140
158
|
Ok(()) => {
|
|
141
159
|
let _ = self.connected.set(Instant::now());
|
|
@@ -153,12 +171,12 @@ impl Connector {
|
|
|
153
171
|
|
|
154
172
|
/// Where a connector dials: a literal address, or a named authority and its
|
|
155
173
|
/// lookup, started on the thread that sends the request, as a guest's own
|
|
156
|
-
/// lookup is
|
|
174
|
+
/// lookup is.
|
|
157
175
|
enum Target {
|
|
158
176
|
Address(IpAddr),
|
|
159
177
|
Named {
|
|
160
178
|
name: String,
|
|
161
|
-
lookup:
|
|
179
|
+
lookup: Arc<NameLookup>,
|
|
162
180
|
},
|
|
163
181
|
}
|
|
164
182
|
|
|
@@ -176,6 +194,7 @@ impl fmt::Debug for Connector {
|
|
|
176
194
|
/// guest's poll does.
|
|
177
195
|
pub struct Transport {
|
|
178
196
|
sock: Arc<TcpSock>,
|
|
197
|
+
poll_budget: Arc<PollBudget>,
|
|
179
198
|
}
|
|
180
199
|
|
|
181
200
|
impl Transport {
|
|
@@ -186,21 +205,27 @@ impl Transport {
|
|
|
186
205
|
}
|
|
187
206
|
|
|
188
207
|
/// `op` once it stops answering `WouldBlock`, the task added to the
|
|
189
|
-
/// socket's wait queue first, so a wake between the two is not lost.
|
|
208
|
+
/// socket's wait queue first, so a wake between the two is not lost. Each
|
|
209
|
+
/// answer spends a step of the task's poll budget, as tokio's I/O does,
|
|
210
|
+
/// so a peer that keeps the socket ready never holds one poll.
|
|
190
211
|
fn attempt<T>(
|
|
191
212
|
&self,
|
|
192
213
|
cx: &mut Context<'_>,
|
|
193
214
|
mut op: impl FnMut() -> Result<T, Errno>,
|
|
194
215
|
) -> Poll<Result<T, Errno>> {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
216
|
+
let step = ready!(self.poll_budget.poll_proceed(cx));
|
|
217
|
+
let done = match op() {
|
|
218
|
+
Err(Errno::WouldBlock) => {
|
|
219
|
+
self.sock.sk_sleep().add(cx.waker());
|
|
220
|
+
match op() {
|
|
221
|
+
Err(Errno::WouldBlock) => return Poll::Pending,
|
|
222
|
+
done => done,
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
done => done,
|
|
226
|
+
};
|
|
227
|
+
step.made_progress();
|
|
228
|
+
Poll::Ready(done)
|
|
204
229
|
}
|
|
205
230
|
}
|
|
206
231
|
|
|
@@ -273,7 +298,7 @@ mod tests {
|
|
|
273
298
|
),
|
|
274
299
|
(failures, HttpError::Internal),
|
|
275
300
|
"a failure the upstream socket answers must read back as the same errno once it \
|
|
276
|
-
crosses an io::Error, so
|
|
301
|
+
crosses an io::Error, so a failure for want of memory answers internal-error"
|
|
277
302
|
);
|
|
278
303
|
}
|
|
279
304
|
}
|