From d484c05e56194346944b295968c66ccc0e543534 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Wed, 24 Mar 2021 21:38:51 +0100 Subject: remove ipc-channel dependency --- Cargo.lock | 294 +++++++--------------------------------------------- mumctl/Cargo.toml | 2 +- mumctl/src/main.rs | 19 ++-- mumd/Cargo.toml | 4 +- mumd/src/client.rs | 5 +- mumd/src/command.rs | 3 +- mumd/src/main.rs | 73 ++++++------- 7 files changed, 89 insertions(+), 311 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62ff857..ac92332 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -39,7 +39,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -125,12 +125,6 @@ dependencies = [ "nom", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -172,7 +166,7 @@ checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" dependencies = [ "atty", "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -248,28 +242,7 @@ dependencies = [ "stdweb", "thiserror", "web-sys", - "winapi 0.3.9", -] - -[[package]] -name = "crossbeam-channel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" -dependencies = [ - "crossbeam-utils", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-utils" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", + "winapi", ] [[package]] @@ -439,22 +412,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures-channel" version = "0.3.13" @@ -538,26 +495,15 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -651,35 +597,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - -[[package]] -name = "ipc-channel" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9b32d360ae2d4662212f1d29bc8a277256f49029cea20fd6c182b89819aea7" -dependencies = [ - "bincode", - "crossbeam-channel", - "fnv", - "lazy_static", - "libc", - "mio 0.6.23", - "rand 0.7.3", - "serde", - "tempfile", - "uuid", - "winapi 0.3.9", + "cfg-if", ] [[package]] @@ -720,16 +638,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -754,8 +662,8 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" dependencies = [ - "cfg-if 1.0.0", - "winapi 0.3.9", + "cfg-if", + "winapi", ] [[package]] @@ -801,7 +709,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -813,37 +721,12 @@ dependencies = [ "libc", ] -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.2", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.7.10" @@ -852,21 +735,9 @@ checksum = "2182a122f3b7f3f5329cb1972cee089ba2459a0a80a56935e6e674f096f8d839" dependencies = [ "libc", "log", - "miow 0.3.6", + "miow", "ntapi", - "winapi 0.3.9", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "winapi", ] [[package]] @@ -876,7 +747,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ "socket2", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -897,9 +768,9 @@ dependencies = [ name = "mumctl" version = "0.3.0" dependencies = [ + "bincode", "clap", "colored", - "ipc-channel", "log", "mumlib", ] @@ -908,6 +779,7 @@ dependencies = [ name = "mumd" version = "0.3.0" dependencies = [ + "bincode", "bytes", "cpal", "dasp_frame", @@ -918,7 +790,6 @@ dependencies = [ "futures-channel", "futures-util", "hound", - "ipc-channel", "libnotify", "log", "mumble-protocol", @@ -1009,17 +880,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c44922cb3dbb1c70b5e5f443d63b64363a898564d739ba5198e3a9138442868d" -[[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "nix" version = "0.20.0" @@ -1028,7 +888,7 @@ checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" dependencies = [ "bitflags", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", ] @@ -1048,7 +908,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1139,7 +999,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "foreign-types", "libc", "once_cell", @@ -1202,12 +1062,12 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "instant", "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1304,19 +1164,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - [[package]] name = "rand" version = "0.8.3" @@ -1324,19 +1171,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" dependencies = [ "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -1346,16 +1183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -1364,16 +1192,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.2", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -1382,7 +1201,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" dependencies = [ - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -1415,7 +1234,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1440,7 +1259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1516,9 +1335,9 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1574,12 +1393,12 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", - "rand 0.8.3", + "rand", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1618,8 +1437,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" dependencies = [ "autocfg", + "bytes", "libc", - "mio 0.7.10", + "memchr", + "mio", "num_cpus", "pin-project-lite", "tokio-macros", @@ -1698,15 +1519,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom 0.2.2", -] - [[package]] name = "vcpkg" version = "0.2.11" @@ -1732,16 +1544,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -1754,7 +1560,7 @@ version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -1812,12 +1618,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -1828,12 +1628,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1846,7 +1640,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1855,16 +1649,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "yaml-rust" version = "0.3.5" diff --git a/mumctl/Cargo.toml b/mumctl/Cargo.toml index b22ca02..02326c8 100644 --- a/mumctl/Cargo.toml +++ b/mumctl/Cargo.toml @@ -16,6 +16,6 @@ mumlib = { version = "0.3", path = "../mumlib" } clap = { version = "2.33", features = ["yaml"] } colored = "2.0" log = "0.4" -ipc-channel = "0.15" +bincode = "1.3.2" #cursive = "0.15" diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index d07a482..3cbbcf7 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -1,15 +1,15 @@ use clap::{App, AppSettings, Arg, Shell, SubCommand, ArgMatches}; use colored::Colorize; -use ipc_channel::ipc::{self, IpcSender}; use log::{error, warn}; use log::{Record, Level, Metadata, LevelFilter}; use mumlib::command::{Command, CommandResponse}; use mumlib::config; use mumlib::config::{ServerConfig, Config}; use mumlib::state::Channel; -use std::io::BufRead; -use std::{fs, io, iter, fmt}; +use std::io::{BufRead, Write}; +use std::{io::{self, Read}, iter, fmt}; use std::fmt::{Display, Formatter}; +use std::os::unix::net::UnixStream; const INDENTATION: &str = " "; @@ -615,16 +615,17 @@ fn parse_status(server_state: &mumlib::state::Server) { } fn send_command(command: Command) -> Result>, crate::Error> { - let (tx_client, rx_client) = - ipc::channel::>>().unwrap(); + let mut connection = UnixStream::connect("/tmp/mumd").unwrap(); - let server_name = fs::read_to_string(mumlib::SOCKET_PATH).unwrap(); //TODO don't panic + let serialized = bincode::serialize(&command).unwrap(); - let tx0 = IpcSender::connect(server_name).map_err(|_| Error::ConnectionError)?; + connection.write(&(serialized.len() as u32).to_be_bytes()).unwrap(); + connection.write(&serialized).unwrap(); - tx0.send((command, tx_client)).unwrap(); + connection.read_exact(&mut [0; 4]).unwrap(); + let response = bincode::deserialize_from(&mut connection).unwrap(); - Ok(rx_client.recv().unwrap()) + Ok(response) } fn print_channel(channel: &Channel, depth: usize) { diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index 9080bdf..f271e69 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -28,7 +28,6 @@ dasp_ring_buffer = "0.11" futures-util = { version = "0.3", features = ["sink"]} futures-channel = "0.3" hound = "3.4" -ipc-channel = "0.15" log = "0.4" mumble-protocol = "0.4.1" native-tls = "0.2" @@ -37,10 +36,11 @@ opus = "0.2" serde = { version = "1.0", features = ["derive"] } strum = "0.20" strum_macros = "0.20" -tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time"] } +tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time", "io-util"] } tokio-stream = "0.1.0" tokio-native-tls = "0.3" tokio-util = { version = "0.6", features = ["codec", "net"] } +bincode = "1.3.2" libnotify = { version = "1.0", optional = true } diff --git a/mumd/src/client.rs b/mumd/src/client.rs index 84c1ea1..cdae7eb 100644 --- a/mumd/src/client.rs +++ b/mumd/src/client.rs @@ -2,16 +2,15 @@ use crate::command; use crate::network::{tcp, udp, ConnectionInfo}; use crate::state::State; -use ipc_channel::ipc::IpcSender; use mumble_protocol::{Serverbound, control::ControlPacket, crypt::ClientCryptState}; use mumlib::command::{Command, CommandResponse}; use std::sync::Arc; -use tokio::{join, sync::{mpsc, watch, Mutex}}; +use tokio::{join, sync::{Mutex, mpsc, oneshot, watch}}; pub async fn handle( command_receiver: mpsc::UnboundedReceiver<( Command, - IpcSender>>, + oneshot::Sender>>, )>, ) { let (connection_info_sender, connection_info_receiver) = diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 653d1fa..3e462b1 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -5,7 +5,6 @@ use crate::network::{ }; use crate::state::{ExecutionContext, State}; -use ipc_channel::ipc::IpcSender; use log::*; use mumble_protocol::{Serverbound, control::ControlPacket}; use mumlib::command::{Command, CommandResponse}; @@ -16,7 +15,7 @@ pub async fn handle( state: Arc>, mut command_receiver: mpsc::UnboundedReceiver<( Command, - IpcSender>>, + oneshot::Sender>>, )>, tcp_event_register_sender: mpsc::UnboundedSender<(TcpEvent, TcpEventCallback)>, ping_request_sender: mpsc::UnboundedSender, diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 7c3745c..d4151e3 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -5,13 +5,14 @@ mod network; mod notify; mod state; -use ipc_channel::ipc::{self, IpcOneShotServer, IpcSender}; +use futures_util::StreamExt; +//use ipc_channel::ipc::{self, IpcOneShotServer, IpcSender}; use log::*; use mumlib::command::{Command, CommandResponse}; use mumlib::setup_logger; -use std::fs; -use tokio::{join, sync::mpsc}; -use tokio::task::spawn_blocking; +use tokio::{join, net::UnixListener, sync::{mpsc, oneshot}}; +use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec}; +use bytes::{BufMut, BytesMut}; #[tokio::main] async fn main() { @@ -24,7 +25,7 @@ async fn main() { notify::init(); // check if another instance is live - let (tx_client, rx_client) = + /*let (tx_client, rx_client) = ipc::channel::>>().unwrap(); if let Ok(server_name) = fs::read_to_string(mumlib::SOCKET_PATH) { if let Ok(tx0) = IpcSender::connect(server_name) { @@ -41,50 +42,44 @@ async fn main() { } } } - } + }*/ - let (command_sender, command_receiver) = mpsc::unbounded_channel::<( - Command, - IpcSender>>, - )>(); + let (command_sender, command_receiver) = mpsc::unbounded_channel(); - let (_, e) = join!( + join!( client::handle(command_receiver), - spawn_blocking(move || { - // IpcSender is blocking - receive_oneshot_commands(command_sender); - }), + receive_commands(command_sender), ); - e.unwrap(); } -fn receive_oneshot_commands( +async fn receive_commands( command_sender: mpsc::UnboundedSender<( Command, - IpcSender>>, + oneshot::Sender>>, )>, ) { + let socket = UnixListener::bind("/tmp/mumd").unwrap(); + loop { - // create listener - let (server, server_name): ( - IpcOneShotServer<( - Command, - IpcSender>>, - )>, - String, - ) = IpcOneShotServer::new().unwrap(); - fs::write(mumlib::SOCKET_PATH, &server_name).unwrap(); - debug!("Listening to {}", server_name); + if let Ok((incoming, _)) = socket.accept().await { + let (reader, writer) = incoming.into_split(); + let reader = FramedRead::new(reader, LengthDelimitedCodec::new()); + let writer = FramedWrite::new(writer, LengthDelimitedCodec::new()); + + reader.filter_map(|buf| async { + buf.ok() + }) + .map(|buf| bincode::deserialize::(&buf).unwrap()) + .filter_map(|command| async { + let (tx, rx) = oneshot::channel(); - // receive command and response channel - let (_, conn): ( - _, - ( - Command, - IpcSender>>, - ), - ) = server.accept().unwrap(); - debug!("Sending command {:?} to command handler", conn.0); - command_sender.send(conn).unwrap(); + command_sender.send((command, tx)).unwrap(); + + let response = rx.await.unwrap(); + let mut serialized = BytesMut::new(); + bincode::serialize_into((&mut serialized).writer(), &response).unwrap(); + Some(Ok(serialized.freeze())) + }).forward(writer).await.unwrap(); + } } -} +} \ No newline at end of file -- cgit v1.2.1 From 169eb4f49f3fd587e9c28f2209b2dd130425d866 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:10:09 +0100 Subject: re-add check for live server --- mumd/Cargo.toml | 2 +- mumd/src/main.rs | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index f271e69..7f0739b 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -36,7 +36,7 @@ opus = "0.2" serde = { version = "1.0", features = ["derive"] } strum = "0.20" strum_macros = "0.20" -tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time", "io-util"] } +tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time", "io-util", "fs"] } tokio-stream = "0.1.0" tokio-native-tls = "0.3" tokio-util = { version = "0.6", features = ["codec", "net"] } diff --git a/mumd/src/main.rs b/mumd/src/main.rs index d4151e3..5b22089 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -5,12 +5,12 @@ mod network; mod notify; mod state; -use futures_util::StreamExt; +use futures_util::{SinkExt, StreamExt}; //use ipc_channel::ipc::{self, IpcOneShotServer, IpcSender}; use log::*; use mumlib::command::{Command, CommandResponse}; use mumlib::setup_logger; -use tokio::{join, net::UnixListener, sync::{mpsc, oneshot}}; +use tokio::{join, net::{UnixListener, UnixStream}, sync::{mpsc, oneshot}}; use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec}; use bytes::{BufMut, BytesMut}; @@ -25,24 +25,32 @@ async fn main() { notify::init(); // check if another instance is live - /*let (tx_client, rx_client) = - ipc::channel::>>().unwrap(); - if let Ok(server_name) = fs::read_to_string(mumlib::SOCKET_PATH) { - if let Ok(tx0) = IpcSender::connect(server_name) { - if tx0.send((Command::Ping, tx_client)).is_ok() { - match rx_client.recv() { - Ok(Ok(Some(CommandResponse::Pong))) => { + let connection = UnixStream::connect("/tmp/mumd").await; + match connection { + Ok(stream) => { + let (reader, writer) = stream.into_split(); + let mut reader = FramedRead::new(reader, LengthDelimitedCodec::new()); + let mut writer = FramedWrite::new(writer, LengthDelimitedCodec::new()); + let mut command = BytesMut::new(); + bincode::serialize_into((&mut command).writer(), &Command::Ping).unwrap(); + if let Ok(()) = writer.send(command.freeze()).await { + if let Some(Ok(buf)) = reader.next().await { + if let Ok(Ok::, mumlib::error::Error>(Some(CommandResponse::Pong))) = bincode::deserialize(&buf) { error!("Another instance of mumd is already running"); return; - }, - resp => { - warn!("Ping with weird response. Continuing..."); - debug!("Response was {:?}", resp); } } } + debug!("a dead socket was found, removing"); + tokio::fs::remove_file("/tmp/mumd").await.unwrap(); } - }*/ + Err(e) => { + if matches!(e.kind(), std::io::ErrorKind::ConnectionRefused) { + debug!("a dead socket was found, removing"); + tokio::fs::remove_file("/tmp/mumd").await.unwrap(); + } + } + } let (command_sender, command_receiver) = mpsc::unbounded_channel(); -- cgit v1.2.1 From 5cc61e8d2140280421b5962b2911ebbcc927e9d1 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:15:55 +0100 Subject: re-add error checking --- mumctl/src/main.rs | 10 +++++----- mumd/src/main.rs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 3cbbcf7..123f5cd 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -615,15 +615,15 @@ fn parse_status(server_state: &mumlib::state::Server) { } fn send_command(command: Command) -> Result>, crate::Error> { - let mut connection = UnixStream::connect("/tmp/mumd").unwrap(); + let mut connection = UnixStream::connect("/tmp/mumd").map_err(|_| Error::ConnectionError)?; let serialized = bincode::serialize(&command).unwrap(); - connection.write(&(serialized.len() as u32).to_be_bytes()).unwrap(); - connection.write(&serialized).unwrap(); + connection.write(&(serialized.len() as u32).to_be_bytes()).map_err(|_| Error::ConnectionError)?; + connection.write(&serialized).map_err(|_| Error::ConnectionError)?; - connection.read_exact(&mut [0; 4]).unwrap(); - let response = bincode::deserialize_from(&mut connection).unwrap(); + connection.read_exact(&mut [0; 4]).map_err(|_| Error::ConnectionError)?; + let response = bincode::deserialize_from(&mut connection).map_err(|_| Error::ConnectionError)?; Ok(response) } diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 5b22089..18b84b8 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -77,7 +77,8 @@ async fn receive_commands( reader.filter_map(|buf| async { buf.ok() }) - .map(|buf| bincode::deserialize::(&buf).unwrap()) + .map(|buf| bincode::deserialize::(&buf)) + .filter_map(|e| async { e.ok() }) .filter_map(|command| async { let (tx, rx) = oneshot::channel(); -- cgit v1.2.1 From e8f80aeb9afe036eb93e750d4678f55267b520ca Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:19:56 +0100 Subject: remove unneeded feature --- Cargo.lock | 2 -- mumd/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac92332..3bb9e3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1437,9 +1437,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" dependencies = [ "autocfg", - "bytes", "libc", - "memchr", "mio", "num_cpus", "pin-project-lite", diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml index 7f0739b..a853622 100644 --- a/mumd/Cargo.toml +++ b/mumd/Cargo.toml @@ -36,7 +36,7 @@ opus = "0.2" serde = { version = "1.0", features = ["derive"] } strum = "0.20" strum_macros = "0.20" -tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time", "io-util", "fs"] } +tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "net", "time", "fs"] } tokio-stream = "0.1.0" tokio-native-tls = "0.3" tokio-util = { version = "0.6", features = ["codec", "net"] } -- cgit v1.2.1 From 0f677fff3f48d4d17ece37060323ce19a41d87ad Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:20:16 +0100 Subject: remove code comment --- mumd/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 18b84b8..c596b8f 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -6,7 +6,6 @@ mod notify; mod state; use futures_util::{SinkExt, StreamExt}; -//use ipc_channel::ipc::{self, IpcOneShotServer, IpcSender}; use log::*; use mumlib::command::{Command, CommandResponse}; use mumlib::setup_logger; -- cgit v1.2.1 From b0034ec3e344030274c98cf81f75789d80ce6211 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:23:57 +0100 Subject: use constant string for socket path --- mumd/src/main.rs | 8 ++++---- mumlib/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mumd/src/main.rs b/mumd/src/main.rs index c596b8f..5b71ae0 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -24,7 +24,7 @@ async fn main() { notify::init(); // check if another instance is live - let connection = UnixStream::connect("/tmp/mumd").await; + let connection = UnixStream::connect(mumlib::SOCKET_PATH).await; match connection { Ok(stream) => { let (reader, writer) = stream.into_split(); @@ -41,12 +41,12 @@ async fn main() { } } debug!("a dead socket was found, removing"); - tokio::fs::remove_file("/tmp/mumd").await.unwrap(); + tokio::fs::remove_file(mumlib::SOCKET_PATH).await.unwrap(); } Err(e) => { if matches!(e.kind(), std::io::ErrorKind::ConnectionRefused) { debug!("a dead socket was found, removing"); - tokio::fs::remove_file("/tmp/mumd").await.unwrap(); + tokio::fs::remove_file(mumlib::SOCKET_PATH).await.unwrap(); } } } @@ -65,7 +65,7 @@ async fn receive_commands( oneshot::Sender>>, )>, ) { - let socket = UnixListener::bind("/tmp/mumd").unwrap(); + let socket = UnixListener::bind(mumlib::SOCKET_PATH).unwrap(); loop { if let Ok((incoming, _)) = socket.accept().await { diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs index 439efa9..bccf073 100644 --- a/mumlib/src/lib.rs +++ b/mumlib/src/lib.rs @@ -6,7 +6,7 @@ pub mod state; use colored::*; use log::*; -pub const SOCKET_PATH: &str = "/var/tmp/mumd"; +pub const SOCKET_PATH: &str = "/tmp/mumd"; pub const DEFAULT_PORT: u16 = 64738; pub fn setup_logger>(target: T, color: bool) { -- cgit v1.2.1 From 8afd49fcb78bd725ef602e48b73d42a91673d0c5 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:48:09 +0100 Subject: make command receiving scaleable --- mumd/src/main.rs | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 5b71ae0..6303978 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -69,25 +69,34 @@ async fn receive_commands( loop { if let Ok((incoming, _)) = socket.accept().await { - let (reader, writer) = incoming.into_split(); - let reader = FramedRead::new(reader, LengthDelimitedCodec::new()); - let writer = FramedWrite::new(writer, LengthDelimitedCodec::new()); + let sender = command_sender.clone(); + tokio::spawn(async move { + let (reader, writer) = incoming.into_split(); + let mut reader = FramedRead::new(reader, LengthDelimitedCodec::new()); + let mut writer = FramedWrite::new(writer, LengthDelimitedCodec::new()); + + while let Some(next) = reader.next().await { + let buf = match next { + Ok(buf) => buf, + Err(_) => continue, + }; - reader.filter_map(|buf| async { - buf.ok() - }) - .map(|buf| bincode::deserialize::(&buf)) - .filter_map(|e| async { e.ok() }) - .filter_map(|command| async { - let (tx, rx) = oneshot::channel(); + let command = match bincode::deserialize::(&buf) { + Ok(e) => e, + Err(_) => continue, + }; - command_sender.send((command, tx)).unwrap(); + let (tx, rx) = oneshot::channel(); - let response = rx.await.unwrap(); - let mut serialized = BytesMut::new(); - bincode::serialize_into((&mut serialized).writer(), &response).unwrap(); - Some(Ok(serialized.freeze())) - }).forward(writer).await.unwrap(); + sender.send((command, tx)).unwrap(); + + let response = rx.await.unwrap(); + let mut serialized = BytesMut::new(); + bincode::serialize_into((&mut serialized).writer(), &response).unwrap(); + + let _ = writer.send(serialized.freeze()).await; + } + }); } } } \ No newline at end of file -- cgit v1.2.1 From c22a8731df928ebce1859728cd55873503f72982 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:50:16 +0100 Subject: clean up imports --- mumctl/src/main.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 123f5cd..018bc3a 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -1,15 +1,10 @@ use clap::{App, AppSettings, Arg, Shell, SubCommand, ArgMatches}; use colored::Colorize; -use log::{error, warn}; -use log::{Record, Level, Metadata, LevelFilter}; +use log::{Record, Level, Metadata, LevelFilter, error, warn}; use mumlib::command::{Command, CommandResponse}; -use mumlib::config; -use mumlib::config::{ServerConfig, Config}; +use mumlib::config::{self, ServerConfig, Config}; use mumlib::state::Channel; -use std::io::{BufRead, Write}; -use std::{io::{self, Read}, iter, fmt}; -use std::fmt::{Display, Formatter}; -use std::os::unix::net::UnixStream; +use std::{io::{self, Read, BufRead, Write}, iter, fmt::{Display, Formatter}, os::unix::net::UnixStream}; const INDENTATION: &str = " "; -- cgit v1.2.1 From bb81c02ddf4f9cc6ab0dbceea890e1be06fdbcf0 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 28 Mar 2021 17:42:45 +0200 Subject: fix import --- mumctl/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 018bc3a..0b948c0 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -654,7 +654,7 @@ enum Error { } impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "Unable to connect to mumd. Is mumd running?") } } -- cgit v1.2.1 From 0e56945163d1447b2127f5499f6b897b41271d40 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 29 Mar 2021 00:45:09 +0200 Subject: update according to feedback --- mumctl/src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 0b948c0..9d9e4fd 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -610,7 +610,7 @@ fn parse_status(server_state: &mumlib::state::Server) { } fn send_command(command: Command) -> Result>, crate::Error> { - let mut connection = UnixStream::connect("/tmp/mumd").map_err(|_| Error::ConnectionError)?; + let mut connection = UnixStream::connect(mumlib::SOCKET_PATH).map_err(|_| Error::ConnectionError)?; let serialized = bincode::serialize(&command).unwrap(); @@ -618,9 +618,7 @@ fn send_command(command: Command) -> Result Date: Mon, 29 Mar 2021 00:46:23 +0200 Subject: re-add trailing newline --- mumctl/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 9d9e4fd..7475d4d 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -656,3 +656,4 @@ impl Display for Error { write!(f, "Unable to connect to mumd. Is mumd running?") } } + -- cgit v1.2.1 From d0eb98decf0d78957acc870624c338b75fc24edf Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 29 Mar 2021 00:47:26 +0200 Subject: re-add trailing newline 2 electric boogaloo --- mumctl/src/main.rs | 1 - mumd/src/main.rs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 7475d4d..9d9e4fd 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -656,4 +656,3 @@ impl Display for Error { write!(f, "Unable to connect to mumd. Is mumd running?") } } - diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 6303978..f7168c4 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -99,4 +99,5 @@ async fn receive_commands( }); } } -} \ No newline at end of file +} + -- cgit v1.2.1 From 80cedde5d6868f5e4db85db2c80825e49d981a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 29 Mar 2021 11:16:35 +0200 Subject: remove extra newline --- mumd/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/mumd/src/main.rs b/mumd/src/main.rs index f7168c4..26e8d49 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -100,4 +100,3 @@ async fn receive_commands( } } } - -- cgit v1.2.1