fixed mishandle of ping-pong packets leaded to longer delays in response time

This commit is contained in:
Nickiel12 2024-07-02 20:19:00 -07:00
parent 8a997a3d4c
commit 58546e8432
10 changed files with 625 additions and 64 deletions

524
Cargo.lock generated
View file

@ -17,6 +17,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "android-tzdata" name = "android-tzdata"
version = "0.1.1" version = "0.1.1"
@ -51,6 +60,39 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "async-recursion"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.53",
]
[[package]]
name = "async-stream"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51"
dependencies = [
"async-stream-impl",
"futures-core",
"pin-project-lite",
]
[[package]]
name = "async-stream-impl"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.53",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.78" version = "0.1.78"
@ -74,6 +116,51 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axum"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
dependencies = [
"async-trait",
"axum-core",
"bitflags 1.3.2",
"bytes 1.6.0",
"futures-util",
"http 0.2.12",
"http-body",
"hyper",
"itoa",
"matchit",
"memchr",
"mime",
"percent-encoding",
"pin-project-lite",
"rustversion",
"serde",
"sync_wrapper",
"tower",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-core"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
dependencies = [
"async-trait",
"bytes 1.6.0",
"futures-util",
"http 0.2.12",
"http-body",
"mime",
"rustversion",
"tower-layer",
"tower-service",
]
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.71" version = "0.3.71"
@ -240,6 +327,44 @@ dependencies = [
"yaml-rust", "yaml-rust",
] ]
[[package]]
name = "console-api"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a257c22cd7e487dd4a13d413beabc512c5052f0bc048db0da6a84c3d8a6142fd"
dependencies = [
"futures-core",
"prost",
"prost-types",
"tonic",
"tracing-core",
]
[[package]]
name = "console-subscriber"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31c4cc54bae66f7d9188996404abdf7fdfa23034ef8e43478c8810828abad758"
dependencies = [
"console-api",
"crossbeam-channel",
"crossbeam-utils",
"futures-task",
"hdrhistogram",
"humantime",
"prost",
"prost-types",
"serde",
"serde_json",
"thread_local",
"tokio",
"tokio-stream",
"tonic",
"tracing",
"tracing-core",
"tracing-subscriber",
]
[[package]] [[package]]
name = "const-random" name = "const-random"
version = "0.1.18" version = "0.1.18"
@ -294,6 +419,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.13" version = "0.5.13"
@ -402,6 +536,16 @@ dependencies = [
"rustc_version", "rustc_version",
] ]
[[package]]
name = "flate2"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -1013,6 +1157,31 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "h2"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
dependencies = [
"bytes 1.6.0",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http 0.2.12",
"indexmap 2.2.5",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.13.2" version = "0.13.2"
@ -1025,6 +1194,19 @@ version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "hdrhistogram"
version = "7.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d"
dependencies = [
"base64",
"byteorder",
"flate2",
"nom",
"num-traits",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.1" version = "0.4.1"
@ -1037,6 +1219,17 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "http"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"
dependencies = [
"bytes 1.6.0",
"fnv",
"itoa",
]
[[package]] [[package]]
name = "http" name = "http"
version = "1.1.0" version = "1.1.0"
@ -1048,12 +1241,71 @@ dependencies = [
"itoa", "itoa",
] ]
[[package]]
name = "http-body"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
dependencies = [
"bytes 1.6.0",
"http 0.2.12",
"pin-project-lite",
]
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.8.0" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
[[package]]
name = "httpdate"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hyper"
version = "0.14.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33"
dependencies = [
"bytes 1.6.0",
"futures-channel",
"futures-core",
"futures-util",
"h2",
"http 0.2.12",
"http-body",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"socket2",
"tokio",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper-timeout"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1"
dependencies = [
"hyper",
"pin-project-lite",
"tokio",
"tokio-io-timeout",
]
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.60" version = "0.1.60"
@ -1087,6 +1339,16 @@ dependencies = [
"unicode-normalization", "unicode-normalization",
] ]
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.2.5" version = "2.2.5"
@ -1156,7 +1418,9 @@ name = "joystick-controller-client"
version = "2.0.0" version = "2.0.0"
dependencies = [ dependencies = [
"async-channel", "async-channel",
"async-recursion",
"config", "config",
"console-subscriber",
"futures-core", "futures-core",
"futures-util", "futures-util",
"gilrs", "gilrs",
@ -1238,6 +1502,21 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "matchit"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.1" version = "2.7.1"
@ -1253,6 +1532,12 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -1495,6 +1780,26 @@ dependencies = [
"sha2", "sha2",
] ]
[[package]]
name = "pin-project"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.53",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.13" version = "0.2.13"
@ -1567,6 +1872,38 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "prost"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29"
dependencies = [
"bytes 1.6.0",
"prost-derive",
]
[[package]]
name = "prost-derive"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1"
dependencies = [
"anyhow",
"itertools",
"proc-macro2",
"quote",
"syn 2.0.53",
]
[[package]]
name = "prost-types"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0"
dependencies = [
"prost",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.35" version = "1.0.35"
@ -1606,6 +1943,50 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "regex"
version = "1.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.7",
"regex-syntax 0.8.4",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax 0.8.4",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]] [[package]]
name = "ron" name = "ron"
version = "0.8.1" version = "0.8.1"
@ -1643,6 +2024,12 @@ dependencies = [
"semver", "semver",
] ]
[[package]]
name = "rustversion"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.17" version = "1.0.17"
@ -1794,6 +2181,12 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]] [[package]]
name = "system-deps" name = "system-deps"
version = "6.2.1" version = "6.2.1"
@ -1911,6 +2304,8 @@ dependencies = [
"num_cpus", "num_cpus",
"pin-project-lite", "pin-project-lite",
"socket2", "socket2",
"tokio-macros",
"tracing",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -1925,6 +2320,38 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "tokio-io-timeout"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf"
dependencies = [
"pin-project-lite",
"tokio",
]
[[package]]
name = "tokio-macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.53",
]
[[package]]
name = "tokio-stream"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af"
dependencies = [
"futures-core",
"pin-project-lite",
"tokio",
]
[[package]] [[package]]
name = "tokio-tungstenite" name = "tokio-tungstenite"
version = "0.21.0" version = "0.21.0"
@ -1937,6 +2364,19 @@ dependencies = [
"tungstenite", "tungstenite",
] ]
[[package]]
name = "tokio-util"
version = "0.7.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1"
dependencies = [
"bytes 1.6.0",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.12" version = "0.8.12"
@ -1964,7 +2404,7 @@ version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [ dependencies = [
"indexmap", "indexmap 2.2.5",
"toml_datetime", "toml_datetime",
"winnow 0.5.40", "winnow 0.5.40",
] ]
@ -1975,13 +2415,72 @@ version = "0.22.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4"
dependencies = [ dependencies = [
"indexmap", "indexmap 2.2.5",
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"winnow 0.6.5", "winnow 0.6.5",
] ]
[[package]]
name = "tonic"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13"
dependencies = [
"async-stream",
"async-trait",
"axum",
"base64",
"bytes 1.6.0",
"h2",
"http 0.2.12",
"http-body",
"hyper",
"hyper-timeout",
"percent-encoding",
"pin-project",
"prost",
"tokio",
"tokio-stream",
"tower",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "tower"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
dependencies = [
"futures-core",
"futures-util",
"indexmap 1.9.3",
"pin-project",
"pin-project-lite",
"rand",
"slab",
"tokio",
"tokio-util",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "tower-layer"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0"
[[package]]
name = "tower-service"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.40" version = "0.1.40"
@ -2043,14 +2542,24 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [ dependencies = [
"matchers",
"nu-ansi-term", "nu-ansi-term",
"once_cell",
"regex",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
"tracing",
"tracing-core", "tracing-core",
"tracing-log", "tracing-log",
] ]
[[package]]
name = "try-lock"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]] [[package]]
name = "tungstenite" name = "tungstenite"
version = "0.21.0" version = "0.21.0"
@ -2060,7 +2569,7 @@ dependencies = [
"byteorder", "byteorder",
"bytes 1.6.0", "bytes 1.6.0",
"data-encoding", "data-encoding",
"http", "http 1.1.0",
"httparse", "httparse",
"log", "log",
"rand", "rand",
@ -2156,6 +2665,15 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "want"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
dependencies = [
"try-lock",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"

View file

@ -27,3 +27,5 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["tracing-log"] } tracing-subscriber = { version = "0.3.18", features = ["tracing-log"] }
tracing-appender = "0.2.3" tracing-appender = "0.2.3"
snafu = "0.8.2" snafu = "0.8.2"
console-subscriber = "0.3.0"
async-recursion = "1.1.1"

View file

@ -193,7 +193,7 @@ pub async fn start_coordinator(
y_adj = y; y_adj = y;
} }
Err(e) => { Err(e) => {
error!("Could not calculate the tracking!: {e}"); info!("Could not calculate the tracking!: {e}");
} }
} }

