Skip to content

Commit

Permalink
bump version: ruci-cmd->0.0.6;rucimp->0.0.8; minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
e1732a364fed committed Jan 1, 2099
1 parent 44cb8d6 commit 11fe07d
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/ruci-cmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ruci-cmd"
version = "0.0.5"
version = "0.0.6"
edition = "2021"
license = "MIT OR Apache-2.0"

Expand Down
2 changes: 1 addition & 1 deletion dev_res/local.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ local config_26_chain_mitm_embedder = {
}
},
{ Embedder = { file_name = "record_dir1/1-2_mitm_ruci_info.json" } },
{ Trojan = { password = "mypassword", do_not_use_early_data = true } }
{ Trojan = { password = "mypassword", do_not_use_early_data = false } }
}
} }
}
Expand Down
2 changes: 1 addition & 1 deletion doc/book/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
让我们开始吧!
[入门](get_started.md)

本手册基于 ruci v0.0.7 制作
本手册基于 ruci v0.0.8 制作
2 changes: 1 addition & 1 deletion rucimp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rucimp"
version = "0.0.7"
version = "0.0.8"
edition = "2021"

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions rucimp/src/map/steganography/embed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ impl AsyncWrite for EmbedConn {

match self.write_state.take() {
None => {
debug!("write buf when write_state is None");
let r = self.write_buf(cur_info, cx, buf, false);
match ready!(r) {
WriteBufResult::Continue => {
Expand Down
23 changes: 11 additions & 12 deletions src/map/trojan/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio::io::AsyncWriteExt;
use tracing::debug;

use crate::{
map::{self, helpers::EarlyDataWrapper, Map, MapExt, MapResult, CID},
map::{self, Map, MapExt, MapResult, CID},
net::{self, helpers, Network},
utils::ob_to_buf,
};
Expand Down Expand Up @@ -74,23 +74,22 @@ impl Client {
if self.do_not_use_early_data {
debug!(
"trojan client writing buf(not with early data) {}",
&buf[..50.min(buf.len())].escape_ascii()
buf.len()
);

base.write_all(&buf).await?;
base.flush().await?;
debug!("trojan client write done");

if is_udp {
let u = udp::from(base);
Ok(MapResult::new_u(u).b(first_payload).a(Some(ta)).build())
} else {
let b = ob_to_buf(first_payload);
if b.is_empty() || !self.is_tail_of_chain() {

if b.is_empty() {
Ok(MapResult::new_c(base).build())
} else {
debug!("trojan client using EarlyDataWrapper, {}", b.len());
let ec = EarlyDataWrapper::from(b, base);
Ok(MapResult::new_c(Box::new(ec)).build())
Ok(MapResult::new_c(base).b(Some(b)).build())
}
}
} else {
Expand All @@ -105,13 +104,13 @@ impl Client {
}
}

debug!(
"trojan client writing buf {}",
&buf[..50.min(buf.len())].escape_ascii()
);
// debug!(
// "trojan client writing buf {}",
// &buf[..50.min(buf.len())].escape_ascii()
// );
base.write_all(&buf).await?;
base.flush().await?;
debug!("trojan client write done");
// debug!("trojan client write done");

if is_udp {
let u = udp::from(base);
Expand Down
75 changes: 73 additions & 2 deletions src/net/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> AsyncWrite for RWWrapper<R, W>
}
}

/// wrap base connection with an early data buffer, read from
/// wrap base connection with an early data buffer, READ from
/// the buffer first.
pub struct EarlyDataWrapper {
ed: Option<BytesMut>,
Expand Down Expand Up @@ -244,8 +244,8 @@ impl AsyncRead for EarlyDataWrapper {
Some(ed) => {
let el = ed.len();
if el > 0 {
// debug!("EarlyDataWrapper read from ed, {}", el);
let m = min(el, buf.initialized().len());
//buf.set_filled(m);
buf.put(&ed[..m]);
ed.advance(m);
if ed.is_empty() {
Expand Down Expand Up @@ -285,6 +285,77 @@ impl AsyncWrite for EarlyDataWrapper {
}
}

pub struct EarlyWriteDataWrapper {
ed: Option<BytesMut>,
base: Pin<Conn>,
}

impl EarlyWriteDataWrapper {
pub fn from(bs: BytesMut, conn: Conn) -> Self {
EarlyWriteDataWrapper {
ed: if bs.is_empty() { None } else { Some(bs) },
base: Box::pin(conn),
}
}
}

impl AsyncRead for EarlyWriteDataWrapper {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
self.base.as_mut().poll_read(cx, buf)
}
}

impl AsyncWrite for EarlyWriteDataWrapper {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
loop {
match self.ed.take() {
None => return self.base.as_mut().poll_write(cx, buf),

Some(ed) => {
let edl = ed.len();
let r = self.base.as_mut().poll_write(cx, &ed);
self.ed = Some(ed);
match ready!(r) {
Ok(n) => {
if n == edl {
self.ed = None;
} else {
let mut ed = self.ed.take().unwrap();
ed.advance(n);
self.ed = Some(ed);
}
continue;
}
Err(e) => return Poll::Ready(Err(e)),
}
}
}
}
}

fn poll_flush(
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> Poll<io::Result<()>> {
self.base.as_mut().poll_flush(cx)
}

fn poll_shutdown(
mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> Poll<io::Result<()>> {
self.base.as_mut().poll_shutdown(cx)
}
}

pub enum BytesDisplayMode {
UTF8,
Bytes,
Expand Down

0 comments on commit 11fe07d

Please sign in to comment.