code stringlengths 40 729k | docstring stringlengths 22 46.3k | func_name stringlengths 1 97 | language stringclasses 1
value | repo stringlengths 6 48 | path stringlengths 8 176 | url stringlengths 47 228 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
fn assert_memories_match(&mut self, exports: &ModuleExports) {
for name in exports.memories() {
let Some(wasmi_mem) = self.wasmi_oracle.get_memory(name) else {
continue;
};
let Some(oracle_mem) = self.chosen_oracle.get_memory(name) else {
conti... | Asserts that the linear memory state is equal in both oracles. | assert_memories_match | rust | wasmi-labs/wasmi | fuzz/fuzz_targets/differential.rs | https://github.com/wasmi-labs/wasmi/blob/master/fuzz/fuzz_targets/differential.rs | Apache-2.0 |
fn report_divergent_behavior(
&self,
func_name: &str,
params: &[FuzzVal],
wasmi_result: &Result<Box<[FuzzVal]>, FuzzError>,
oracle_result: &Result<Box<[FuzzVal]>, FuzzError>,
) {
assert!(matches!(
(&wasmi_result, &oracle_result),
(Ok(_), Err(_)... | Reports divergent behavior between Wasmi and the chosen oracle. | report_divergent_behavior | rust | wasmi-labs/wasmi | fuzz/fuzz_targets/differential.rs | https://github.com/wasmi-labs/wasmi/blob/master/fuzz/fuzz_targets/differential.rs | Apache-2.0 |
fn fill_values(dst: &mut Vec<Val>, src: &[ValType], u: &mut Unstructured) {
dst.clear();
dst.extend(
src.iter()
.copied()
.map(FuzzValType::from)
.map(|ty| FuzzVal::with_type(ty, u))
.map(Val::from),
);
} | Fill [`Val`]s of type `src` into `dst` using `u` for initialization.
Clears `dst` before the operation. | fill_values | rust | wasmi-labs/wasmi | fuzz/fuzz_targets/execute.rs | https://github.com/wasmi-labs/wasmi/blob/master/fuzz/fuzz_targets/execute.rs | Apache-2.0 |
pub fn new(start_delay: Duration, max_delay: Duration) -> Self {
Self {
start_delay,
max_delay,
current_delay: start_delay,
}
} | Creates a new exponential backoff instance starting with delay
`start_delay` and maxing out at `max_delay`. | new | rust | mullvad/udp-over-tcp | src/exponential_backoff.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/exponential_backoff.rs | Apache-2.0 |
pub fn reset(&mut self) {
self.current_delay = self.start_delay;
} | Resets the exponential backoff so that the next delay is the start delay again. | reset | rust | mullvad/udp-over-tcp | src/exponential_backoff.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/exponential_backoff.rs | Apache-2.0 |
pub fn next_delay(&mut self) -> Duration {
let delay = self.current_delay;
let next_delay = self.current_delay * 2;
self.current_delay = cmp::min(next_delay, self.max_delay);
delay
} | Returns the next delay. This is twice as long as the last returned delay,
up until `max_delay` is reached. | next_delay | rust | mullvad/udp-over-tcp | src/exponential_backoff.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/exponential_backoff.rs | Apache-2.0 |
pub async fn process_udp_over_tcp(
udp_socket: UdpSocket,
tcp_stream: TcpStream,
tcp_recv_timeout: Option<Duration>,
) {
let udp_in = Arc::new(udp_socket);
let udp_out = udp_in.clone();
let (tcp_in, tcp_out) = tcp_stream.into_split();
let tcp2udp = async move {
if let Err(error) = p... | Forward traffic between the given UDP and TCP sockets in both directions.
This async function runs until one of the sockets are closed or there is an error.
Both sockets are closed before returning. | process_udp_over_tcp | rust | mullvad/udp-over-tcp | src/forward_traffic.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/forward_traffic.rs | Apache-2.0 |
async fn process_tcp2udp(
mut tcp_in: TcpReadHalf,
udp_out: Arc<UdpSocket>,
tcp_recv_timeout: Option<Duration>,
) -> Result<(), Box<dyn std::error::Error>> {
let mut buffer = datagram_buffer();
// `buffer` has unprocessed data from the TCP socket up until this index.
let mut unprocessed_i = 0;
... | Reads from `tcp_in` and extracts UDP datagrams. Writes the datagrams to `udp_out`.
Returns if the TCP socket is closed, or an IO error happens on either socket. | process_tcp2udp | rust | mullvad/udp-over-tcp | src/forward_traffic.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/forward_traffic.rs | Apache-2.0 |
async fn forward_datagrams_in_buffer(udp_out: &UdpSocket, buffer: &[u8]) -> io::Result<usize> {
let mut unprocessed_buffer = buffer;
loop {
let Some((datagram_data, tail)) = split_first_datagram(unprocessed_buffer) else {
// The buffer does not contain the entire datagram
break O... | Forward all complete datagrams in `buffer` to `udp_out`.
Returns the number of processed bytes. | forward_datagrams_in_buffer | rust | mullvad/udp-over-tcp | src/forward_traffic.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/forward_traffic.rs | Apache-2.0 |
fn split_first_datagram(buffer: &[u8]) -> Option<(&[u8], &[u8])> {
let (header, tail) = buffer.split_first_chunk::<HEADER_LEN>()?;
let datagram_len = usize::from(u16::from_be_bytes(*header));
tail.split_at_checked(datagram_len)
} | Parses the header at the beginning of the `buffer` and if it contains a full
`udp-to-tcp` datagram it splits the buffer and returns the datagram data and
buffer tail as two separate slices: `(datagram_data, tail)` | split_first_datagram | rust | mullvad/udp-over-tcp | src/forward_traffic.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/forward_traffic.rs | Apache-2.0 |
async fn process_udp2tcp(
udp_in: Arc<UdpSocket>,
mut tcp_out: TcpWriteHalf,
) -> Result<Infallible, Box<dyn std::error::Error>> {
// A buffer large enough to hold any possible UDP datagram plus its 16 bit length header.
let mut buffer = datagram_buffer();
loop {
let udp_read_len = udp_in
... | Reads datagrams from `udp_in` and writes them (with the 16 bit header containing the length)
to `tcp_out` indefinitely, or until an IO error happens on either socket. | process_udp2tcp | rust | mullvad/udp-over-tcp | src/forward_traffic.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/forward_traffic.rs | Apache-2.0 |
pub fn new(tcp_listen_addrs: Vec<SocketAddr>, udp_forward_addr: SocketAddr) -> Self {
Options {
tcp_listen_addrs,
udp_forward_addr,
udp_bind_ip: None,
tcp_options: Default::default(),
#[cfg(feature = "statsd")]
statsd_host: None,
}
... | Creates a new [`Options`] with all mandatory fields set to the passed arguments.
All optional values are set to their default values. They can later be set, since
they are public.
# Examples
```
# use std::net::{IpAddr, Ipv4Addr, SocketAddrV4, SocketAddr};
let mut options = udp_over_tcp::tcp2udp::Options::new(
// Li... | new | rust | mullvad/udp-over-tcp | src/tcp2udp.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/tcp2udp.rs | Apache-2.0 |
pub async fn run(options: Options) -> Result<Infallible, Tcp2UdpError> {
if options.tcp_listen_addrs.is_empty() {
return Err(Tcp2UdpError::NoTcpListenAddrs);
}
let udp_bind_ip = options.udp_bind_ip.unwrap_or_else(|| {
if options.udp_forward_addr.is_ipv4() {
"0.0.0.0".parse().unw... | Sets up TCP listening sockets on all addresses in `Options::tcp_listen_addrs`.
If binding a listening socket fails this returns an error. Otherwise the function
will continue indefinitely to accept incoming connections and forward to UDP.
Errors are just logged. | run | rust | mullvad/udp-over-tcp | src/tcp2udp.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/tcp2udp.rs | Apache-2.0 |
async fn process_socket(
tcp_stream: TcpStream,
tcp_peer_addr: SocketAddr,
udp_bind_ip: IpAddr,
udp_peer_addr: SocketAddr,
tcp_recv_timeout: Option<Duration>,
) -> Result<(), Box<dyn std::error::Error>> {
let udp_bind_addr = SocketAddr::new(udp_bind_ip, 0);
let udp_socket = UdpSocket::bind(... | Sets up a UDP socket bound to `udp_bind_ip` and connected to `udp_peer_addr` and forwards
traffic between that UDP socket and the given `tcp_stream` until the `tcp_stream` is closed.
`tcp_peer_addr` should be the remote addr that `tcp_stream` is connected to. | process_socket | rust | mullvad/udp-over-tcp | src/tcp2udp.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/tcp2udp.rs | Apache-2.0 |
pub fn kind(&self) -> ApplyTcpOptionsErrorKind {
use ApplyTcpOptionsErrorInternal::*;
match self.0 {
RecvBuffer(_) => ApplyTcpOptionsErrorKind::RecvBuffer,
SendBuffer(_) => ApplyTcpOptionsErrorKind::SendBuffer,
#[cfg(target_os = "linux")]
Mark(_) => ApplyT... | Returns the kind of error that happened as an enum | kind | rust | mullvad/udp-over-tcp | src/tcp_options.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/tcp_options.rs | Apache-2.0 |
pub fn apply(socket: &TcpSocket, options: &TcpOptions) -> Result<(), ApplyTcpOptionsError> {
if let Some(recv_buffer_size) = options.recv_buffer_size {
socket
.set_recv_buffer_size(recv_buffer_size)
.map_err(ApplyTcpOptionsErrorInternal::RecvBuffer)?;
}
log::debug!(
"... | Applies the given options to the given TCP socket. | apply | rust | mullvad/udp-over-tcp | src/tcp_options.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/tcp_options.rs | Apache-2.0 |
pub fn set_nodelay(tcp_stream: &TcpStream, nodelay: bool) -> Result<(), ApplyTcpOptionsError> {
// Configure TCP_NODELAY on the TCP stream
tcp_stream
.set_nodelay(nodelay)
.map_err(ApplyTcpOptionsErrorInternal::TcpNoDelay)?;
log::debug!(
"TCP_NODELAY: {}",
tcp_stream
... | We need to apply the nodelay option separately as it is not currently exposed on TcpSocket.
=> https://github.com/tokio-rs/tokio/issues/5510 | set_nodelay | rust | mullvad/udp-over-tcp | src/tcp_options.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/tcp_options.rs | Apache-2.0 |
pub async fn new(
udp_listen_addr: SocketAddr,
tcp_forward_addr: SocketAddr,
tcp_options: crate::TcpOptions,
) -> Result<Self, Error> {
let tcp_socket = match &tcp_forward_addr {
SocketAddr::V4(..) => TcpSocket::new_v4(),
SocketAddr::V6(..) => TcpSocket::new_v... | Creates a TCP socket and binds to the given UDP address.
Just calling this constructor won't forward any traffic over the sockets (see `run`). | new | rust | mullvad/udp-over-tcp | src/udp2tcp.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/udp2tcp.rs | Apache-2.0 |
pub async fn run(self) -> Result<(), Error> {
// Wait for the first datagram, to get the UDP peer_addr to connect to.
let mut tmp_buffer = crate::forward_traffic::datagram_buffer();
let (_udp_read_len, udp_peer_addr) = self
.udp_socket
.peek_from(tmp_buffer.as_mut())
... | Connects to the TCP address and runs the forwarding until the TCP socket is closed, or
an error occur. | run | rust | mullvad/udp-over-tcp | src/udp2tcp.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/udp2tcp.rs | Apache-2.0 |
fn create_runtime(threads: Option<NonZeroU8>) -> tokio::runtime::Runtime {
let mut runtime = match threads.map(NonZeroU8::get) {
Some(1) => {
log::info!("Using a single thread");
tokio::runtime::Builder::new_current_thread()
}
Some(threads) => {
let mut ru... | Creates a Tokio runtime for the process to use.
If `threads` is `None` it uses the same amount of worker threads as system cores.
Creates a single threaded runtime if `threads` is `Some(1)`.
Otherwise it uses the specified number of worker threads. | create_runtime | rust | mullvad/udp-over-tcp | src/bin/tcp2udp.rs | https://github.com/mullvad/udp-over-tcp/blob/master/src/bin/tcp2udp.rs | Apache-2.0 |
async fn setup_udp2tcp() -> Result<
(UdpSocket, TcpStream, JoinHandle<Result<(), udp2tcp::Error>>),
Box<dyn std::error::Error>,
> {
let tcp_listener = TcpListener::bind("127.0.0.1:0").await?;
let tcp_listen_addr = tcp_listener.local_addr().unwrap();
let udp2tcp = udp2tcp::Udp2Tcp::new(
"127... | Spawns a Udp2Tcp instance and connects to boths ends of it.
Returns the UDP and TCP sockets that goes through it. | setup_udp2tcp | rust | mullvad/udp-over-tcp | tests/udp2tcp.rs | https://github.com/mullvad/udp-over-tcp/blob/master/tests/udp2tcp.rs | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.