View file

@ -1,7 +1,7 @@
use std::{collections::VecDeque, time::Duration}; use std::{collections::VecDeque, time::Duration};
use async_channel::Sender; use async_channel::Sender;
use tracing::error; use tracing::{error, info};
use crate::ui::GuiUpdate; use crate::ui::GuiUpdate;

View file

@ -1,13 +1,15 @@
use std::{ use std::{
sync::{atomic::Ordering, Arc, Mutex}, sync::{atomic::Ordering, Arc},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use async_recursion::async_recursion;
use async_channel::Sender; use async_channel::Sender;
use futures_util::{SinkExt, StreamExt, TryStreamExt}; use futures_util::{stream::SplitStream, SinkExt, StreamExt, TryStreamExt};
use gstreamer_app::AppSink; use gstreamer_app::AppSink;
use tokio::time::sleep_until; use tokio::{net::TcpStream, sync::Mutex, time::sleep_until};
use tokio_tungstenite::{connect_async, tungstenite::Message}; use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream};
use tracing::{error, info, instrument, warn}; use tracing::{error, info, instrument, warn};
use super::{ use super::{
@ -48,13 +50,7 @@ pub async fn remote_video_loop(
last_iter = Instant::now(); last_iter = Instant::now();
// Do this in an encloser to not keep a lock on the appsink // Do this in an encloser to not keep a lock on the appsink
let image_message = match { let image_message = match {
let appsnk = match appsink.lock() { let appsnk = appsink.lock().await;
Ok(e) => e,
Err(e) => {
error!("Unrecoverable error: Could not get a lock on the appsink in remote video loop {e}");
return;
}
};
get_video_frame(&appsnk) get_video_frame(&appsnk)
} { } {
@ -79,37 +75,10 @@ pub async fn remote_video_loop(
break; break;
} }
match recvr.try_next().await { let do_not_break = handle_message(&mut recvr, &to_mec, last_iter).await;
Ok(Some(message)) => {
match process_incoming_string(message.to_string()) { if !do_not_break { break; }
Ok(v) => {
if let Err(e) = to_mec
.send(ApplicationEvent::TrackerUpdate(TrackerUpdate::Update(
TrackerUpdatePackage {
boxes: v,
time: Instant::now(),
request_duration: Instant::now() - last_iter,
},
)))
.await
{
error!("Could not send to MEC! {e}");
break;
}
}
Err(e) => {
error!("Could not parse incoming string! {e}");
}
};
}
Ok(None) => {
info!("Recieved an empty message from the remote computer: Aborting");
break;
}
Err(e) => {
error!("Got an error on while recieving from remote computer: {e}");
}
}
if !socket_state.stay_connected.load(Ordering::SeqCst) { if !socket_state.stay_connected.load(Ordering::SeqCst) {
info!("Shutting down remote video loop"); info!("Shutting down remote video loop");
@ -117,7 +86,6 @@ pub async fn remote_video_loop(
} }
// rate limit updates // rate limit updates
// prevent starving the GUI thread's lock on the tracker state
sleep_until(tokio::time::Instant::now() + Duration::from_millis(10)).await; sleep_until(tokio::time::Instant::now() + Duration::from_millis(10)).await;
} }
} }
@ -159,3 +127,69 @@ fn get_video_frame(appsink: &AppSink) -> Result<Message, String> {
.map_err(|e| format!("Could not get readable map: {e}"))?; .map_err(|e| format!("Could not get readable map: {e}"))?;
Ok(Message::binary(map.to_vec())) Ok(Message::binary(map.to_vec()))
} }
#[async_recursion]
async fn handle_message(
recvr: &mut SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
to_mec: &Sender<ApplicationEvent>,
last_iter: Instant,
) -> bool {
match recvr.try_next().await {
Ok(Some(message)) => {
match message {
Message::Close(_) => {
info!("Close packet received from remote computer: {:?}", message);
return false;
}
Message::Pong(_) | Message::Frame(_) | Message::Text(_) => {
warn!("There was an unhandled message type from the camera: {}\n{}", message, message.to_string());
// this was not the expected response, recursion!
return handle_message(recvr, to_mec, last_iter).await;
}
Message::Ping(content) => {
if let Err(e) = to_mec.send(ApplicationEvent::SocketMessage(Message::Pong(content))).await {
error!("Video processor could not send message to MEC, exiting: {e}");
return false;
}
// this was not the expected response, recursion!
return handle_message(recvr, to_mec, last_iter).await;
}
Message::Binary(bin) => {
let message = std::str::from_utf8(&bin);
if let Err(e) = message {
error!("Could not decode binary message! Assuming corrupted response! {e}");
}
match process_incoming_string(message.unwrap().to_string()) {
Ok(v) => {
if let Err(e) = to_mec
.send(ApplicationEvent::TrackerUpdate(TrackerUpdate::Update(
TrackerUpdatePackage {
boxes: v,
time: Instant::now(),
request_duration: Instant::now() - last_iter,
},
)))
.await
{
error!("Could not send to MEC! {e}");
return false;
}
}
Err(e) => {
error!("Could not parse incoming string! {}\n{}", e, message.unwrap());
}
};
}
}
}
Ok(None) => {
info!("Recieved an empty message from the remote computer: Aborting");
return false;
}
Err(e) => {
error!("Got an error on while recieving from remote computer: {e}");
}
}
return true;
}

View file

@ -38,6 +38,8 @@ impl TrackerState {
self.identity_boxes = new_boxes; self.identity_boxes = new_boxes;
} }
// TODO: have a return type that says "highlighted ID not found" and "no highlighted id selected"
// It's not really worth logging...
pub fn calculate_tracking(&mut self) -> core::result::Result<(i32, i32, bool), String> { pub fn calculate_tracking(&mut self) -> core::result::Result<(i32, i32, bool), String> {
if let Some(target_box) = self if let Some(target_box) = self
.identity_boxes .identity_boxes

View file

@ -4,7 +4,8 @@ use gstreamer_app::AppSink;
use gtk::glib::BoolError; use gtk::glib::BoolError;
use snafu::prelude::*; use snafu::prelude::*;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use tokio::sync::Mutex;
#[derive(Debug)] #[derive(Debug)]
pub struct WebcamPipeline { pub struct WebcamPipeline {
@ -88,7 +89,7 @@ impl WebcamPipeline {
let sink_frame = AppSink::builder() let sink_frame = AppSink::builder()
.name("frame_appsink") .name("frame_appsink")
.sync(false) .sync(false)
.max_buffers(3u32) .max_buffers(1u32)
.drop(true) .drop(true)
.caps(&appsrc_caps) .caps(&appsrc_caps)
.build(); .build();

View file

@ -3,6 +3,8 @@ use gtk::{glib, Application};
use std::{env, sync::Arc}; use std::{env, sync::Arc};
use tokio::{runtime, sync::RwLock}; use tokio::{runtime, sync::RwLock};
use tracing::{self, info, Level}; use tracing::{self, info, Level};
#[cfg(not(debug_assertions))]
use tracing_subscriber; use tracing_subscriber;
use crate::config::{load_config, AppConfig}; use crate::config::{load_config, AppConfig};
@ -19,14 +21,20 @@ fn main() -> glib::ExitCode {
// set the environment var to make gtk use window's default action bar // set the environment var to make gtk use window's default action bar
env::set_var("gtk_csd", "0"); env::set_var("gtk_csd", "0");
// #[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
let file_appender = tracing_appender::rolling::daily(".\\logs", "camera-controller"); {
let (non_blocking, _gaurd) = tracing_appender::non_blocking(file_appender); let file_appender = tracing_appender::rolling::daily(".\\logs", "camera-controller");
tracing_subscriber::fmt() let (non_blocking, _gaurd) = tracing_appender::non_blocking(file_appender);
.with_writer(non_blocking) tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG) .with_writer(non_blocking)
.with_ansi(false) .with_max_level(tracing::Level::DEBUG)
.init(); .with_ansi(false)
.init();
}
#[cfg(debug_assertions)]
{
console_subscriber::init();
}
let span = tracing::span!(Level::TRACE, "main"); let span = tracing::span!(Level::TRACE, "main");
let _enter = span.enter(); let _enter = span.enter();

View file

@ -1,6 +1,6 @@
use std::{ use std::{
net::SocketAddr, net::SocketAddr,
sync::{atomic::Ordering, Arc, Mutex}, sync::{atomic::Ordering, Arc},
}; };
use async_channel::Sender; use async_channel::Sender;

View file

@ -3,7 +3,7 @@ use std::sync::Arc;
use gtk::glib::{self, clone}; use gtk::glib::{self, clone};
use gtk::{ use gtk::{
prelude::{BoxExt, ButtonExt, EditableExt, GtkWindowExt}, prelude::{BoxExt, ButtonExt, EditableExt, GtkWindowExt},
Application, ApplicationWindow, Box, Button, Entry, Label, Window, Application, ApplicationWindow, Button, Entry, Label, Window,
}; };
use log::{error, info}; use log::{error, info};
use tokio::runtime::Handle; use tokio::runtime::Handle;
@ -13,8 +13,6 @@ use crate::config::{save_config, AppConfig};
pub struct ConnectionsModal { pub struct ConnectionsModal {
pub window: Window, pub window: Window,
pub top_level: Box,
} }
impl ConnectionsModal { impl ConnectionsModal {
@ -158,8 +156,6 @@ impl ConnectionsModal {
ConnectionsModal { ConnectionsModal {
window, window,
top_level: main_box,
} }
} }
} }