diff options
| author | Eskil Queseth <eskilq@kth.se> | 2021-03-24 21:38:51 +0100 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2021-03-24 21:38:51 +0100 |
| commit | d484c05e56194346944b295968c66ccc0e543534 (patch) | |
| tree | 41ee9fba2ad0841bffbd04b805ae6d675be7fb52 | |
| parent | a5c26eaad44c45da852027d707bf1d8e838ed901 (diff) | |
| download | mum-d484c05e56194346944b295968c66ccc0e543534.tar.gz | |
remove ipc-channel dependency
| -rw-r--r-- | Cargo.lock | 294 | ||||
| -rw-r--r-- | mumctl/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumctl/src/main.rs | 19 | ||||
| -rw-r--r-- | mumd/Cargo.toml | 4 | ||||
| -rw-r--r-- | mumd/src/client.rs | 5 | ||||
| -rw-r--r-- | mumd/src/command.rs | 3 | ||||
| -rw-r--r-- | mumd/src/main.rs | 73 |
7 files changed, 89 insertions, 311 deletions
@@ -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]] @@ -127,12 +127,6 @@ dependencies = [ [[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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" @@ -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]] @@ -440,22 +413,6 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -540,24 +497,13 @@ dependencies = [ [[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]] @@ -721,16 +639,6 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -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]] @@ -814,12 +722,6 @@ dependencies = [ ] [[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" @@ -827,46 +729,15 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" 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", @@ -1010,17 +881,6 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -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]] @@ -1306,37 +1166,14 @@ dependencies = [ [[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" 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", @@ -1699,15 +1520,6 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1732,18 +1544,12 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" @@ -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", ] @@ -1814,12 +1620,6 @@ dependencies = [ [[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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" @@ -1829,12 +1629,6 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -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]] @@ -1856,16 +1650,6 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" 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<mumlib::error::Result<Option<CommandResponse>>, crate::Error> { - let (tx_client, rx_client) = - ipc::channel::<mumlib::error::Result<Option<CommandResponse>>>().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<mumlib::error::Result<Option<CommandResponse>>>, + oneshot::Sender<mumlib::error::Result<Option<CommandResponse>>>, )>, ) { 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<Mutex<State>>, mut command_receiver: mpsc::UnboundedReceiver<( Command, - IpcSender<mumlib::error::Result<Option<CommandResponse>>>, + oneshot::Sender<mumlib::error::Result<Option<CommandResponse>>>, )>, tcp_event_register_sender: mpsc::UnboundedSender<(TcpEvent, TcpEventCallback)>, ping_request_sender: mpsc::UnboundedSender<PingRequest>, 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::<mumlib::error::Result<Option<CommandResponse>>>().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<mumlib::error::Result<Option<CommandResponse>>>, - )>(); + 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<mumlib::error::Result<Option<CommandResponse>>>, + oneshot::Sender<mumlib::error::Result<Option<CommandResponse>>>, )>, ) { + let socket = UnixListener::bind("/tmp/mumd").unwrap(); + loop { - // create listener - let (server, server_name): ( - IpcOneShotServer<( - Command, - IpcSender<mumlib::error::Result<Option<CommandResponse>>>, - )>, - 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::<Command>(&buf).unwrap()) + .filter_map(|command| async { + let (tx, rx) = oneshot::channel(); - // receive command and response channel - let (_, conn): ( - _, - ( - Command, - IpcSender<mumlib::error::Result<Option<CommandResponse>>>, - ), - ) = 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 |
