Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

服务端无法处理rtmp流数据 #14

Open
qiuzi opened this issue Apr 1, 2021 · 5 comments
Open

服务端无法处理rtmp流数据 #14

qiuzi opened this issue Apr 1, 2021 · 5 comments

Comments

@qiuzi
Copy link

qiuzi commented Apr 1, 2021

作为服务端无法中继twitch的rtmp流

[2021-04-01T10:20:32Z DEBUG trojan_r::protocol::direct::connector] direct: connecting to 52.223.247.225:1935
[2021-04-01T10:20:32Z INFO  trojan_r::proxy] relaying tcp stream to [2607:f8b0:4007:80c::200c]:1935
[2021-04-01T10:20:32Z INFO  trojan_r::proxy] relaying tcp stream to 52.223.247.225:1935
[2021-04-01T10:20:36Z DEBUG trojan_r::protocol::mux::acceptor] new mux stream 6 accepted
[2021-04-01T10:20:36Z DEBUG trojan_r::protocol::direct::connector] direct: connecting to 91.108.56.176:80
[2021-04-01T10:20:36Z INFO  trojan_r::proxy] relaying tcp stream to 91.108.56.176:80
[2021-04-01T10:20:39Z DEBUG trojan_r::protocol::mux::acceptor] new mux stream 7 accepted
[2021-04-01T10:20:39Z DEBUG trojan_r::protocol::direct::connector] direct: connecting to [2607:f8b0:4023:c03::bc]:443
[2021-04-01T10:20:39Z INFO  trojan_r::proxy] relaying tcp stream to [2607:f8b0:4023:c03::bc]:443
[2021-04-01T10:20:42Z DEBUG trojan_r::protocol::mux::acceptor] new mux stream 8 accepted
[2021-04-01T10:20:42Z DEBUG trojan_r::protocol::direct::connector] direct: connecting to 91.108.56.176:80
[2021-04-01T10:20:42Z INFO  trojan_r::proxy] relaying tcp stream to 91.108.56.176:80
[2021-04-01T10:20:43Z DEBUG trojan_r::protocol::mux::acceptor] new mux stream 9 accepted
[2021-04-01T10:20:43Z DEBUG trojan_r::protocol::direct::connector] direct: connecting to 52.88.36.248:443
[2021-04-01T10:20:43Z INFO  trojan_r::proxy] relaying tcp stream to 52.88.36.248:443
[2021-04-01T10:21:03Z INFO  trojan_r::proxy] tcp session ends
[2021-04-01T10:21:03Z DEBUG trojan_r::protocol::mux] local shutdown stream 4
[2021-04-01T10:21:06Z DEBUG trojan_r::proxy] relay_tcp err: Connection reset by peer (os error 104)
[2021-04-01T10:21:06Z INFO  trojan_r::proxy] tcp session ends
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] frame recvd but the stream 5 is closed
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] echo finish frame 5
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 4
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 5
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 4
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 5
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 4
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 5
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 4
[2021-04-01T10:21:06Z DEBUG trojan_r::protocol::mux] invalid frame recvd, stream_id = 5

无mux:

[2021-04-01T10:33:45Z DEBUG tungstenite::handshake::server] Server handshake done.
[2021-04-01T10:33:45Z INFO  trojan_r::protocol::trojan::acceptor] trojan tcp stream 52.223.247.183:1935
[2021-04-01T10:33:45Z DEBUG trojan_r::protocol::direct::connector] direct: connecting to 52.223.247.183:1935
[2021-04-01T10:33:45Z INFO  trojan_r::proxy] relaying tcp stream to 52.223.247.183:1935
[2021-04-01T10:33:47Z DEBUG tungstenite::handshake::server] Server handshake done.

开mux无法正常推流 关闭mux会间接性中断
image

@cattyhouse
Copy link

try this patch, see if it solves the problem, use write_all instead of write in copy_tcp:

