This commit is contained in:
nora 2022-02-20 14:10:19 +01:00
parent 2e0a31f4af
commit ed4a107c44
13 changed files with 1448 additions and 1860 deletions

124
Cargo.lock generated
View file

@ -2,21 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.18" version = "0.7.18"
@ -55,7 +40,6 @@ dependencies = [
"axum", "axum",
"serde", "serde",
"tokio", "tokio",
"tower-http",
"tracing", "tracing",
] ]
@ -89,9 +73,6 @@ name = "anyhow"
version = "1.0.53" version = "1.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0"
dependencies = [
"backtrace",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
@ -104,12 +85,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.4.5" version = "0.4.5"
@ -155,21 +130,6 @@ dependencies = [
"mime", "mime",
] ]
[[package]]
name = "backtrace"
version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "1.3.2"
@ -182,12 +142,6 @@ 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 = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "cc"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -266,12 +220,6 @@ dependencies = [
"wasi", "wasi",
] ]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.0" version = "0.4.0"
@ -401,15 +349,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata",
]
[[package]] [[package]]
name = "matches" name = "matches"
version = "0.1.9" version = "0.1.9"
@ -434,32 +373,12 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
dependencies = [
"adler",
"autocfg",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.8.0" version = "0.8.0"
@ -512,15 +431,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "object"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.9.0" version = "1.9.0"
@ -672,27 +582,12 @@ dependencies = [
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax",
]
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.25" version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.9" version = "1.0.9"
@ -941,13 +836,7 @@ dependencies = [
"http", "http",
"http-body", "http-body",
"http-range-header", "http-range-header",
"httpdate",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite", "pin-project-lite",
"tokio",
"tokio-util 0.7.0",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
] ]
@ -1016,13 +905,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa" checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"lazy_static",
"matchers",
"regex",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
"tracing",
"tracing-core", "tracing-core",
"tracing-log", "tracing-log",
] ]
@ -1033,15 +918,6 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.2.2" version = "0.2.2"

View file

@ -15,4 +15,4 @@ amqp_dashboard = { path = "./amqp_dashboard" }
amqp_transport = { path = "./amqp_transport" } amqp_transport = { path = "./amqp_transport" }
tokio = { version = "1.16.1", features = ["full"] } tokio = { version = "1.16.1", features = ["full"] }
tracing = "0.1.30" tracing = "0.1.30"
tracing-subscriber = { version = "0.3.8", features = ["env-filter"] } tracing-subscriber = "0.3.8"

View file

@ -1,3 +1,5 @@
#![warn(rust_2018_idioms)]
use parking_lot::Mutex; use parking_lot::Mutex;
use std::collections::HashMap; use std::collections::HashMap;
use std::net::SocketAddr; use std::net::SocketAddr;

View file

@ -10,5 +10,4 @@ amqp_core = { path = "../amqp_core" }
axum = "0.4.5" axum = "0.4.5"
serde = { version = "1.0.136", features = ["derive"] } serde = { version = "1.0.136", features = ["derive"] }
tokio = { version = "1.17.0", features = ["full"] } tokio = { version = "1.17.0", features = ["full"] }
tower-http = { version = "0.2.3", features = ["fs"] }
tracing = "0.1.31" tracing = "0.1.31"

View file

@ -1,3 +1,5 @@
#![warn(rust_2018_idioms)]
use amqp_core::GlobalData; use amqp_core::GlobalData;
use axum::body::{boxed, Full}; use axum::body::{boxed, Full};
use axum::response::{Html, IntoResponse, Response}; use axum::response::{Html, IntoResponse, Response};

View file

@ -7,7 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
amqp_core = { path = "../amqp_core" } amqp_core = { path = "../amqp_core" }
anyhow = { version = "1.0.53", features = ["backtrace"] } anyhow = "1.0.53"
nom = "7.1.0" nom = "7.1.0"
once_cell = "1.9.0" once_cell = "1.9.0"
rand = "0.8.4" rand = "0.8.4"

File diff suppressed because it is too large Load diff

View file

