refactor(connlib): repurpose connlib-shared as connlib-model (#6919)

The `connlib-shared` crate has become a bit of a dependency magnet
without a clear purpose. It hosts utilities like `get_user_agent`,
messages for the client and gateway to communicate with the portal and
domain types like `ResourceId`.

To create a better dependency structure in our workspace, we repurpose
`connlib-shared` as a `connlib-model` crate. Its purpose is to host
domain-specific model types that multiple crates may want to use. For
that purpose, we rename the `callbacks::ResourceDescription` type to
`ResourceView`, designating that this is a _view_ onto a resource as
seen by `connlib`. The message types which currently double up as
connlib-internal model thus become an implementation detail of
`firezone-tunnel` and shouldn't be used for anything else.

---------

Signed-off-by: Reactor Scram <ReactorScram@users.noreply.github.com>
Co-authored-by: Reactor Scram <ReactorScram@users.noreply.github.com>
This commit is contained in:
Thomas Eizinger
2024-10-04 00:47:58 +10:00
committed by GitHub
parent fd9724a3a3
commit be250f1e00
56 changed files with 902 additions and 974 deletions

View File

@@ -12,7 +12,7 @@ atomicwrites = { workspace = true } # Needed to safely backup `/etc/resolv.conf`
backoff = "0.4.0"
clap = { version = "4.5", features = ["derive", "env", "string"] }
connlib-client-shared = { workspace = true }
connlib-shared = { workspace = true }
connlib-model = { workspace = true }
firezone-bin-shared = { workspace = true }
firezone-logging = { workspace = true }
firezone-telemetry = { workspace = true }
@@ -30,7 +30,7 @@ smbios-lib = "0.9.2"
thiserror = { version = "1.0", default-features = false }
# This actually relies on many other features in Tokio, so this will probably
# fail to build outside the workspace. <https://github.com/firezone/firezone/pull/4328#discussion_r1540342142>
tokio = { workspace = true, features = ["macros", "signal", "process", "time", "rt-multi-thread"] }
tokio = { workspace = true, features = ["macros", "signal", "process", "time", "rt-multi-thread", "fs"] }
tokio-stream = "0.1.16"
tokio-util = { version = "0.7.11", features = ["codec"] }
tracing = { workspace = true }
@@ -66,17 +66,17 @@ winreg = "0.52.0"
[target.'cfg(windows)'.dependencies.windows]
version = "0.58.0"
features = [
# For DNS control and route control
"Win32_Foundation",
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_Ndis",
"Win32_Networking_WinSock",
# For DNS control and route control
"Win32_Foundation",
"Win32_NetworkManagement_IpHelper",
"Win32_NetworkManagement_Ndis",
"Win32_Networking_WinSock",
"Win32_Security", # For named pipe IPC
"Win32_System_GroupPolicy", # For NRPT when GPO is used
"Win32_System_SystemInformation", # For uptime
"Win32_System_SystemServices",
"Win32_System_Pipes",
"Win32_Security", # For named pipe IPC
"Win32_System_GroupPolicy", # For NRPT when GPO is used
"Win32_System_SystemInformation", # For uptime
"Win32_System_SystemServices",
"Win32_System_Pipes",
]
[lints]

View File

@@ -4,8 +4,8 @@ use crate::{
};
use anyhow::{bail, Context as _, Result};
use clap::Parser;
use connlib_client_shared::{keypair, ConnectArgs, LoginUrl};
use connlib_shared::callbacks::ResourceDescription;
use connlib_client_shared::{keypair, ConnectArgs};
use connlib_model::ResourceView;
use firezone_bin_shared::{
platform::{tcp_socket_factory, udp_socket_factory, DnsControlMethod},
TunDeviceManager, TOKEN_ENV_KEY,
@@ -16,6 +16,7 @@ use futures::{
task::{Context, Poll},
Future as _, SinkExt as _, Stream as _,
};
use phoenix_channel::LoginUrl;
use secrecy::SecretString;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeSet, net::IpAddr, path::PathBuf, pin::pin, sync::Arc, time::Duration};
@@ -26,9 +27,9 @@ use url::Url;
pub mod ipc;
use backoff::ExponentialBackoffBuilder;
use connlib_shared::{get_user_agent, messages::ResourceId};
use connlib_model::ResourceId;
use ipc::{Server as IpcServer, ServiceId};
use phoenix_channel::PhoenixChannel;
use phoenix_channel::{get_user_agent, PhoenixChannel};
use secrecy::Secret;
#[cfg(target_os = "linux")]
@@ -97,7 +98,7 @@ pub enum ServerMsg {
error_msg: String,
is_authentication_error: bool,
},
OnUpdateResources(Vec<ResourceDescription>),
OnUpdateResources(Vec<ResourceView>),
/// The IPC service is terminating, maybe due to a software update
///
/// This is a hint that the Client should exit with a message like,

View File

@@ -10,7 +10,7 @@
use anyhow::{Context as _, Result};
use connlib_client_shared::{Callbacks, DisconnectError};
use connlib_shared::callbacks;
use connlib_model::ResourceView;
use firezone_bin_shared::platform::DnsControlMethod;
use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr},
@@ -82,7 +82,7 @@ pub enum ConnlibMsg {
ipv6: Ipv6Addr,
dns: Vec<IpAddr>,
},
OnUpdateResources(Vec<callbacks::ResourceDescription>),
OnUpdateResources(Vec<ResourceView>),
OnUpdateRoutes {
ipv4: Vec<Ipv4Network>,
ipv6: Vec<Ipv6Network>,
@@ -117,7 +117,7 @@ impl Callbacks for CallbackHandler {
.expect("Should be able to send OnSetInterfaceConfig");
}
fn on_update_resources(&self, resources: Vec<callbacks::ResourceDescription>) {
fn on_update_resources(&self, resources: Vec<ResourceView>) {
tracing::debug!(len = resources.len(), "New resource list");
self.cb_tx
.try_send(ConnlibMsg::OnUpdateResources(resources))

View File

@@ -3,8 +3,7 @@
use anyhow::{anyhow, Context as _, Result};
use backoff::ExponentialBackoffBuilder;
use clap::Parser;
use connlib_client_shared::{keypair, ConnectArgs, LoginUrl, Session};
use connlib_shared::get_user_agent;
use connlib_client_shared::{keypair, ConnectArgs, Session};
use firezone_bin_shared::{
new_dns_notifier, new_network_notifier,
platform::{tcp_socket_factory, udp_socket_factory},
@@ -15,6 +14,8 @@ use firezone_headless_client::{
};
use firezone_telemetry::Telemetry;
use futures::{FutureExt as _, StreamExt as _};
use phoenix_channel::get_user_agent;
use phoenix_channel::LoginUrl;
use phoenix_channel::PhoenixChannel;
use secrecy::{Secret, SecretString};
use std::{