increase mpsc cap

serve
Avril 4 years ago
parent 87c8c525cd
commit 4ead6b5a92
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,6 @@
[package] [package]
name = "markov" name = "markov"
version = "0.1.1" version = "0.1.2"
description = "Generate string of text from Markov chain fed by stdin" description = "Generate string of text from Markov chain fed by stdin"
authors = ["Avril <flanchan@cumallover.me>"] authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018" edition = "2018"

@ -97,6 +97,7 @@ async fn gen_body(chain: Arc<RwLock<Chain<String>>>, num: Option<usize>, mut out
if !chain.is_empty() { if !chain.is_empty() {
match num { match num {
Some(num) if num < MAX_GEN_SIZE => { Some(num) if num < MAX_GEN_SIZE => {
//This could DoS `full_body` and writes, potentially.
for string in chain.str_iter_for(num) { for string in chain.str_iter_for(num) {
output.send(string).await.map_err(|e| GenBodyError(e.0))?; output.send(string).await.map_err(|e| GenBodyError(e.0))?;
} }
@ -149,7 +150,7 @@ async fn main() {
.and(warp::path::param().map(|opt: usize| Some(opt)).or(warp::any().map(|| Option::<usize>::None)).unify()) .and(warp::path::param().map(|opt: usize| Some(opt)).or(warp::any().map(|| Option::<usize>::None)).unify())
.and_then(|chain: Arc<RwLock<Chain<String>>>, host: IpAddr, num: Option<usize>| { .and_then(|chain: Arc<RwLock<Chain<String>>>, host: IpAddr, num: Option<usize>| {
async move { async move {
let (tx, rx) = mpsc::channel(16); let (tx, rx) = mpsc::channel(MAX_GEN_SIZE);
tokio::spawn(gen_body(chain, num, tx)); tokio::spawn(gen_body(chain, num, tx));
Ok::<_, std::convert::Infallible>(Response::new(Body::wrap_stream(rx.map(move |x| { Ok::<_, std::convert::Infallible>(Response::new(Body::wrap_stream(rx.map(move |x| {
info!("{} <- {:?}", host, x); info!("{} <- {:?}", host, x);

Loading…
Cancel
Save