Skip to content

Commit

Permalink
tree wide: use simple 16 byte random string for UUID
Browse files Browse the repository at this point in the history
Since all we are using UUIDs for is to avoid duplicate names then we can
achieve the same thing by using a random 16 byte string rather than strictly
adhering to the UUID v4 spec (which just sets a couple of the bytes to a
known value for identification purposes). This way we can reduce dependencies
by just relying on the bare minimum of `getrandom`.
  • Loading branch information
ammgws committed Nov 10, 2020
1 parent ac739ec commit 2538831
Show file tree
Hide file tree
Showing 39 changed files with 100 additions and 110 deletions.
26 changes: 14 additions & 12 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 @@ -18,6 +18,7 @@ profiling = ["cpuprofiler", "progress"]
[dependencies]
crossbeam-channel = "0.5"
dbus = "0.8"
getrandom = "0.2"
lazy_static = "1.0"
maildir = "0.4"
nix = "0.19.0"
Expand All @@ -28,7 +29,7 @@ serde_json = "1.0"
swayipc = "2.7"
toml = "0.5"
signal-hook = "0.1.16"
uuid = { version = "0.8", features = ["v4"] }

# Optional features/blocks
libpulse-binding = { optional = true, version = "2.15.0", default-features = false }
notmuch = { optional = true, version = "0.6.0" }
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/backlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use std::time::{Duration, Instant};
use crossbeam_channel::Sender;
use inotify::{EventMask, Inotify, WatchMask};
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::Update;
use crate::blocks::{Block, ConfigBlock};
use crate::config::{Config, LogicalDirection, Scrolling};
use crate::errors::*;
use crate::input::I3BarEvent;
use crate::scheduler::Task;
use crate::util::pseudo_uuid;
use crate::widget::I3BarWidget;
use crate::widgets::button::ButtonWidget;

Expand Down Expand Up @@ -245,7 +245,7 @@ impl ConfigBlock for Backlight {
None => BacklitDevice::default(block_config.root_scaling),
}?;

let id = Uuid::new_v4().to_simple().to_string();
let id = pseudo_uuid().to_string();
let brightness_file = device.brightness_file();

let scrolling = config.scrolling;
Expand Down
7 changes: 4 additions & 3 deletions src/blocks/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ use crossbeam_channel::Sender;
use dbus::arg::Array;
use dbus::ffidisp::stdintf::org_freedesktop_dbus::Properties;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::Update;
use crate::blocks::{Block, ConfigBlock};
use crate::config::Config;
use crate::de::deserialize_duration;
use crate::errors::*;
use crate::scheduler::Task;
use crate::util::{battery_level_to_icon, format_percent_bar, read_file, FormatTemplate};
use crate::util::{
battery_level_to_icon, format_percent_bar, pseudo_uuid, read_file, FormatTemplate,
};
use crate::widget::{I3BarWidget, State};
use crate::widgets::text::TextWidget;

Expand Down Expand Up @@ -649,7 +650,7 @@ impl ConfigBlock for Battery {
_ => BatteryDriver::Sysfs,
};

