Skip to content

Commit

Permalink
add recv log for UDP remote-to-local task
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Apr 28, 2021
1 parent 4dfcc8e commit d69a2fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
38 changes: 30 additions & 8 deletions crates/shadowsocks-service/src/local/net/udp/association.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,16 @@ where
let mut buffer = [0u8; MAXIMUM_UDP_PAYLOAD_SIZE];
loop {
let (n, addr) = match outbound.recv(&mut buffer).await {
Ok(n) => {
Ok((n, addr)) => {
trace!(
"udp relay {} <- {} (proxied) received {} bytes",
self.peer_addr,
addr,
n
);
// Keep association alive in map
let _ = self.assoc_map.lock().await.get(&self.peer_addr);
n
(n, addr)
}
Err(err) => {
// Socket that connected to remote server returns an error, it should be ECONNREFUSED in most cases.
Expand All @@ -575,24 +581,35 @@ where
// Send back to client
if let Err(err) = self.respond_writer.send_to(self.peer_addr, &addr, data).await {
warn!(
"udp failed to send back to client {}, from target {}, error: {}",
"udp failed to send back to client {}, from target {} (proxied), error: {}",
self.peer_addr, addr, err
);
continue;
}

trace!("udp relay {} <- {} with {} bytes", self.peer_addr, addr, data.len());
trace!(
"udp relay {} <- {} (proxied) with {} bytes",
self.peer_addr,
addr,
data.len()
);
}
}

async fn copy_bypassed_r2l(self: Arc<Self>, outbound: Arc<UdpSocket>) -> io::Result<()> {
let mut buffer = [0u8; MAXIMUM_UDP_PAYLOAD_SIZE];
loop {
let (n, addr) = match outbound.recv_from(&mut buffer).await {
Ok(n) => {
Ok((n, addr)) => {
trace!(
"udp relay {} <- {} (bypassed) received {} bytes",
self.peer_addr,
addr,
n
);
// Keep association alive in map
let _ = self.assoc_map.lock().await.get(&self.peer_addr);
n
(n, addr)
}
Err(err) => {
error!(
Expand All @@ -610,13 +627,18 @@ where
// Send back to client
if let Err(err) = self.respond_writer.send_to(self.peer_addr, &addr, data).await {
warn!(
"udp failed to send back to client {}, from target {}, error: {}",
"udp failed to send back to client {}, from target {} (bypassed), error: {}",
self.peer_addr, addr, err
);
continue;
}

trace!("udp relay {} <- {} with {} bytes", self.peer_addr, addr, data.len());
trace!(
"udp relay {} <- {} (bypassed) with {} bytes",
self.peer_addr,
addr,
data.len()
);
}
}
}
5 changes: 3 additions & 2 deletions crates/shadowsocks-service/src/local/tunnel/udprelay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ impl UdpAssociationContext {
async fn copy_proxied_r2l(self: Arc<Self>, outbound: Arc<MonProxySocket>) -> io::Result<()> {
let mut buffer = [0u8; MAXIMUM_UDP_PAYLOAD_SIZE];
loop {
let (n, _) = match outbound.recv(&mut buffer).await {
Ok(n) => {
let n = match outbound.recv(&mut buffer).await {
Ok((n, addr)) => {
trace!("udp relay {} <- {} received {} bytes", self.peer_addr, addr, n);
// Keep association alive in map
let _ = self.assoc_map.lock().await.get(&self.peer_addr);
n
Expand Down
5 changes: 3 additions & 2 deletions crates/shadowsocks-service/src/server/udprelay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ impl UdpAssociationContext {
let mut buffer = [0u8; MAXIMUM_UDP_PAYLOAD_SIZE];
loop {
let (n, addr) = match outbound.recv_from(&mut buffer).await {
Ok(n) => {
Ok((n, addr)) => {
trace!("udp relay {} <- {} received {} bytes", self.peer_addr, addr, n);
// Keep association alive in map
let _ = self.assoc_map.lock().await.get(&self.peer_addr);
n
(n, addr)
}
Err(err) => {
error!(
Expand Down

0 comments on commit d69a2fa

Please sign in to comment.