Use redis-rs, implement better info op handling, implement CHANNEL_REQ

This needs to be cleaned up
This commit is contained in:
Evie Viau 2022-02-19 18:10:45 -05:00
parent d0a5454231
commit 50d9252815
No known key found for this signature in database
GPG key ID: DBCFB51C41FF87FF
8 changed files with 165 additions and 576 deletions

548
Cargo.lock generated
View file

@ -2,21 +2,6 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
dependencies = [
"memchr",
]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "async-trait"
version = "0.1.52"
@ -28,17 +13,6 @@ dependencies = [
"syn",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -50,7 +24,6 @@ name = "bannana-pho"
version = "0.1.0"
dependencies = [
"dotenv",
"fred",
"futures-util",
"hex",
"hmac",
@ -58,6 +31,7 @@ dependencies = [
"num-derive",
"num-traits",
"rand",
"redis",
"serde",
"serde_json",
"serde_repr",
@ -78,18 +52,6 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
version = "0.19.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55f93d0ef3363c364d5976646a38f04cf67cfe1d4c8d160cdea02cab2c116b33"
dependencies = [
"funty",
"radium",
"tap",
"wyz",
]
[[package]]
name = "block-buffer"
version = "0.9.0"
@ -120,12 +82,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -133,27 +89,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cookie-factory"
version = "0.3.2"
name = "combine"
version = "4.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "396de984970346b0d9e93d1415082923c679e5ae5c3ee3dcbd104f5610af126b"
[[package]]
name = "core-foundation"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
checksum = "50b727aacc797f9fc28e355d21f34709ac4fc9adecfe470ad07b8f4464f53062"
dependencies = [
"core-foundation-sys",
"libc",
"bytes",
"memchr",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "cpufeatures"
version = "0.2.1"
@ -163,12 +107,6 @@ dependencies = [
"libc",
]
[[package]]
name = "crc16"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "338089f42c427b86394a5ee60ff321da23a5c89c9d89514c829687b26359fcff"
[[package]]
name = "crypto-common"
version = "0.1.3"
@ -206,35 +144,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "env_logger"
version = "0.7.1"
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "fastrand"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
dependencies = [
"instant",
]
[[package]]
name = "float-cmp"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4"
dependencies = [
"num-traits",
]
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]]
name = "fnv"
@ -242,21 +155,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.0.1"
@ -267,86 +165,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "fred"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1868cfe5b3189eccde798b4893d4b6b09e9cac5729a94035eed290b795fe7dfe"
dependencies = [
"async-trait",
"bytes",
"float-cmp",
"futures",
"lazy_static",
"log",
"native-tls",
"parking_lot 0.11.2",
"pretty_env_logger",
"rand",
"redis-protocol",
"semver",
"sha-1",
"tokio",
"tokio-native-tls",
"tokio-stream",
"tokio-util",
"url",
]
[[package]]
name = "funty"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
[[package]]
name = "futures"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
[[package]]
name = "futures-executor"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]]
name = "futures-macro"
version = "0.3.21"
@ -376,13 +200,10 @@ version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
@ -441,7 +262,7 @@ checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03"
dependencies = [
"bytes",
"fnv",
"itoa",
"itoa 1.0.1",
]
[[package]]
@ -450,15 +271,6 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4"
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
]
[[package]]
name = "idna"
version = "0.2.3"
@ -471,13 +283,10 @@ dependencies = [
]
[[package]]
name = "instant"
version = "0.1.12"
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
@ -485,25 +294,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]]
name = "libc"
version = "0.2.118"
@ -562,37 +352,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "native-tls"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d"
dependencies = [
"lazy_static",
"libc",
"log",
"openssl",
"openssl-probe",
"openssl-sys",
"schannel",
"security-framework",
"security-framework-sys",
"tempfile",
]
[[package]]
name = "nom"
version = "6.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c5c51b9083a3c620fa67a2a635d1ce7d95b897e957d6b28ff9a5da960a103a6"
dependencies = [
"bitvec",
"funty",
"lexical-core",
"memchr",
"version_check",
]
[[package]]
name = "ntapi"
version = "0.3.7"
@ -711,50 +470,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "openssl"
version = "0.10.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95"
dependencies = [
"bitflags",
"cfg-if",
"foreign-types",
"libc",
"once_cell",
"openssl-sys",
]
[[package]]
name = "openssl-probe"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb"
dependencies = [
"autocfg",
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core 0.8.5",
]
[[package]]
name = "parking_lot"
version = "0.12.0"
@ -762,21 +477,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"lock_api",
"parking_lot_core 0.9.1",
]
[[package]]
name = "parking_lot_core"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
"parking_lot_core",
]
[[package]]
@ -810,28 +511,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "ppv-lite86"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "pretty_env_logger"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d"
dependencies = [
"env_logger",
"log",
]
[[package]]
name = "proc-macro2"
version = "1.0.36"
@ -841,12 +526,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.15"
@ -856,12 +535,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "radium"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
[[package]]
name = "rand"
version = "0.8.5"
@ -893,16 +566,18 @@ dependencies = [
]
[[package]]
name = "redis-protocol"
version = "3.1.0"
name = "redis"
version = "0.21.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb7023bcb2073713373c72c4096ec4fee06819b3047991b8c187e8c00072d3"
checksum = "1a80b5f38d7f5a020856a0e16e40a9cfabf88ae8f0e4c2dcd8a3114c1e470852"
dependencies = [
"bytes",
"cookie-factory",
"crc16",
"log",
"nom",
"async-trait",
"combine",
"dtoa",
"itoa 0.4.8",
"percent-encoding",
"sha1",
"url",
]
[[package]]
@ -914,83 +589,18 @@ dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
]
[[package]]
name = "ryu"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "schannel"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
dependencies = [
"lazy_static",
"winapi",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "security-framework"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "semver"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0486718e92ec9a68fbed73bb5ef687d71103b142595b406835649bebd33f72c7"
[[package]]
name = "serde"
version = "1.0.136"
@ -1017,7 +627,7 @@ version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [
"itoa",
"itoa 1.0.1",
"ryu",
"serde",
]
@ -1046,6 +656,21 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "sha1"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770"
dependencies = [
"sha1_smol",
]
[[package]]
name = "sha1_smol"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]]
name = "sha2"
version = "0.10.2"
@ -1088,12 +713,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "subtle"
version = "2.4.1"
@ -1111,35 +730,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "tempfile"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if",
"fastrand",
"libc",
"redox_syscall",
"remove_dir_all",
"winapi",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.30"
@ -1187,7 +777,7 @@ dependencies = [
"mio",
"num_cpus",
"once_cell",
"parking_lot 0.12.0",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
@ -1206,27 +796,6 @@ dependencies = [
"syn",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
dependencies = [
"native-tls",
"tokio",
]
[[package]]
name = "tokio-stream"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3"
dependencies = [
"futures-core",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-tungstenite"
version = "0.16.1"
@ -1239,20 +808,6 @@ dependencies = [
"tungstenite",
]
[[package]]
name = "tokio-util"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"log",
"pin-project-lite",
"tokio",
]
[[package]]
name = "tungstenite"
version = "0.16.0"
@ -1317,12 +872,6 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
@ -1351,15 +900,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
@ -1408,9 +948,3 @@ name = "windows_x86_64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
[[package]]
name = "wyz"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"

View file

@ -26,4 +26,4 @@ hmac = "0.12.1"
sha2 = "0.10.2"
hex = "0.4.3"
fred = "4.3.2"
redis = "0.21.5"

View file

@ -9,9 +9,8 @@
(Also found in `example.env`)
| Variable | Description | Example | Required? |
|:--------------------:|:------------------------------------------------------------:|:---------------:|:---------:|
|:--------------------:|:------------------------------------------------------------:|:------------------------:|:---------:|
| `LISTEN_ADDR` | Listen address of the websocket | `0.0.0.0:3621` | |
| `SECRET` | Shared Secret, can be anything, must be the same on Litecord | `deez nuts 420` | [x] |
| `HEARTBEAT_INTERVAL` | Rate of which Litecord will send a heartbeat (in seconds) | `1` | |
| `REDIS_HOST` | Redis database hostname | `127.0.0.1` | |
| `REDIS_PORT` | Redis database port | `6379` | |
| `REDIS_ADDR` | Redis database URL | `redis://127.0.0.1:6379` | |

View file

@ -2,5 +2,4 @@ LISTEN_ADDR=
SECRET=
HEARTBEAT_INTERVAL=
REDIS_HOST=
REDIS_PORT=
REDIS_ADDR=

View file

@ -7,7 +7,7 @@ use tokio_tungstenite::tungstenite::Message;
use crate::opcodes::INFO;
/// Info message types
#[derive(Serialize_repr, Deserialize_repr)]
#[derive(FromPrimitive, Serialize_repr, Deserialize_repr, PartialEq, Debug)]
#[repr(u8)]
pub enum InfoType {
/// Request a channel to be created inside the voice server.
@ -34,6 +34,32 @@ pub enum InfoType {
VST_LEAVE = 6
}
/// Request a channel to be created inside the voice server.
///
/// The Server MUST reply back with a CHANNEL_ASSIGN when resources are
/// allocated for the channel.
#[derive(Deserialize, Serialize, Clone)]
pub struct CHANNEL_REQ {
/// Channel ID
pub channel_id: String,
/// Guild ID, not provided if dm / group dm
pub guild_id: Option<String>
}
/// Sent by the Server to signal the successful creation of a voice channel.
#[derive(Deserialize, Serialize)]
pub struct CHANNEL_ASSIGN {
/// Channel ID
pub channel_id: String,
/// Guild ID, not provided if dm / group dm
pub guild_id: Option<String>,
/// Authentication token
pub token: String
}
/// Info message data
#[derive(Deserialize, Serialize)]
#[serde(untagged)]
@ -42,21 +68,15 @@ pub enum InfoData {
///
/// The Server MUST reply back with a CHANNEL_ASSIGN when resources are
/// allocated for the channel.
CHANNEL_REQ {
/// Channel ID
channel_id: u64,
/// Guild ID, not provided if dm / group dm
guild_id: Option<u64>
},
CHANNEL_REQ(CHANNEL_REQ),
/// Sent by the Server to signal the successful creation of a voice channel.
CHANNEL_ASSIGN {
/// Channel ID
channel_id: u64,
channel_id: String,
/// Guild ID, not provided if dm / group dm
guild_id: Option<u64>,
guild_id: Option<String>,
/// Authentication token
token: String
@ -66,34 +86,34 @@ pub enum InfoData {
/// a channel being deleted, or all members in it leaving.
CHANNEL_DESTROY {
/// Channel ID
channel_id: u64,
channel_id: String,
/// Guild ID, not provided if dm / group dm
guild_id: Option<u64>
guild_id: Option<String>
},
/// Sent by the client to create a voice state.
VST_CREATE {
/// User ID
user_id: u64,
user_id: String,
/// Channel ID
channel_id: u64,
channel_id: String,
/// Guild ID, not provided if dm / group dm
guild_id: Option<u64>
guild_id: Option<String>
},
/// Sent by the server to indicate the success of a VST_CREATE.
VST_DONE {
/// User ID
user_id: u64,
user_id: String,
/// Channel ID
channel_id: u64,
channel_id: String,
/// Guild ID, not provided if dm / group dm
guild_id: Option<u64>,
guild_id: Option<String>,
/// Session ID for the voice state
session_id: String

View file

@ -1,13 +1,13 @@
#[macro_use]
extern crate num_derive;
use std::collections::HashSet;
use std::io::Error;
use dotenv::dotenv;
use std::env;
use std::net::SocketAddr;
use std::time::Duration;
use fred::client::RedisClient;
use tokio::net::{TcpListener, TcpStream};
use futures_util::{future, SinkExt, StreamExt, TryStreamExt};
@ -15,18 +15,20 @@ use tokio_tungstenite::tungstenite::{client, Message};
use crate::OpCode::{HEARTBEAT_ACK, HELLO, READY};
use crate::opcodes::{get_opcode, IDENTIFY, MessageData, OpCode, SocketMessage};
use crate::infoops::get_infotype;
use crate::infoops::{get_infotype, InfoData, InfoType};
use rand::prelude::*;
use rand::distributions::Alphanumeric;
use redis::{Client, Connection, RedisConnectionInfo};
use serde_json::Value::Array;
use crate::util::verify_token;
use redis::Commands;
mod opcodes;
mod infoops;
mod util;
mod redis;
#[tokio::main]
async fn main() -> Result<(), Error> {
@ -35,12 +37,8 @@ async fn main() -> Result<(), Error> {
let shared_secret = env::var("SECRET").expect("No secret present in environment!");
let addr = env::var("LISTEN_ADDR").unwrap_or("0.0.0.0:3621".to_string());
let redis_addr: (String, u16) = (
env::var("REDIS_HOST").unwrap_or("127.0.0.1:6379".to_string()),
env::var("REDIS_PORT").unwrap_or("6379".to_string()).parse::<u16>().expect("Failed to get Redis port!")
);
let redis = redis::connect_redis(redis_addr.0, redis_addr.1).await.expect("Failed to connect to Redis!");
let redis_client = redis::Client::open(env::var("REDIS_HOST").unwrap_or("redis://127.0.0.1:6379".to_string())).expect("Failed to connect to Redis server!");
let socket = TcpListener::bind(&addr).await.expect("Failed to bind to address!");
println!("Listening on {}!", &addr);
@ -49,14 +47,14 @@ async fn main() -> Result<(), Error> {
let peer = stream.peer_addr().expect("Failed to connect to peer, missing address?");
println!("Connecting to peer {}...", &peer);
tokio::spawn(accept_conn(peer, stream, redis.clone(), shared_secret.clone()));
tokio::spawn(accept_conn(peer, stream, redis_client.clone(), shared_secret.clone()));
}
Ok(())
}
async fn accept_conn(peer: SocketAddr, stream: TcpStream, redis: RedisClient, shared_secret: String) {
if let Err(e) = handle_conn(peer, stream, redis, shared_secret).await {
async fn accept_conn(peer: SocketAddr, stream: TcpStream, redis_client: Client, shared_secret: String) {
if let Err(e) = handle_conn(peer, stream, redis_client, shared_secret).await {
match e {
tokio_tungstenite::tungstenite::Error::ConnectionClosed | tokio_tungstenite::tungstenite::Error::Protocol(_) | tokio_tungstenite::tungstenite::Error::Utf8 => (),
err => eprintln!("Error accepting connection from {}!", &peer),
@ -64,7 +62,7 @@ async fn accept_conn(peer: SocketAddr, stream: TcpStream, redis: RedisClient, sh
}
}
async fn handle_conn(peer: SocketAddr, stream: TcpStream, redis: RedisClient, shared_secret: String) -> tokio_tungstenite::tungstenite::Result<()> {
async fn handle_conn(peer: SocketAddr, stream: TcpStream, redis_client: Client, shared_secret: String) -> tokio_tungstenite::tungstenite::Result<()> {
let ws_stream = tokio_tungstenite::accept_async(stream)
.await
.expect("Failed to complete the websocket handshake!");
@ -73,14 +71,15 @@ async fn handle_conn(peer: SocketAddr, stream: TcpStream, redis: RedisClient, sh
let (mut ws_sender, mut ws_receiver) = ws_stream.split();
let mut heartbeat = tokio::time::interval(Duration::from_millis(1000));
let mut redis = redis_client.get_connection().expect("Failed to get Redis connection!");
let mut nonce: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(10)
.map(char::from)
.collect();
let _: () = redis.set(format!("{}_nonce", peer), &nonce, None, None, false)
.await.expect("Failed to insert nonce!");
let _: () = redis.set(format!("{}_nonce", peer), &nonce).expect("Failed to insert nonce!");
println!("HELLO to {}", &peer);
ws_sender.send(Message::Text(
@ -124,7 +123,7 @@ async fn handle_conn(peer: SocketAddr, stream: TcpStream, redis: RedisClient, sh
if let MessageData::IDENTIFY(dn) = op.1 {
println!("IDENTIFY from {}", &peer);
let nonce: Option<String> = redis.get(format!("{}_nonce", peer)).await.expect("Failed to get nonce from Redis!");
let nonce: Option<String> = redis.get(format!("{}_nonce", peer)).expect("Failed to get nonce from Redis!");
if verify_token(shared_secret.clone(), nonce, dn.token).await {
println!("READY to {}", &peer);
@ -161,7 +160,7 @@ async fn handle_conn(peer: SocketAddr, stream: TcpStream, redis: RedisClient, sh
&SocketMessage {
op: HEARTBEAT_ACK,
d: MessageData::HEARTBEAT_ACK {
health: 1.0 // trust
health: 6.9 // trust
}
}
).unwrap().to_owned()
@ -172,7 +171,61 @@ async fn handle_conn(peer: SocketAddr, stream: TcpStream, redis: RedisClient, sh
let info_data = get_infotype(msg.clone());
if info_data.is_ok() {
println!("INFO from {} with type {}", &peer, info_data.unwrap().0 as u8);
let info = info_data.unwrap();
println!("INFO from {} with type {:?}", &peer, &info.0);
match info.0 {
InfoType::CHANNEL_REQ => {
if let InfoData::CHANNEL_REQ(dn) = info.1 {
let guild_id = dn.clone().guild_id.unwrap_or("dm".to_string());
println!("Creating voice channel for {} in {}", &dn.channel_id, &guild_id);
let token: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(64)
.map(char::from)
.collect();
let mut channel_set: HashSet<String> = HashSet::new();
if channel_set.insert(format!("token_{}", token)) {
let _: () = redis.sadd(format!("{}_{}_voice", guild_id, &dn.channel_id), channel_set)
.expect("Failed to insert into Redis!");
println!("CHANNEL_ASSIGN to {}", &peer);
ws_sender.send(Message::Text(
serde_json::to_string(
&SocketMessage {
op: OpCode::INFO,
d: MessageData::INFO {
_type: InfoType::CHANNEL_ASSIGN,
data: InfoData::CHANNEL_ASSIGN {
channel_id: dn.channel_id,
guild_id: dn.guild_id,
token
}
}
}
).unwrap().to_owned()
)).await?;
} else {
// cry about it
ws_sender.send(Message::Text((opcodes::ErrorCode::GENERAL as i32).to_string())).await?;
}
} else {
ws_sender.send(Message::Text((opcodes::ErrorCode::DECODE as i32).to_string())).await?;
}
},
InfoType::CHANNEL_DESTROY => todo!(),
InfoType::VST_CREATE => todo!(),
InfoType::VST_UPDATE => todo!(),
InfoType::VST_LEAVE => todo!(),
_ => {
ws_sender.send(Message::Text((opcodes::ErrorCode::DECODE as i32).to_string())).await?;
}
}
} else {
ws_sender.send(Message::Text((opcodes::ErrorCode::DECODE as i32).to_string())).await?;
}

View file

@ -122,7 +122,14 @@ pub enum MessageData {
///
/// The INFO message is extensible in which many request / response scenarios
/// are laid on.
INFO(INFO)
INFO {
/// Info type
#[serde(rename = "type")]
_type: InfoType,
/// Info data, varies depending on InfoType
data: InfoData
}
}
/// Message data is defined by each opcode.

View file

@ -1,23 +0,0 @@
use fred::prelude::*;
pub async fn connect_redis(host: String, port: u16) -> Result<RedisClient, RedisError> {
let client = RedisClient::new(RedisConfig {
fail_fast: false,
pipeline: false,
blocking: Default::default(),
username: None,
password: None,
server: ServerConfig::new_centralized(host, port),
tls: None
});
client.connect(Some(ReconnectPolicy::default()));
client.wait_for_connect().await?;
client.flushall(false).await?;
if client.is_connected() {
Ok(client)
} else {
Err(RedisError::from(()))
}
}