forked from fastly/Viceroy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add edge rate limiting hostcalls (fastly#333)
- Loading branch information
Showing
8 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//! Tests related to HTTP request and response bodies. | ||
|
||
use { | ||
crate::common::{Test, TestResult}, | ||
hyper::StatusCode, | ||
}; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn check_hostcalls_implemented() -> TestResult { | ||
let resp = Test::using_fixture("edge-rate-limiting.wasm") | ||
.against_empty() | ||
.await?; | ||
assert_eq!(resp.status(), StatusCode::OK); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::{ | ||
error::Error, session::Session, wiggle_abi::fastly_erl::FastlyErl, wiggle_abi::GuestPtr, | ||
}; | ||
|
||
impl FastlyErl for Session { | ||
fn check_rate( | ||
&mut self, | ||
_rc: &GuestPtr<str>, | ||
_entry: &GuestPtr<str>, | ||
_delta: u32, | ||
_window: u32, | ||
_limit: u32, | ||
_pb: &GuestPtr<str>, | ||
_ttl: u32, | ||
) -> std::result::Result<u32, Error> { | ||
Ok(0) | ||
} | ||
|
||
fn ratecounter_increment( | ||
&mut self, | ||
_rc: &GuestPtr<str>, | ||
_entry: &GuestPtr<str>, | ||
_delta: u32, | ||
) -> std::result::Result<(), Error> { | ||
Ok(()) | ||
} | ||
|
||
fn ratecounter_lookup_rate( | ||
&mut self, | ||
_rc: &GuestPtr<str>, | ||
_entry: &GuestPtr<str>, | ||
_window: u32, | ||
) -> std::result::Result<u32, Error> { | ||
Ok(0) | ||
} | ||
|
||
fn ratecounter_lookup_count( | ||
&mut self, | ||
_rc: &GuestPtr<str>, | ||
_entry: &GuestPtr<str>, | ||
_duration: u32, | ||
) -> std::result::Result<u32, Error> { | ||
Ok(0) | ||
} | ||
|
||
fn penaltybox_add( | ||
&mut self, | ||
_pb: &GuestPtr<str>, | ||
_entry: &GuestPtr<str>, | ||
_ttl: u32, | ||
) -> std::result::Result<(), Error> { | ||
Ok(()) | ||
} | ||
|
||
fn penaltybox_has( | ||
&mut self, | ||
_pb: &GuestPtr<str>, | ||
_entry: &GuestPtr<str>, | ||
) -> std::result::Result<u32, Error> { | ||
Ok(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! A guest program to test that edge-rate-limiting API is implemented. | ||
|
||
//use std::time::Duration; | ||
|
||
//use fastly::erl::{CounterDuration, Penaltybox, RateCounter, RateWindow, ERL}; | ||
|
||
fn main() { | ||
// let entry = "entry"; | ||
|
||
// let rc = RateCounter::open("rc"); | ||
// let pb = Penaltybox::open("pb"); | ||
// let erl = ERL::open(rc, pb); | ||
|
||
// let not_blocked = erl | ||
// .check_rate(entry, 1, RateWindow::TenSecs, 100, Duration::from_secs(300)) | ||
// .unwrap(); | ||
// assert_eq!(not_blocked, false); | ||
|
||
// let rc2 = RateCounter::open("rc"); | ||
// let rate_1 = rc2.lookup_rate(entry, RateWindow::OneSec).unwrap(); | ||
// assert_eq!(rate_1, 0); | ||
|
||
// let count10 = rc2.lookup_count(entry, CounterDuration::TenSec).unwrap(); | ||
// assert_eq!(count10, 0); | ||
|
||
// assert!(rc2.increment(entry, 600).is_ok()); | ||
|
||
// let pb2 = Penaltybox::open("pb"); | ||
// let not_in_pb = pb2.has(entry).unwrap(); | ||
// assert_eq!(not_in_pb, false); | ||
|
||
// assert!(pb2.add(entry, Duration::from_secs(300)).is_ok()); | ||
} |