shadowsocks, trojan: send header and first payload separately

This is not the best handling but at least would not cause issues
on connections where first-payload is coming from the server side.
This commit is contained in:
eric committed 2021-05-07 13:39:40 +08:00
1 parent 30b7323866
commit ecccc94255
2 files changed
+12 -8

No files matched your search

+6 -4
View File
@@ -2,11 +2,12 @@ use std::{io, net::SocketAddr};
use async_trait::async_trait;
use bytes::BytesMut;
use tokio::io::AsyncWriteExt;
use super::shadow::ShadowedStream;
use crate::{
app::SyncDnsClient,
proxy::{BufHeadProxyStream, OutboundConnect, ProxyStream, TcpConnector, TcpOutboundHandler},
proxy::{OutboundConnect, ProxyStream, SimpleProxyStream, TcpConnector, TcpOutboundHandler},
session::{Session, SocksAddrWireType},
};
@@ -51,11 +52,12 @@ impl TcpOutboundHandler for Handler {
)
.await?
};
let stream = ShadowedStream::new(stream, &self.cipher, &self.password)?;
let mut stream = ShadowedStream::new(stream, &self.cipher, &self.password)?;
let mut buf = BytesMut::new();
sess.destination
.write_buf(&mut buf, SocksAddrWireType::PortLast)?;
// FIXME receive-only conns
Ok(Box::new(BufHeadProxyStream::new(stream, buf.freeze())))
// FIXME combine header and first payload
stream.write_all(&buf).await?;
Ok(Box::new(SimpleProxyStream(stream)))
}
}
+6 -4
View File
@@ -4,10 +4,11 @@ use std::net::SocketAddr;
use async_trait::async_trait;
use bytes::{BufMut, BytesMut};
use sha2::{Digest, Sha224};
use tokio::io::AsyncWriteExt;
use crate::{
app::SyncDnsClient,
proxy::{BufHeadProxyStream, OutboundConnect, ProxyStream, TcpConnector, TcpOutboundHandler},
proxy::{OutboundConnect, ProxyStream, SimpleProxyStream, TcpConnector, TcpOutboundHandler},
session::{Session, SocksAddrWireType},
};
@@ -36,7 +37,7 @@ impl TcpOutboundHandler for Handler {
sess: &'a Session,
stream: Option<Box<dyn ProxyStream>>,
) -> io::Result<Box<dyn ProxyStream>> {
let stream = if let Some(stream) = stream {
let mut stream = if let Some(stream) = stream {
stream
} else {
self.dial_tcp_stream(
@@ -56,7 +57,8 @@ impl TcpOutboundHandler for Handler {
sess.destination
.write_buf(&mut buf, SocksAddrWireType::PortLast)?;
buf.put_slice(b"\r\n");
// FIXME receive-only conns
Ok(Box::new(BufHeadProxyStream::new(stream, buf.freeze())))
// FIXME combine header and first payload
stream.write_all(&buf).await?;
Ok(Box::new(SimpleProxyStream(stream)))
}
}