Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Nov 3, 2024
1 parent f785c9f commit dda7052
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 5 deletions.
90 changes: 90 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ members = [
'crates/hyperion-utils',
'events/proof-of-concept',
'crates/hyperion-circle-buf',
'crates/hyperion-permission'
'crates/hyperion-permission',
'crates/hyperion-bot'
]
resolver = '2'

[workspace.dependencies]
antithesis = {version = "0.2.4", package = "antithesis_sdk"}
anyhow = '1.0.86'
approx = '0.5.1'
arrayvec = '0.7.4'
Expand All @@ -48,7 +50,9 @@ criterion = '0.5.1'
derive-build = '0.1.1'
dirs-next = '2.0.0'
divan = '0.1.14'
dotenvy = {version = "0.15.7"}
enumset = '1.1.5'
envy = {version = "0.4.2"}
fastrand = '2.1.0'
glam = '0.29.0'
heapless = '0.8.0'
Expand All @@ -62,7 +66,7 @@ libdeflater = '1.20.0'
memmap2 = '0.9.5'
more-asserts = '0.3.1'
no_denormals = '0.1.2'
nom = "8.0.0-alpha2"
nom = '8.0.0-alpha2'
once_cell = '1.19.0'
ordered-float = '4.2.0'
ouroboros = '0.18.4'
Expand All @@ -71,6 +75,7 @@ plotters-bitmap = '0.3.6'
pretty-hex = '0.4.1'
rand = '0.8.5'
rayon = '1.10.0'
regex = {version = "1.11.1", features = ["perf", "perf-dfa-full"]} # todo: do we want perf-dfa-full?
rustc-hash = '2.0.0'
rustc_version = '0.4.0'
serde = '1.0.214'
Expand All @@ -83,8 +88,7 @@ thiserror = '1.0.63'
tikv-jemallocator = '0.6.0'
tokio = '1.40.0'
toml = '0.8.14'
tracing-tracy = {version = "0.11.3", features = ["timer-fallback"]}
uuid = '1.8.0'
uuid = {version = '1.8.0', features = ["serde"]}

[workspace.dependencies.bvh]
git = 'https://github.com/andrewgazelka/bvh-data'
Expand All @@ -109,12 +113,15 @@ default-features = false
version = '1.0.30'

[workspace.dependencies.flecs_ecs]
features = ["flecs_manual_registration"]
features = ['flecs_manual_registration']
git = 'https://github.com/Indra-db/Flecs-Rust'

[workspace.dependencies.hyperion]
path = 'crates/hyperion'

[workspace.dependencies.hyperion-bot]
path = 'crates/hyperion-bot'

[workspace.dependencies.hyperion-circle-buf]
path = 'crates/hyperion-circle-buf'

Expand Down Expand Up @@ -185,6 +192,10 @@ version = '0.1.40'
features = ['env-filter', 'time']
version = '0.3.18'

[workspace.dependencies.tracing-tracy]
features = ['timer-fallback']
version = '0.11.3'

[workspace.dependencies.valence_anvil]
branch = 'feat-open'
features = ['parsing']
Expand Down
1 change: 1 addition & 0 deletions crates/hyperion-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
25 changes: 25 additions & 0 deletions crates/hyperion-bot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[dependencies]
eyre = "0.6.12"
tokio = {features = ["full"], workspace = true}
antithesis.workspace = true
derive_more.workspace = true
dotenvy.workspace = true
envy.workspace = true
rand.workspace = true
regex.workspace = true
serde.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid.workspace = true
valence_protocol.workspace = true

[lints]
workspace = true

[package]
authors = ["Andrew Gazelka <andrew.gazelka@gmail.com>"]
edition = "2021"
name = "hyperion-bot"
publish = false
readme = "README.md"
version = "0.1.0"
1 change: 1 addition & 0 deletions crates/hyperion-bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# hyperion-bot
6 changes: 6 additions & 0 deletions crates/hyperion-bot/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct Config {
pub max_number_of_bots: usize,
}
2 changes: 2 additions & 0 deletions crates/hyperion-bot/src/generate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod name;
pub use name::{generate as name, Name};
29 changes: 29 additions & 0 deletions crates/hyperion-bot/src/generate/name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::sync::LazyLock;

