Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASI Preview2 #16

Merged
merged 3 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions common-types.wit

This file was deleted.

9 changes: 9 additions & 0 deletions wasi-default-network.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

/// This interface provides a value-export of the default network handle..
default interface wasi-default-network {
use pkg.wasi-network.{network}

/// Get a handle to the default network.
default-network: func() -> network

}
103 changes: 71 additions & 32 deletions wasi-ip-name-lookup.wit
Original file line number Diff line number Diff line change
@@ -1,32 +1,71 @@
use { error, ip-address, ip-address-family } from common-types
use { network } from wasi-network

/// Resolve an internet host name to a list of IP addresses.
///
/// See the proposal README.md for a comparison with getaddrinfo.
///
/// Parameters:
/// - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted
/// to ASCII using IDNA encoding.
/// - `address-family`: If provided, limit the results to addresses of this specific address family.
/// - `include-unavailable`: When set to true, this function will also return addresses of which the runtime
/// thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on
/// systems without an active IPv6 interface. Notes:
/// - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address.
/// - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged.
///
/// Results:
/// - When successful, there is always at least one result.
/// - The results are returned in the order the runtime thinks the application should try to connect to first.
/// - Never returns IPv4-mapped IPv6 addresses.
///
/// Returns EAI_FAIL when `name` is:
/// - empty
/// - an IP address
/// - a syntactically invalid domain name in another way
///
/// References:
/// - https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
/// - https://man7.org/linux/man-pages/man3/getaddrinfo.3.html
///
resolve-addresses: func(name: string, address-family: option<ip-address-family>, include-unavailable: bool) -> future<expected<list<ip-address>, error>>

default interface wasi-ip-name-lookup {
use pkg.wasi-poll.{pollable}
use pkg.wasi-network.{network, error, ip-address, ip-address-family}


/// Resolve an internet host name to a list of IP addresses.
///
/// See the wasi-socket proposal README.md for a comparison with getaddrinfo.
///
/// Parameters:
/// - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted
/// to ASCII using IDNA encoding.
/// - `address-family`: If provided, limit the results to addresses of this specific address family.
/// - `include-unavailable`: When set to true, this function will also return addresses of which the runtime
/// thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on
/// systems without an active IPv6 interface. Notes:
/// - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address.
/// - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged.
///
/// This function never blocks. It either immediately returns successfully with a `resolve-address-stream`
/// that can be used to (asynchronously) fetch the results.
/// Or it immediately fails whenever `name` is:
/// - empty
/// - an IP address
/// - a syntactically invalid domain name in another way
///
/// References:
/// - https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
/// - https://man7.org/linux/man-pages/man3/getaddrinfo.3.html
///
resolve-addresses: func(network: network, name: string, address-family: option<ip-address-family>, include-unavailable: bool) -> result<resolve-address-stream, error>



type resolve-address-stream = u32

/// Returns the next address from the resolver.
///
/// This function should be called multiple times. On each call, it will
/// return the next address in connection order preference. If all
/// addresses have been exhausted, this function returns `none`.
/// After which, you should release the stream with `drop-resolve-address-stream`.
///
/// This function never returns IPv4-mapped IPv6 addresses.
resolve-next-address: func(this: resolve-address-stream) -> result<option<ip-address>, error>



/// Dispose of the specified `resolve-address-stream`, after which it may no longer be used.
///
/// Note: this function is scheduled to be removed when Resources are natively supported in Wit.
drop-resolve-address-stream: func(this: resolve-address-stream)

/// Get/set the blocking mode of the stream.
///
/// By default a stream is in "blocking" mode, meaning that any function blocks and waits for its completion.
/// When switched to "non-blocking" mode, operations that would block return an `again` error. After which
/// the API consumer is expected to call `subscribe` and wait for completion using the wasi-poll module.
///
/// Note: these functions are here for WASI Preview2 only.
/// They're planned to be removed when `future` is natively supported in Preview3.
non-blocking: func(this: resolve-address-stream) -> result<bool, error>
set-non-blocking: func(this: resolve-address-stream, value: bool) -> result<_, error>

/// Create a `pollable` which will resolve once the stream is ready for I/O.
///
/// Note: this function is here for WASI Preview2 only.
/// It's planned to be removed when `future` is natively supported in Preview3.
subscribe: func(this: resolve-address-stream) -> pollable
}
57 changes: 55 additions & 2 deletions wasi-network.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@

/// Capability handle for accessing network-related functions.
resource network {}
default interface wasi-network {
/// An opaque resource that represents access to (a subset of) the network.
/// This enables context-based security for networking.
/// There is no need for this to map 1:1 to a physical network interface.
///
/// FYI, In the future this will be replaced by handle types.
type network = u32

/// Dispose of the specified `network`, after which it may no longer be used.
///
/// Note: this function is scheduled to be removed when Resources are natively supported in Wit.
drop-network: func(this: network)



enum error {
unknown,
again,
// TODO ...
}

enum ip-address-family {
/// Similar to `AF_INET` in POSIX.
ipv4,

/// Similar to `AF_INET6` in POSIX.
ipv6,
}

type ipv4-address = tuple<u8, u8, u8, u8>
type ipv6-address = tuple<u16, u16, u16, u16, u16, u16, u16, u16>

variant ip-address {
ipv4(ipv4-address),
ipv6(ipv6-address),
}

record ipv4-socket-address {
port: u16, // sin_port
address: ipv4-address, // sin_addr
}

record ipv6-socket-address {
port: u16, // sin6_port
flow-info: u32, // sin6_flowinfo
address: ipv6-address, // sin6_addr
scope-id: u32, // sin6_scope_id
}

variant ip-socket-address {
ipv4(ipv4-socket-address),
ipv6(ipv6-socket-address),
}

}
41 changes: 0 additions & 41 deletions wasi-socket-ip.wit

This file was deleted.

Loading