diff --git a/src/proxy/mod.rs b/src/proxy/mod.rs
index d0e3342..3559e40 100644
--- a/src/proxy/mod.rs
+++ b/src/proxy/mod.rs
@@ -61,7 +61,7 @@ async fn copy_tcp<R: AsyncRead + Unpin, W: AsyncWrite + Unpin>(
         if len == 0 {
             break;
         }
-        w.write(&buf[..len]).await?;
+        w.write_all(&buf[..len]).await?;
         w.flush().await?;
     }
     Ok(())

@cattyhouse
Copy link

对于 mux 这部 也许需要改 protocol/mux/mod.rs 的 line 92:

w.write(&buf).await?; 改为 w.write_all(&buf).await?;

总而言之所有 AsyncWrite 的方法里面都用 write_all

@cattyhouse
Copy link

所有涉及 TCP AsyncWrite 的地方全部改成 write_all

用法: 保存这个内容到 tcp-async-write_all.patch, 然后 cd trojan-r ; git apply tcp-async-write_all.patch

diff --git a/src/protocol/mux/mod.rs b/src/protocol/mux/mod.rs
index 882a42e..35c0e98 100644
--- a/src/protocol/mux/mod.rs
+++ b/src/protocol/mux/mod.rs
@@ -89,7 +89,7 @@ impl RequestHeader {
         cursor.put_u8(cmd);
         addr.write_to_buf(cursor);
 
-        w.write(&buf).await?;
+        w.write_all(&buf).await?;
         Ok(())
     }
 }
@@ -138,9 +138,9 @@ impl MuxFrame {
         cursor.put_u8(command);
         cursor.put_u16_le(data_length as u16);
         cursor.put_u32_le(stream_id);
-        writer.write(&buf).await?;
+        writer.write_all(&buf).await?;
         if let MuxFrame::Push(f) = self {
-            writer.write(&f.data).await?;
+            writer.write_all(&f.data).await?;
         }
         writer.flush().await?;
         Ok(())
diff --git a/src/protocol/socks5/mod.rs b/src/protocol/socks5/mod.rs
index fe6fd1c..2a6b587 100644
--- a/src/protocol/socks5/mod.rs
+++ b/src/protocol/socks5/mod.rs
@@ -114,7 +114,7 @@ impl TcpResponseHeader {
     {
         let mut buf = BytesMut::with_capacity(self.serialized_len());
         self.write_to_buf(&mut buf);
-        w.write(&buf).await?;
+        w.write_all(&buf).await?;
         Ok(())
     }
 
diff --git a/src/protocol/trojan/mod.rs b/src/protocol/trojan/mod.rs
index 1ab97b4..72e7e7a 100644
--- a/src/protocol/trojan/mod.rs
+++ b/src/protocol/trojan/mod.rs
@@ -122,7 +122,7 @@ impl RequestHeader {
         addr.write_to_buf(cursor);
         cursor.put_slice(crlf);
 
-        w.write(&buf).await?;
+        w.write_all(&buf).await?;
         Ok(())
     }
 }
@@ -173,7 +173,7 @@ impl UdpHeader {
         self.address.write_to_buf(cursor);
         cursor.put_u16(self.payload_len);
         cursor.put_slice(b"\r\n");
-        w.write(&buf).await?;
+        w.write_all(&buf).await?;
         Ok(())
     }
 }
diff --git a/src/proxy/mod.rs b/src/proxy/mod.rs
index d0e3342..3559e40 100644
--- a/src/proxy/mod.rs
+++ b/src/proxy/mod.rs
@@ -61,7 +61,7 @@ async fn copy_tcp<R: AsyncRead + Unpin, W: AsyncWrite + Unpin>(
         if len == 0 {
             break;
         }
-        w.write(&buf[..len]).await?;
+        w.write_all(&buf[..len]).await?;
         w.flush().await?;
     }
     Ok(())

@qiuzi
Copy link
Author

qiuzi commented May 13, 2024

居然还在维护?
@cattyhouse 是不是有新的客户端支持?

@cattyhouse
Copy link

@qiuzi 没有, 我也是在使用这个客户端过程中发现 relay_tcp err: Connection reset by peer (os error 104), 导致一些网络问题, 比如下载断流, 下载包不完整等, 打了这个 patch 后, 问题消失.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants