Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CDN] Implement hooks for DDoS protection #3664

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fd553c1
implement cdn hooks
rob-maron Sep 9, 2024
fa4259e
revert `justfile` changes
rob-maron Sep 9, 2024
3ecc2fc
Merge remote-tracking branch 'origin/main' into rm/cdn-hooks
rob-maron Sep 9, 2024
9c59725
improvement to topic hashing
rob-maron Sep 10, 2024
30ed13e
`date` -> `data`
rob-maron Sep 10, 2024
91b466b
`sma` algorithm
rob-maron Sep 10, 2024
81768ae
Merge remote-tracking branch 'origin/main' into rm/cdn-hooks
rob-maron Sep 10, 2024
57a4bf8
`clippy`
rob-maron Sep 11, 2024
7bd8912
refactor a bit
rob-maron Sep 11, 2024
138f1db
change default configuration
rob-maron Sep 11, 2024
451e2c0
add minimum to hook
rob-maron Sep 11, 2024
0aab9f8
remove minimum
rob-maron Sep 11, 2024
6f964fa
Merge branch 'main' into rm/cdn-hooks
rob-maron Sep 11, 2024
d41f297
make tests more lenient
rob-maron Sep 11, 2024
ba44b2e
simplify code, clamp to `max(1000bps,global_avg)`
rob-maron Sep 11, 2024
e2bcf54
make tests more lenient
rob-maron Sep 11, 2024
9d535ac
better clamping
rob-maron Sep 11, 2024
4f7719a
fix clamping (again)
rob-maron Sep 11, 2024
b7a42b6
Merge remote-tracking branch 'origin/main' into rm/cdn-hooks
rob-maron Sep 12, 2024
63e37f8
Merge remote-tracking branch 'origin/main' into rm/cdn-hooks
rob-maron Sep 13, 2024
c72f3a9
extrapolate out the cache
rob-maron Sep 13, 2024
8691fec
skip the message instead of kicking them
rob-maron Sep 13, 2024
5a360bb
fix comment
rob-maron Sep 13, 2024
8aa43ba
cooldown functionality
rob-maron Sep 13, 2024
2b4964b
remove checked div
rob-maron Sep 13, 2024
12e422f
Merge branch 'main' into rm/cdn-hooks
rob-maron Sep 16, 2024
946d61a
add to sample even if cooling down
rob-maron Sep 16, 2024
da87823
fix test
rob-maron Sep 16, 2024
84fa587
move local and global sample commit
rob-maron Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ espresso-systems-common = { git = "https://github.com/espressosystems/espresso-s
ethereum-types = { version = "0.14", default-features = false, features = [
"serialize",
] }
derive_more = { version = "1.0", features = [ "from" ] }
derive_more = { version = "1.0", features = ["from"] }
futures = { version = "0.3", default-features = false }
# TODO generic-array should not be a direct dependency
# https://github.com/EspressoSystems/HotShot/issues/1850
Expand Down Expand Up @@ -121,10 +121,10 @@ anyhow = "1"


# Push CDN imports
cdn-client = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.7" }
cdn-broker = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.7" }
cdn-marshal = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.7" }
cdn-proto = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.7" }
cdn-client = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.9" }
cdn-broker = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.9" }
cdn-marshal = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.9" }
cdn-proto = { git = "https://github.com/EspressoSystems/Push-CDN", tag = "0.4.9" }

### Profiles
###
Expand Down
53 changes: 29 additions & 24 deletions crates/examples/combined/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use async_compatibility_layer::{
art::async_spawn,
logging::{setup_backtrace, setup_logging},
};
use cdn_broker::Broker;
use cdn_broker::{reexports::def::hook::NoMessageHook, Broker};
use cdn_marshal::Marshal;
use hotshot::{
traits::implementations::{KeyPair, TestingDef, WrappedSignatureKey},
traits::implementations::{HotShotMessageHook, KeyPair, TestingDef, WrappedSignatureKey},
types::SignatureKey,
};
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
Expand Down Expand Up @@ -72,28 +72,34 @@ async fn main() {
let private_address = format!("127.0.0.1:{private_port}");
let public_address = format!("127.0.0.1:{public_port}");

let config: cdn_broker::Config<TestingDef<<TestTypes as NodeType>::SignatureKey>> =
cdn_broker::Config {
discovery_endpoint: discovery_endpoint.clone(),
public_advertise_endpoint: public_address.clone(),
public_bind_endpoint: public_address,
private_advertise_endpoint: private_address.clone(),
private_bind_endpoint: private_address,

keypair: KeyPair {
public_key: WrappedSignatureKey(broker_public_key),
private_key: broker_private_key.clone(),
},
// Create the message hooks
let broker_message_hook = NoMessageHook;
let user_message_hook = HotShotMessageHook::default();

let config: cdn_broker::Config<TestingDef<TestTypes>> = cdn_broker::Config {
discovery_endpoint: discovery_endpoint.clone(),
public_advertise_endpoint: public_address.clone(),
public_bind_endpoint: public_address,
private_advertise_endpoint: private_address.clone(),
private_bind_endpoint: private_address,

keypair: KeyPair {
public_key: WrappedSignatureKey(broker_public_key),
private_key: broker_private_key.clone(),
},

metrics_bind_endpoint: None,
ca_cert_path: None,
ca_key_path: None,
global_memory_pool_size: Some(1024 * 1024 * 1024),

metrics_bind_endpoint: None,
ca_cert_path: None,
ca_key_path: None,
global_memory_pool_size: Some(1024 * 1024 * 1024),
};
user_message_hook,
broker_message_hook,
};

// Create and spawn the broker
async_spawn(async move {
let broker: Broker<TestingDef<<TestTypes as NodeType>::SignatureKey>> =
let broker: Broker<TestingDef<TestTypes>> =
Broker::new(config).await.expect("broker failed to start");

// Error if we stopped unexpectedly
Expand Down Expand Up @@ -121,10 +127,9 @@ async fn main() {

// Spawn the marshal
async_spawn(async move {
let marshal: Marshal<TestingDef<<TestTypes as NodeType>::SignatureKey>> =
Marshal::new(marshal_config)
.await
.expect("failed to spawn marshal");
let marshal: Marshal<TestingDef<TestTypes>> = Marshal::new(marshal_config)
.await
.expect("failed to spawn marshal");

// Error if we stopped unexpectedly
if let Err(err) = marshal.start().await {
Expand Down
56 changes: 32 additions & 24 deletions crates/examples/push-cdn/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ pub mod types;
use std::path::Path;

use async_compatibility_layer::art::async_spawn;
use cdn_broker::{reexports::crypto::signature::KeyPair, Broker};
use cdn_broker::{
reexports::{crypto::signature::KeyPair, def::hook::NoMessageHook},
Broker,
};
use cdn_marshal::Marshal;
use hotshot::{
traits::implementations::{TestingDef, WrappedSignatureKey},
traits::implementations::{HotShotMessageHook, TestingDef, WrappedSignatureKey},
types::SignatureKey,
};
use hotshot_example_types::{node_types::TestVersions, state_types::TestTypes};
Expand Down Expand Up @@ -78,28 +81,34 @@ async fn main() {
let private_address = format!("127.0.0.1:{private_port}");
let public_address = format!("127.0.0.1:{public_port}");

let config: cdn_broker::Config<TestingDef<<TestTypes as NodeType>::SignatureKey>> =
cdn_broker::Config {
discovery_endpoint: discovery_endpoint.clone(),
public_advertise_endpoint: public_address.clone(),
public_bind_endpoint: public_address,
private_advertise_endpoint: private_address.clone(),
private_bind_endpoint: private_address,

keypair: KeyPair {
public_key: WrappedSignatureKey(broker_public_key),
private_key: broker_private_key.clone(),
},
// Create the message hooks
let broker_message_hook = NoMessageHook;
let user_message_hook = HotShotMessageHook::default();

let config: cdn_broker::Config<TestingDef<TestTypes>> = cdn_broker::Config {
discovery_endpoint: discovery_endpoint.clone(),
public_advertise_endpoint: public_address.clone(),
public_bind_endpoint: public_address,
private_advertise_endpoint: private_address.clone(),
private_bind_endpoint: private_address,

keypair: KeyPair {
public_key: WrappedSignatureKey(broker_public_key),
private_key: broker_private_key.clone(),
},

metrics_bind_endpoint: None,
ca_cert_path: None,
ca_key_path: None,
global_memory_pool_size: Some(1024 * 1024 * 1024),

metrics_bind_endpoint: None,
ca_cert_path: None,
ca_key_path: None,
global_memory_pool_size: Some(1024 * 1024 * 1024),
};
user_message_hook,
broker_message_hook,
};

// Create and spawn the broker
async_spawn(async move {
let broker: Broker<TestingDef<<TestTypes as NodeType>::SignatureKey>> =
let broker: Broker<TestingDef<TestTypes>> =
Broker::new(config).await.expect("broker failed to start");

// Error if we stopped unexpectedly
Expand All @@ -125,10 +134,9 @@ async fn main() {

// Spawn the marshal
async_spawn(async move {
let marshal: Marshal<TestingDef<<TestTypes as NodeType>::SignatureKey>> =
Marshal::new(marshal_config)
.await
.expect("failed to spawn marshal");
let marshal: Marshal<TestingDef<TestTypes>> = Marshal::new(marshal_config)
.await
.expect("failed to spawn marshal");

// Error if we stopped unexpectedly
if let Err(err) = marshal.start().await {
Expand Down
15 changes: 12 additions & 3 deletions crates/examples/push-cdn/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
//! The following is the main `Broker` binary, which just instantiates and runs
//! a `Broker` object.
use anyhow::Result;
use cdn_broker::{Broker, Config};
use cdn_broker::{reexports::def::hook::NoMessageHook, Broker, Config};
use clap::Parser;
use hotshot::traits::implementations::{KeyPair, ProductionDef, WrappedSignatureKey};
use hotshot::traits::implementations::{
HotShotMessageHook, KeyPair, ProductionDef, WrappedSignatureKey,
};
use hotshot_example_types::node_types::TestTypes;
use hotshot_types::traits::{node_implementation::NodeType, signature_key::SignatureKey};
use sha2::Digest;
Expand Down Expand Up @@ -91,8 +93,12 @@ async fn main() -> Result<()> {
let (public_key, private_key) =
<TestTypes as NodeType>::SignatureKey::generated_from_seed_indexed(key_hash.into(), 1337);

// Create the message hooks
let broker_message_hook = NoMessageHook;
let user_message_hook = HotShotMessageHook::default();

// Create config
let broker_config: Config<ProductionDef<<TestTypes as NodeType>::SignatureKey>> = Config {
let broker_config: Config<ProductionDef<TestTypes>> = Config {
ca_cert_path: args.ca_cert_path,
ca_key_path: args.ca_key_path,

Expand All @@ -108,6 +114,9 @@ async fn main() -> Result<()> {
private_bind_endpoint: args.private_bind_endpoint,
private_advertise_endpoint: args.private_advertise_endpoint,
global_memory_pool_size: Some(args.global_memory_pool_size),

user_message_hook,
broker_message_hook,
};

// Create new `Broker`
Expand Down
4 changes: 1 addition & 3 deletions crates/examples/push-cdn/marshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use cdn_marshal::{Config, Marshal};
use clap::Parser;
use hotshot::traits::implementations::ProductionDef;
use hotshot_example_types::node_types::TestTypes;
use hotshot_types::traits::node_implementation::NodeType;
use tracing_subscriber::EnvFilter;

// TODO: forall, add logging where we need it
Expand Down Expand Up @@ -81,8 +80,7 @@ async fn main() -> Result<()> {
};

// Create new `Marshal` from the config
let marshal =
Marshal::<ProductionDef<<TestTypes as NodeType>::SignatureKey>>::new(config).await?;
let marshal = Marshal::<ProductionDef<TestTypes>>::new(config).await?;

// Start the main loop, consuming it
marshal.start().await?;
Expand Down
2 changes: 2 additions & 0 deletions crates/hotshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ blake3.workspace = true
sha2 = { workspace = true }
url = { workspace = true }
num_enum = "0.7"
twox-hash = { version = "1", default-features = false }
parking_lot = "0.12"
simple_moving_average = "1"

[target.'cfg(all(async_executor_impl = "tokio"))'.dependencies]
tokio = { workspace = true }
Expand Down
8 changes: 6 additions & 2 deletions crates/hotshot/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ pub mod implementations {
},
memory_network::{MasterMap, MemoryNetwork},
push_cdn_network::{
CdnMetricsValue, KeyPair, ProductionDef, PushCdnNetwork, TestingDef, Topic as CdnTopic,
WrappedSignatureKey,
definition::{
message_hook::HotShotMessageHook, signature_key::WrappedSignatureKey,
ProductionDef, TestingDef, Topic as CdnTopic,
},
metrics::CdnMetricsValue,
KeyPair, PushCdnNetwork,
},
};
}
Loading
Loading