-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the
wasi:sockets/ip-name-lookup
interface (#7109)
* Implement the `wasi:sockets/ip-name-lookup` interface This commit is an initial implementation of the new `ip-name-lookup` interface from the `wasi-sockets` proposal. The intention is to get a sketch of what an implementation would look like for the preview2 release later this year. Notable features of this implementation are: * Name lookups are disabled by default and must be explicitly enabled in `WasiCtx`. This seems like a reasonable default for now while the full set of configuration around this is settled. * I've added new "typed" methods to `preview2::Table` to avoid the need for extra helpers when using resources. * A new `-Sallow-ip-name-lookup` option is added to control this on the CLI. * Implementation-wise this uses the blocking resolution in the Rust standard library, built on `getaddrinfo`. This doesn't invoke `getaddrinfo` "raw", however, so information such as error details can be lost in translation. This will probably need to change in the future. Closes #7070 * Validate the input domain name. * Use a crate-level helper for `spawn_blocking` --------- Co-authored-by: Dave Bakker <github@davebakker.io>
- Loading branch information
1 parent
a6d0542
commit e2f1bdd
Showing
18 changed files
with
263 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
crates/test-programs/wasi-sockets-tests/src/bin/ip_name_lookup.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use wasi_sockets_tests::wasi::clocks::*; | ||
use wasi_sockets_tests::wasi::io::*; | ||
use wasi_sockets_tests::wasi::sockets::*; | ||
|
||
fn main() { | ||
let network = instance_network::instance_network(); | ||
|
||
let addresses = | ||
ip_name_lookup::resolve_addresses(&network, "example.com", None, false).unwrap(); | ||
let pollable = addresses.subscribe(); | ||
poll::poll_one(&pollable); | ||
assert!(addresses.resolve_next_address().is_ok()); | ||
|
||
let result = ip_name_lookup::resolve_addresses(&network, "a.b<&>", None, false); | ||
assert!(matches!(result, Err(network::ErrorCode::InvalidName))); | ||
|
||
// Try resolving a valid address and ensure that it eventually terminates. | ||
// To help prevent this test from being flaky this additionally times out | ||
// the resolution and allows errors. | ||
let addresses = ip_name_lookup::resolve_addresses(&network, "github.com", None, false).unwrap(); | ||
let lookup = addresses.subscribe(); | ||
let timeout = monotonic_clock::subscribe(1_000_000_000, false); | ||
let ready = poll::poll_list(&[&lookup, &timeout]); | ||
assert!(ready.len() > 0); | ||
match ready[0] { | ||
0 => loop { | ||
match addresses.resolve_next_address() { | ||
Ok(Some(_)) => {} | ||
Ok(None) => break, | ||
Err(_) => break, | ||
} | ||
}, | ||
1 => {} | ||
_ => unreachable!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.