@ -77,23 +77,23 @@ macro_rules! fail {
use crate::classes::{FieldValue, TableFieldName}; use crate::classes::{FieldValue, TableFieldName};
pub use fail; pub use fail;
pub fn octet(input: &[u8]) -> IResult<Octet> { pub fn octet(input: &[u8]) -> IResult<'_, Octet> {
u8(input) u8(input)
} }
pub fn short(input: &[u8]) -> IResult<Short> { pub fn short(input: &[u8]) -> IResult<'_, Short> {
u16(Big)(input) u16(Big)(input)
} }
pub fn long(input: &[u8]) -> IResult<Long> { pub fn long(input: &[u8]) -> IResult<'_, Long> {
u32(Big)(input) u32(Big)(input)
} }
pub fn longlong(input: &[u8]) -> IResult<Longlong> { pub fn longlong(input: &[u8]) -> IResult<'_, Longlong> {
u64(Big)(input) u64(Big)(input)
} }
pub fn bit(input: &[u8], amount: usize) -> IResult<Vec<Bit>> { pub fn bit(input: &[u8], amount: usize) -> IResult<'_, Vec<Bit>> {
let octets = (amount + 7) / 8; let octets = (amount + 7) / 8;
let (input, bytes) = take(octets)(input)?; let (input, bytes) = take(octets)(input)?;
@ -119,25 +119,25 @@ pub fn bit(input: &[u8], amount: usize) -> IResult<Vec<Bit>> {
Ok((input, vec)) Ok((input, vec))
} }
pub fn shortstr(input: &[u8]) -> IResult<Shortstr> { pub fn shortstr(input: &[u8]) -> IResult<'_, Shortstr> {
let (input, len) = u8(input)?; let (input, len) = u8(input)?;
let (input, str_data) = take(usize::from(len))(input)?; let (input, str_data) = take(usize::from(len))(input)?;
let data = String::from_utf8(str_data.into()).map_err(err_other("shortstr"))?; let data = String::from_utf8(str_data.into()).map_err(err_other("shortstr"))?;
Ok((input, data)) Ok((input, data))
} }
pub fn longstr(input: &[u8]) -> IResult<Longstr> { pub fn longstr(input: &[u8]) -> IResult<'_, Longstr> {
let (input, len) = u32(Big)(input)?; let (input, len) = u32(Big)(input)?;
let (input, str_data) = take(usize::try_from(len).unwrap())(input)?; let (input, str_data) = take(usize::try_from(len).unwrap())(input)?;
let data = str_data.into(); let data = str_data.into();
Ok((input, data)) Ok((input, data))
} }
pub fn timestamp(input: &[u8]) -> IResult<Timestamp> { pub fn timestamp(input: &[u8]) -> IResult<'_, Timestamp> {
u64(Big)(input) u64(Big)(input)
} }
pub fn table(input: &[u8]) -> IResult<Table> { pub fn table(input: &[u8]) -> IResult<'_, Table> {
let (input, size) = u32(Big)(input)?; let (input, size) = u32(Big)(input)?;
let (table_input, rest_input) = input.split_at(size.try_into().unwrap()); let (table_input, rest_input) = input.split_at(size.try_into().unwrap());
@ -154,16 +154,16 @@ pub fn table(input: &[u8]) -> IResult<Table> {
Ok((rest_input, table)) Ok((rest_input, table))
} }
fn table_value_pair(input: &[u8]) -> IResult<(TableFieldName, FieldValue)> { fn table_value_pair(input: &[u8]) -> IResult<'_, (TableFieldName, FieldValue)> {
let (input, field_name) = shortstr(input)?; let (input, field_name) = shortstr(input)?;
let (input, field_value) = field_value(input).map_err(err(format!("field {field_name}")))?; let (input, field_value) = field_value(input).map_err(err(format!("field {field_name}")))?;
Ok((input, (field_name, field_value))) Ok((input, (field_name, field_value)))
} }
fn field_value(input: &[u8]) -> IResult<FieldValue> { fn field_value(input: &[u8]) -> IResult<'_, FieldValue> {
type R<'a> = IResult<'a, FieldValue>; type R<'a> = IResult<'a, FieldValue>;
fn boolean(input: &[u8]) -> R { fn boolean(input: &[u8]) -> R<'_> {
let (input, _) = tag(b"t")(input)?; let (input, _) = tag(b"t")(input)?;
let (input, bool_byte) = u8(input)?; let (input, bool_byte) = u8(input)?;
match bool_byte { match bool_byte {
@ -182,37 +182,37 @@ fn field_value(input: &[u8]) -> IResult<FieldValue> {
}; };
} }
number!(b"b", short_short_int, i8, ShortShortInt, R); number!(b"b", short_short_int, i8, ShortShortInt, R<'_>);
number!(b"B", short_short_uint, u8, ShortShortUInt, R); number!(b"B", short_short_uint, u8, ShortShortUInt, R<'_>);
number!(b"U", short_int, i16(Big), ShortInt, R); number!(b"U", short_int, i16(Big), ShortInt, R<'_>);
number!(b"u", short_uint, u16(Big), ShortUInt, R); number!(b"u", short_uint, u16(Big), ShortUInt, R<'_>);
number!(b"I", long_int, i32(Big), LongInt, R); number!(b"I", long_int, i32(Big), LongInt, R<'_>);
number!(b"i", long_uint, u32(Big), LongUInt, R); number!(b"i", long_uint, u32(Big), LongUInt, R<'_>);
number!(b"L", long_long_int, i64(Big), LongLongInt, R); number!(b"L", long_long_int, i64(Big), LongLongInt, R<'_>);
number!(b"l", long_long_uint, u64(Big), LongLongUInt, R); number!(b"l", long_long_uint, u64(Big), LongLongUInt, R<'_>);
number!(b"f", float, f32(Big), Float, R); number!(b"f", float, f32(Big), Float, R<'_>);
number!(b"d", double, f64(Big), Double, R); number!(b"d", double, f64(Big), Double, R<'_>);
fn decimal(input: &[u8]) -> R { fn decimal(input: &[u8]) -> R<'_> {
let (input, _) = tag("D")(input)?; let (input, _) = tag("D")(input)?;
let (input, scale) = u8(input)?; let (input, scale) = u8(input)?;
let (input, value) = u32(Big)(input)?; let (input, value) = u32(Big)(input)?;
Ok((input, FieldValue::DecimalValue(scale, value))) Ok((input, FieldValue::DecimalValue(scale, value)))
} }
fn short_str(input: &[u8]) -> R { fn short_str(input: &[u8]) -> R<'_> {
let (input, _) = tag("s")(input)?; let (input, _) = tag("s")(input)?;
let (input, str) = shortstr(input)?; let (input, str) = shortstr(input)?;
Ok((input, FieldValue::ShortString(str))) Ok((input, FieldValue::ShortString(str)))
} }
fn long_str(input: &[u8]) -> R { fn long_str(input: &[u8]) -> R<'_> {
let (input, _) = tag("S")(input)?; let (input, _) = tag("S")(input)?;
let (input, str) = longstr(input)?; let (input, str) = longstr(input)?;
Ok((input, FieldValue::LongString(str))) Ok((input, FieldValue::LongString(str)))
} }
fn field_array(input: &[u8]) -> R { fn field_array(input: &[u8]) -> R<'_> {
let (input, _) = tag("A")(input)?; let (input, _) = tag("A")(input)?;
// todo is it i32? // todo is it i32?
let (input, len) = u32(Big)(input)?; let (input, len) = u32(Big)(input)?;
@ -220,14 +220,14 @@ fn field_value(input: &[u8]) -> IResult<FieldValue> {
.map(|(input, value)| (input, FieldValue::FieldArray(value))) .map(|(input, value)| (input, FieldValue::FieldArray(value)))
} }
number!(b"T", timestamp, u64(Big), Timestamp, R); number!(b"T", timestamp, u64(Big), Timestamp, R<'_>);
fn field_table(input: &[u8]) -> R { fn field_table(input: &[u8]) -> R<'_> {
let (input, _) = tag("F")(input)?; let (input, _) = tag("F")(input)?;
table(input).map(|(input, value)| (input, FieldValue::FieldTable(value))) table(input).map(|(input, value)| (input, FieldValue::FieldTable(value)))
} }
fn void(input: &[u8]) -> R { fn void(input: &[u8]) -> R<'_> {
tag("V")(input).map(|(input, _)| (input, FieldValue::Void)) tag("V")(input).map(|(input, _)| (input, FieldValue::Void))
} }

View file

@ -27,6 +27,7 @@ const CHANNEL_MAX: u16 = 0;
const FRAME_SIZE_MAX: u32 = 0; const FRAME_SIZE_MAX: u32 = 0;
const HEARTBEAT_DELAY: u16 = 0; const HEARTBEAT_DELAY: u16 = 0;
#[allow(dead_code)]
pub struct Channel { pub struct Channel {
num: u16, num: u16,
channel_handle: amqp_core::ChannelHandle, channel_handle: amqp_core::ChannelHandle,

View file

@ -1,4 +1,4 @@
extern crate core; #![warn(rust_2018_idioms)]
mod classes; mod classes;
mod connection; mod connection;

View file

@ -1,20 +1,25 @@
#![warn(rust_2018_idioms)]
use anyhow::Result; use anyhow::Result;
use std::env; use std::env;
use tracing::Level;
use tracing::{info_span, Instrument}; use tracing::{info_span, Instrument};
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let mut dashboard = false; let mut dashboard = false;
let mut level = Level::INFO;
for arg in env::args().skip(1) { for arg in env::args().skip(1) {
match arg.as_str() { match arg.as_str() {
"--trace" => level = Level::TRACE,
"--dashboard" => dashboard = true, "--dashboard" => dashboard = true,
"ignore-this-clippy" => eprintln!("yes please"), "ignore-this-clippy" => eprintln!("yes please"),
_ => {} _ => {}
} }
} }
setup_tracing(); setup_tracing(level);
let global_data = amqp_core::GlobalData::default(); let global_data = amqp_core::GlobalData::default();
@ -26,12 +31,12 @@ async fn main() -> Result<()> {
amqp_transport::do_thing_i_guess(global_data).await amqp_transport::do_thing_i_guess(global_data).await
} }
fn setup_tracing() { fn setup_tracing(level: Level) {
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_level(true) .with_level(true)
.with_timer(tracing_subscriber::fmt::time::time()) .with_timer(tracing_subscriber::fmt::time::time())
.with_ansi(true) .with_ansi(true)
.with_thread_names(true) .with_thread_names(true)
.with_env_filter("hyper=info,debug") .with_max_level(level)
.init() .init()
} }

View file

@ -1,3 +1,5 @@
#![allow(clippy::needless_late_init)] // because of a bad derive macro
mod parser; mod parser;
mod random; mod random;
mod write; mod write;

View file

@ -176,7 +176,7 @@ fn function<F>(name: &str, ret_ty: &str, body: F)
where where
F: FnOnce(), F: FnOnce(),
{ {
println!("fn {name}(input: &[u8]) -> IResult<{ret_ty}> {{"); println!("fn {name}(input: &[u8]) -> IResult<'_, {ret_ty}> {{");
body(); body();
println!("}}"); println!("}}");
} }