Skip to content
Open
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
11 changes: 3 additions & 8 deletions ts_control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,11 @@ tokio-util = { workspace = true, features = ["time"] }
tracing.workspace = true
url = { workspace = true, features = ["serde", "std"] }
zerocopy.workspace = true

# Required dependencies for the async_tokio feature.
futures-util = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
tokio-stream = { version = "0.1", optional = true, default-features = false, features = ["sync"] }
futures-util = { workspace = true }
tokio = { workspace = true }
tokio-stream = { version = "0.1", default-features = false, features = ["sync"] }

[features]
default = ["async_tokio"]
async_tokio = ["dep:futures-util", "dep:tokio", "dep:tokio-stream"]

# Allow derp connections to be made without verifying TLS certs. Only for use in tests.
insecure-derp = ["ts_derp/insecure-for-tests"]
# Allow control keys to be fetched over plain HTTP1 without TLS. Only for use in tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ts_keys::{MachineKeyPair, MachinePublicKey};
use url::Url;
use zerocopy::network_endian::U32;

use crate::tokio::prefixed_reader::PrefixedReader;
use crate::client::prefixed_reader::PrefixedReader;

const CHALLENGE_MAGIC: [u8; 5] = [0xFF, 0xFF, 0xFF, b'T', b'S'];
const HANDSHAKE_HEADER_KEY: &str = "X-Tailscale-Handshake";
Expand Down
32 changes: 19 additions & 13 deletions ts_control/src/tokio/client.rs → ts_control/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ use tokio::{
use tokio_stream::wrappers::errors::BroadcastStreamRecvError;
use url::Url;

use crate::{
ControlDialer, Error,
map_request_builder::MapRequestBuilder,
tokio::{
map_stream::{StateUpdate, map_stream, send_map_request},
ping::handle_ping,
},
use crate::{ControlDialer, Error, map_request_builder::MapRequestBuilder};

mod connect;
mod map_stream;
mod ping;
mod prefixed_reader;
mod register;

pub use connect::{
CONTROL_PROTOCOL_VERSION, connect, fetch_control_key, read_challenge_packet, upgrade_ts2021,
};
pub use map_stream::{FilterUpdate, PeerUpdate, StateUpdate};
use map_stream::{map_stream, send_map_request};
use ping::handle_ping;
pub use register::register;

/// A client to communicate with control.
#[derive(Debug)]
Expand All @@ -36,9 +43,8 @@ impl AsyncControlClient {
) -> Result<(), Error> {
let control_url = &config.server_url;

let h2_client = crate::tokio::connect(control_url, &node_keys.machine_keys).await?;

crate::tokio::register(config, control_url, auth_key, node_keys, &h2_client).await?;
let h2_client = connect(control_url, &node_keys.machine_keys).await?;
register(config, control_url, auth_key, node_keys, &h2_client).await?;

Ok(())
}
Expand All @@ -63,10 +69,10 @@ impl AsyncControlClient {
let control_url = &config.server_url;
let mut tasks = JoinSet::new();

let h2_client = crate::tokio::connect(control_url, &node_keys.machine_keys).await?;
let h2_client = connect(control_url, &node_keys.machine_keys).await?;
tracing::info!("connected to control, registering");

crate::tokio::register(config, control_url, auth_key, node_keys, &h2_client).await?;
register(config, control_url, auth_key, node_keys, &h2_client).await?;

tracing::info!("registered, starting netmap stream");

Expand Down Expand Up @@ -213,7 +219,7 @@ async fn run_once(
.full_connect_next(control_url, &node_keys.machine_keys)
.await?;

crate::tokio::register(config, control_url, auth_key, node_keys, &h2_client).await?;
register(config, control_url, auth_key, node_keys, &h2_client).await?;

let builder = MapRequestBuilder::new(node_keys)
.keep_alive(true)
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions ts_control/src/control_dialer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,18 @@ where
return Err(Error::InvalidUrl(url.clone()));
}
};
let control_public_key = crate::tokio::fetch_control_key(url).await?;
let control_public_key = crate::client::fetch_control_key(url).await?;

let (handshake, init_msg) = ts_control_noise::Handshake::initialize(
&crate::tokio::CONTROL_PROTOCOL_VERSION,
&crate::client::CONTROL_PROTOCOL_VERSION,
machine_keys,
&control_public_key,
CapabilityVersion::CURRENT,
);

let conn =
crate::tokio::upgrade_ts2021(url, &init_msg, handshake, machine_keys, h1_client).await?;
let conn = crate::tokio::read_challenge_packet(conn).await?;
crate::client::upgrade_ts2021(url, &init_msg, handshake, machine_keys, h1_client).await?;
let conn = crate::client::read_challenge_packet(conn).await?;

let h2_conn = ts_http_util::http2::connect(conn).await?;
tracing::debug!("http2 connection to control established");
Expand Down
8 changes: 2 additions & 6 deletions ts_control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ const PKG_VERSION: &str = if let Some(version) = option_env!("CARGO_PKG_VERSION"
""
};

mod client;
mod config;
mod control_dialer;
mod derp;
mod dial_plan;
#[cfg_attr(not(feature = "async_tokio"), expect(dead_code))]
mod map_request_builder;
mod node;
#[cfg(feature = "async_tokio")]
mod tokio;

use std::fmt;

pub use client::{AsyncControlClient, FilterUpdate, PeerUpdate, StateUpdate};
#[doc(inline)]
pub use config::{Config, DEFAULT_CONTROL_SERVER};
pub use control_dialer::{ControlDialer, TcpDialer, complete_connection};
Expand All @@ -33,9 +32,6 @@ pub use node::{
TailnetAddress,
};

#[cfg(feature = "async_tokio")]
pub use crate::tokio::{AsyncControlClient, FilterUpdate, PeerUpdate, StateUpdate};

/// An error which occurred while connecting to the control server or control plane.
#[derive(Debug, thiserror::Error, Clone, Eq, PartialEq)]
pub enum Error {
Expand Down
14 changes: 0 additions & 14 deletions ts_control/src/tokio/mod.rs

This file was deleted.