use antithesis::random::AntithesisRng;
use rand::Rng;

#[derive(Clone, Debug)]
pub struct Name {
pub value: String,
pub is_valid: bool,
}

pub fn generate() -> Name {
static NAME_REGEX: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r"^[a-zA-Z0-9_]+$").unwrap());

let mut rng = AntithesisRng;

let len = rng.gen_range(0..20);
let name: String = (0..len).map(|_| rng.r#gen::<char>()).collect();

// name is max 16 characters

let is_valid = name.len() <= 16 && { NAME_REGEX.is_match(&name) };

Name {
value: name,
is_valid,
}
}
82 changes: 82 additions & 0 deletions crates/hyperion-bot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use antithesis::{assert_sometimes, random::AntithesisRng};
use derive_more::Constructor;
use rand::{rngs::StdRng, Rng};
use uuid::Uuid;
use valence_protocol::{
packets, packets::handshaking::handshake_c2s::HandshakeNextState, Bounded, VarInt,
PROTOCOL_VERSION,
};

mod config;
pub use config::Config;

mod generate;
mod util;

#[derive(Constructor)]
struct Bot {
name: String,
uuid: Uuid,
}

pub fn bootstrap(config: &Config) {
// todo: use life cycle

let mut rng = AntithesisRng;

let first_name = generate::name();
assert_sometimes!(first_name.is_valid, "First name is never invalid");
assert_sometimes!(!first_name.is_valid, "First name is always valid");

let second_name = generate::name();
assert_sometimes!(second_name.is_valid, "Second name is never invalid");
assert_sometimes!(!second_name.is_valid, "Second name is always valid");

assert_sometimes!(
first_name.value != second_name.value,
"Names are never the same"
);
assert_sometimes!(
first_name.is_valid && second_name.is_valid && first_name.value != second_name.value,
"Names are never valid and the same"
);

let first_uuid: u128 = rng.r#gen();
let first_uuid = Uuid::from_u128(first_uuid);

// todo: do we need to coax the fuzzer to more likely generate the same UUID?
let second_uuid: u128 = rng.r#gen();
let second_uuid = Uuid::from_u128(second_uuid);

assert_sometimes!(first_uuid == second_uuid, "UUIDs are always different");

let first_bot = Bot::new(first_name.value, first_uuid);
let second_bot = Bot::new(second_name.value, second_uuid);

let first_handle = tokio::spawn(login(first_bot));
let second_handle = tokio::spawn(login(second_bot));
}

async fn login(bot: Bot) {
// let mut rng = AntithesisRng;
//
// let protocol_version = util::random_either(
// || PROTOCOL_VERSION,
// || rng.gen(),
// );
//
// let is_valid_protocol_version = protocol_version == PROTOCOL_VERSION;
//
//
// let arbitrary_packet = packets::handshaking::HandshakeC2s::arbitrary(&mut rng);
//
// let
//
//
// let handshake = packets::handshaking::HandshakeC2s {
// protocol_version: VarInt(protocol_version),
// server_address: Default::default(),
// server_port: 0,
// next_state: HandshakeNextState::Login,
// };
}
17 changes: 17 additions & 0 deletions crates/hyperion-bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use eyre::{eyre, Context};
use hyperion_bot::bootstrap;

#[tokio::main]
async fn main() -> eyre::Result<()> {
tracing_subscriber::fmt::init();

// it is not an error if a .env file is missing
drop(dotenvy::dotenv());

let config = envy::from_env().wrap_err("Failed to load config from environment variables")?;

tracing::info!("{config:?}");

bootstrap(&config);
Ok(())
}
Loading

0 comments on commit dda7052

Please sign in to comment.