let id = Uuid::new_v4().to_simple().to_string();
let id = pseudo_uuid().to_string();
let device: Box<dyn BatteryDevice> = match driver {
BatteryDriver::Upower => {
let out = UpowerDevice::from_device(&block_config.device)?;
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use std::time::Instant;

use crossbeam_channel::Sender;
use dbus::ffidisp::stdintf::org_freedesktop_dbus::{ObjectManager, Properties};
use uuid::Uuid;

use crate::blocks::Update;
use crate::blocks::{Block, ConfigBlock};
use crate::config::Config;
use crate::errors::*;
use crate::input::{I3BarEvent, MouseButton};
use crate::scheduler::Task;
use crate::util::pseudo_uuid;
use crate::widget::{I3BarWidget, State};
use crate::widgets::button::ButtonWidget;

Expand Down Expand Up @@ -180,7 +180,7 @@ impl ConfigBlock for Bluetooth {
type Config = BluetoothConfig;

fn new(block_config: Self::Config, config: Config, send: Sender<Task>) -> Result<Self> {
let id: String = Uuid::new_v4().to_simple().to_string();
let id: String = pseudo_uuid().to_string();
let device = BluetoothDevice::new(block_config.mac, block_config.label)?;
device.monitor(id.clone(), send);

Expand Down
5 changes: 2 additions & 3 deletions src/blocks/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::time::Duration;

use crossbeam_channel::Sender;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::Update;
use crate::blocks::{Block, ConfigBlock};
Expand All @@ -15,7 +14,7 @@ use crate::errors::*;
use crate::input::{I3BarEvent, MouseButton};
use crate::scheduler::Task;
use crate::subprocess::spawn_child_async;
use crate::util::{format_percent_bar, FormatTemplate};
use crate::util::{format_percent_bar, pseudo_uuid, FormatTemplate};
use crate::widget::{I3BarWidget, State};
use crate::widgets::button::ButtonWidget;

Expand Down Expand Up @@ -122,7 +121,7 @@ impl ConfigBlock for Cpu {
block_config.format
};

let id = Uuid::new_v4().to_simple().to_string();
let id = pseudo_uuid().to_string();

Ok(Cpu {
id: id.clone(),
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::vec;

use crossbeam_channel::Sender;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::{Block, ConfigBlock, Update};
use crate::config::Config;
Expand All @@ -16,6 +15,7 @@ use crate::input::I3BarEvent;
use crate::scheduler::Task;
use crate::signals::convert_to_valid_signal;
use crate::subprocess::spawn_child_async;
use crate::util::pseudo_uuid;
use crate::widget::{I3BarWidget, State};
use crate::widgets::button::ButtonWidget;

Expand Down Expand Up @@ -85,7 +85,7 @@ impl ConfigBlock for Custom {

fn new(block_config: Self::Config, config: Config, tx: Sender<Task>) -> Result<Self> {
let mut custom = Custom {
id: Uuid::new_v4().to_simple().to_string(),
id: pseudo_uuid().to_string(),
update_interval: block_config.interval,
output: ButtonWidget::new(config.clone(), ""),
command: None,
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/custom_dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use dbus::blocking::LocalConnection;
use dbus::strings::Signature;
use dbus::tree::Factory;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::{Block, ConfigBlock, Update};
use crate::config::Config;
use crate::errors::*;
use crate::input::I3BarEvent;
use crate::scheduler::Task;
use crate::util::pseudo_uuid;
use crate::widget::{I3BarWidget, State};
use crate::widgets::text::TextWidget;

Expand All @@ -41,7 +41,7 @@ impl ConfigBlock for CustomDBus {
type Config = CustomDBusConfig;

fn new(block_config: Self::Config, config: Config, send: Sender<Task>) -> Result<Self> {
let id: String = Uuid::new_v4().to_simple().to_string();
let id: String = pseudo_uuid().to_string();
let id_copy = id.clone();

let status_original = Arc::new(Mutex::new(CustomDBusStatus {
Expand Down
5 changes: 2 additions & 3 deletions src/blocks/disk_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ use std::time::Duration;
use crossbeam_channel::Sender;
use nix::sys::statvfs::statvfs;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::Update;
use crate::blocks::{Block, ConfigBlock};
use crate::config::Config;
use crate::de::deserialize_duration;
use crate::errors::*;
use crate::scheduler::Task;
use crate::util::{format_percent_bar, FormatTemplate};
use crate::util::{format_percent_bar, pseudo_uuid, FormatTemplate};
use crate::widget::{I3BarWidget, State};
use crate::widgets::text::TextWidget;

Expand Down Expand Up @@ -215,7 +214,7 @@ impl ConfigBlock for DiskSpace {
.unwrap_or_else(|| "".to_string());

Ok(DiskSpace {
id: Uuid::new_v4().to_simple().to_string(),
id: pseudo_uuid().to_string(),
update_interval: block_config.interval,
disk_space: TextWidget::new(config),
alias: block_config.alias,
Expand Down
5 changes: 2 additions & 3 deletions src/blocks/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::time::Duration;

use crossbeam_channel::Sender;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::Update;
use crate::blocks::{Block, ConfigBlock};
Expand All @@ -12,7 +11,7 @@ use crate::de::deserialize_duration;
use crate::errors::*;
use crate::input::I3BarEvent;
use crate::scheduler::Task;
use crate::util::FormatTemplate;
use crate::util::{pseudo_uuid, FormatTemplate};
use crate::widget::I3BarWidget;
use crate::widgets::text::TextWidget;

Expand Down Expand Up @@ -70,7 +69,7 @@ impl ConfigBlock for Docker {

fn new(block_config: Self::Config, config: Config, _: Sender<Task>) -> Result<Self> {
Ok(Docker {
id: Uuid::new_v4().to_simple().to_string(),
id: pseudo_uuid().to_string(),
text: TextWidget::new(config).with_text("N/A").with_icon("docker"),
format: FormatTemplate::from_string(&block_config.format)
.block_error("docker", "Invalid format specified")?,
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/focused_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crossbeam_channel::Sender;
use serde_derive::Deserialize;
use swayipc::reply::{Event, Node, WindowChange, WorkspaceChange};
use swayipc::{Connection, EventType};
use uuid::Uuid;

use crate::blocks::{Block, ConfigBlock, Update};
use crate::config::Config;
use crate::errors::*;
use crate::scheduler::Task;
use crate::util::pseudo_uuid;
use crate::widget::I3BarWidget;
use crate::widgets::text::TextWidget;

Expand Down Expand Up @@ -58,7 +58,7 @@ impl ConfigBlock for FocusedWindow {
type Config = FocusedWindowConfig;

fn new(block_config: Self::Config, config: Config, tx: Sender<Task>) -> Result<Self> {
let id = Uuid::new_v4().to_simple().to_string();
let id = pseudo_uuid().to_string();
let id_clone = id.clone();

let title = Arc::new(Mutex::new(String::from("")));
Expand Down
5 changes: 2 additions & 3 deletions src/blocks/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ use crossbeam_channel::Sender;
use lazy_static::lazy_static;
use regex::Regex;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::{Block, ConfigBlock, Update};
use crate::config::Config;
use crate::de::deserialize_duration;
use crate::errors::*;
use crate::input::I3BarEvent;
use crate::scheduler::Task;
use crate::util::FormatTemplate;
use crate::util::{pseudo_uuid, FormatTemplate};
use crate::widget::I3BarWidget;
use crate::widgets::text::TextWidget;

Expand Down Expand Up @@ -76,7 +75,7 @@ impl ConfigBlock for Github {
};

Ok(Github {
id: Uuid::new_v4().to_simple().to_string(),
id: pseudo_uuid().to_string(),
update_interval: block_config.interval,
text: TextWidget::new(config).with_text("x").with_icon("github"),
api_server: block_config.api_server,
Expand Down
5 changes: 2 additions & 3 deletions src/blocks/hueshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ use std::time::Duration;

use crossbeam_channel::Sender;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::{Block, ConfigBlock, Update};
use crate::config::{Config, LogicalDirection};
use crate::de::deserialize_duration;
use crate::errors::*;
use crate::input::{I3BarEvent, MouseButton};
use crate::scheduler::Task;
use crate::util::has_command;
use crate::util::{has_command, pseudo_uuid};
use crate::widget::I3BarWidget;
use crate::widgets::button::ButtonWidget;

Expand Down Expand Up @@ -121,7 +120,7 @@ impl ConfigBlock for Hueshift {
) -> Result<Self> {
let current_temp = block_config.current_temp;
let mut step = block_config.step;
let id = Uuid::new_v4().to_simple().to_string();
let id = pseudo_uuid().to_string();
let mut max_temp = block_config.max_temp;
let mut min_temp = block_config.min_temp;
// limit too big steps at 500K to avoid too brutal changes
Expand Down
5 changes: 2 additions & 3 deletions src/blocks/ibus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ use dbus::{
};
use regex::Regex;
use serde_derive::Deserialize;
use uuid::Uuid;

use crate::blocks::Update;
use crate::blocks::{Block, ConfigBlock};
use crate::config::Config;
use crate::errors::*;
use crate::input::I3BarEvent;
use crate::scheduler::Task;
use crate::util::{xdg_config_home, FormatTemplate};
use crate::util::{pseudo_uuid, xdg_config_home, FormatTemplate};
use crate::widget::I3BarWidget;
use crate::widgets::text::TextWidget;

Expand Down Expand Up @@ -62,7 +61,7 @@ impl ConfigBlock for IBus {

#[allow(clippy::many_single_char_names)]
fn new(block_config: Self::Config, config: Config, send: Sender<Task>) -> Result<Self> {
let id: String = Uuid::new_v4().to_simple().to_string();
let id: String = pseudo_uuid().to_string();
let id_copy = id.clone();
let id_copy2 = id.clone();
let send2 = send.clone();
Expand Down
Loading

0 comments on commit 2538831

Please sign in to comment.