Skip to content

Commit

Permalink
WIP squashing/rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Nov 30, 2024
1 parent 3d2fc08 commit 57ae57a
Show file tree
Hide file tree
Showing 18 changed files with 2,503 additions and 5 deletions.
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ serde = { version = "1.0.200", features = ["rc"] }
futures-util = { version = "0.3.30", default-features = false }
enumflags2 = "0.7.9"
console-subscriber = { version = "0.4.0", optional = true }
xdg-home = "1.1.0"
xdg-home = "1.3.0"
event-listener = "5.3.0"
quick-xml = { version = "0.36.2", features = ["serialize"] }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.29.0", features = ["user"] }
Expand Down
35 changes: 33 additions & 2 deletions src/bin/busd.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
extern crate busd;

use std::path::PathBuf;
#[cfg(unix)]
use std::{fs::File, io::Write, os::fd::FromRawFd};

use busd::bus;
use busd::{bus, config::Config};

use anyhow::Result;
use clap::Parser;
Expand All @@ -18,9 +19,14 @@ use tracing::{info, warn};
#[clap(author, version, about, long_about = None)]
struct Args {
/// The address to listen on.
/// Takes precedence over any `<listen>` element in the configuration file.
#[clap(short = 'a', long, value_parser)]
address: Option<String>,

/// Use the given configuration file.
#[clap(long)]
config: Option<PathBuf>,

/// Print the address of the message bus to standard output.
#[clap(long)]
print_address: bool,
Expand All @@ -36,6 +42,15 @@ struct Args {
#[cfg(unix)]
#[clap(long)]
ready_fd: Option<i32>,

/// Equivalent to `--config /usr/share/dbus-1/session.conf`.
/// This is the default if `--config` and `--system` are unspecified.
#[clap(long)]
session: bool,

/// Equivalent to `--config /usr/share/dbus-1/system.conf`.
#[clap(long)]
system: bool,
}

#[tokio::main]
Expand All @@ -44,7 +59,23 @@ async fn main() -> Result<()> {

let args = Args::parse();

let mut bus = bus::Bus::for_address(args.address.as_deref()).await?;
let config_path = if args.system {
PathBuf::from("/usr/share/dbus-1/system.conf")
} else if let Some(config_path) = args.config {
config_path
} else {
PathBuf::from("/usr/share/dbus-1/session.conf")
};
eprintln!("reading configuration file {} ...", config_path.display());
let config = Config::read_file(&config_path)?;

let address = if let Some(address) = args.address {
Some(address)
} else {
config.listen.map(|address| format!("{address}"))
};

let mut bus = bus::Bus::for_address(address.as_deref()).await?;

#[cfg(unix)]
if let Some(fd) = args.ready_fd {
Expand Down
95 changes: 95 additions & 0 deletions src/config/limits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use std::time::Duration;

use super::BusType;

#[derive(Clone, Debug, PartialEq)]
pub struct Limits {
/// total size in bytes of messages incoming from a single connection
pub max_incoming_bytes: u32,
/// total number of unix fds of messages incoming from a single connection
pub max_incoming_unix_fds: u32,
/// total size in bytes of messages queued up for a single connection
pub max_outgoing_bytes: u32,
/// total number of unix fds of messages queued up for a single connection
pub max_outgoing_unix_fds: u32,
/// max size of a single message in bytes
pub max_message_size: u32,
/// max unix fds of a single message
pub max_message_unix_fds: u32,
/// time a started service has to connect
pub service_start_timeout: Duration,
/// time a connection is given to authenticate
pub auth_timeout: Duration,
/// time a fd is given to be transmitted to dbus-daemon before disconnecting the connection
pub pending_fd_timeout: Duration,
/// max number of authenticated connections
pub max_completed_connections: u32,
/// max number of unauthenticated connections
pub max_incomplete_connections: u32,
/// max number of completed connections from the same user (only enforced on Unix OSs)
pub max_connections_per_user: u32,
/// max number of service launches in progress at the same time
pub max_pending_service_starts: u32,
/// max number of names a single connection can own
pub max_names_per_connection: u32,
/// max number of match rules for a single connection
pub max_match_rules_per_connection: u32,
/// max number of pending method replies per connection (number of calls-in-progress)
pub max_replies_per_connection: u32,
/// time until a method call times out
pub reply_timeout: Duration,
}
impl Default for Limits {
fn default() -> Self {
Self {
max_incoming_bytes: 133169152,
max_incoming_unix_fds: 64,
max_outgoing_bytes: 133169152,
max_outgoing_unix_fds: 64,
max_message_size: 33554432,
max_message_unix_fds: 16,
service_start_timeout: Duration::from_millis(25000),
auth_timeout: Duration::from_millis(5000),
pending_fd_timeout: Duration::from_millis(150000),
max_completed_connections: 2048,
max_incomplete_connections: 64,
max_connections_per_user: 256,
max_pending_service_starts: 512,
max_names_per_connection: 512,
max_match_rules_per_connection: 512,
max_replies_per_connection: 128,
reply_timeout: Duration::from_millis(5000),
}
}
}
impl From<BusType> for Limits {
fn from(value: BusType) -> Self {
if value == BusType::Session {
Self {
// dbus-daemon / dbus-broker is limited to the highest positive number in i32,
// but we use u32 here, so we can pick the preferred 4GB memory limits
max_incoming_bytes: 4000000000,
max_incoming_unix_fds: 250000000,
max_outgoing_bytes: 4000000000,
max_outgoing_unix_fds: 250000000,
max_message_size: 4000000000,
// We do not override max_message_unix_fds here,
// since the in-kernel limit is also relatively low
max_message_unix_fds: 16,
service_start_timeout: Duration::from_millis(120000),
auth_timeout: Duration::from_millis(240000),
pending_fd_timeout: Duration::from_millis(150000),
max_completed_connections: 100000,
max_incomplete_connections: 10000,
max_connections_per_user: 100000,
max_pending_service_starts: 10000,
max_names_per_connection: 50000,
max_match_rules_per_connection: 50000,
max_replies_per_connection: 50000,
..Default::default()
}
} else {
Self::default()
}
}
}
Loading

0 comments on commit 57ae57a

Please sign in to comment.