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

feat: hysteria draft #217

Merged
merged 2 commits into from
Oct 16, 2024
Merged

feat: hysteria draft #217

merged 2 commits into from
Oct 16, 2024

Conversation

eauxxs
Copy link
Contributor

@eauxxs eauxxs commented Dec 16, 2023

🤔 This is a ...

  • New feature

🔗 Related issue link

💡 Background and solution

📝 Changelog

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Changelog is provided or not needed

@@ -0,0 +1,43 @@
use std::sync::Arc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put this under clash_lib/src/proxy/converters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@eauxxs
Copy link
Contributor Author

eauxxs commented Dec 17, 2023

At present, hysteria2 can already perform tcp proxy, mainly udp proxy, brutal congestion, ports hopping has not been implemented, port hopping may be just a small problem.
In the process of implementing salamander, I encountered a very confusing problem. The obfuscation can be correctly encrypted and decrypted by both parties, and the quic connection can be established. But when sending h3 authentication, an error will occur. I don’t know if it’s a problem with the h3 library or the obfuscation algorithm itself or something else. I don’t know if you know more about quic and if you have any ideas.
@ibigbug @greenhat616 @xmh0511

@greenhat616
Copy link
Collaborator

I'm busy these days. while I am spare, I could take a look.

@eauxxs
Copy link
Contributor Author

eauxxs commented Dec 19, 2023

I'm busy these days. while I am spare, I could take a look.

thanks, salamander obfs have been fixed, it work now

@ibigbug
Copy link
Member

ibigbug commented Dec 25, 2023

Hey thank you guys.

I see that you've fixed the problem, is there anything left to be done for this PR?

@ibigbug
Copy link
Member

ibigbug commented Dec 25, 2023

@eauxxs the build is failed on Windows

@@ -60,5 +60,5 @@ proxies:
udp: true

rules:
- MATCH, ss
- MATCH, ss-01
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- MATCH, ss-01
- MATCH, ss


proxies:
- name: "local"
type: Hysteria2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type: Hysteria2
type: hysteria2

@@ -6,6 +6,7 @@ use serde::Serialize;
use tokio::sync::broadcast::Sender;

use tracing::debug;
use tracing::Level;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use tracing::Level;

@@ -103,6 +104,11 @@ pub fn setup_logging(
)
.from_env_lossy();

// let trace = tracing_subscriber::filter::targets::Targets::new()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do something like this to enable the level RUST_LOG=h2=trace,clash=debug

@@ -53,6 +53,7 @@ pub enum OutboundProxyProtocol {
Trojan(OutboundTrojan),
#[serde(rename = "vmess")]
Vmess(OutboundVmess),
Hysteria2(OutboundHysteria2),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Hysteria2(OutboundHysteria2),
#[serde(rename = "hysteria2")]
Hysteria2(OutboundHysteria2),


use crate::proxy::converters::hysteria2::PortGenrateor;

pub struct UdpHop {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a short description for this struct, such as what part it plays in the protocol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

println!("done");
// std::thread::sleep(std::time::Duration::from_secs(100000));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// std::thread::sleep(std::time::Duration::from_secs(100000));

@@ -368,3 +371,53 @@ impl TryFrom<HashMap<String, Value>> for OutboundProxyProviderDef {
.map_err(map_serde_error)
}
}

// #hysteria2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great if you can convert these into the standard doc comment https://doc.rust-lang.org/rust-by-example/meta/doc.html

so that we might use them in future to generate the API references


struct Burtal;

impl Controller for Burtal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used any where?


use quinn_proto::congestion::{Bbr, BbrConfig, Controller, ControllerFactory};

pub struct DynCongestion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this file used at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current protocol still needs to implement the congestion algorithm and udp proxy. I will fix this part of the code next week.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can not wait it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can not wait it

哥们尽快吧,主要是最近比较忙,还生病了。
另外rust的quinn拥塞算法接口和go的那边还不一样,go这边有现成的,rust没有,工作还比较多。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

身体要紧。
如果有什么问题可以分享出来大家一起看。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢关心。目前就是拥塞算法,对照着go版本hysteria的brutal拥塞算法,它那里是计算丢包个数再进行调整发送速率,quinn接口只有丢包字节数,我问一下这个issue,目前还在看,不知道是否有更好的方法

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看有回复,如果他的说法可行,提个PR?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can not wait it

@eauxxs
Copy link
Contributor Author

eauxxs commented Dec 28, 2023

@eauxxs the build is failed on Windows

It looks like the problem is with borrowing-ssl, can we remove deps directory, and use boring crate directly, why it is necessary?

@ibigbug
Copy link
Member

ibigbug commented Dec 31, 2023

@eauxxs the build is failed on Windows

It looks like the problem is with borrowing-ssl, can we remove deps directory, and use boring crate directly, why it is necessary?

the forked boring added aes and this #240 removes it

@ibigbug ibigbug changed the title hysteria draft feat: hysteria draft May 10, 2024
@ibigbug
Copy link
Member

ibigbug commented Sep 11, 2024

@eauxxs Any blockers for this ?

@eauxxs
Copy link
Contributor Author

eauxxs commented Sep 16, 2024

@ibigbug I'm very sorry that I just saw this news now. One is the problem of my work, and the other is the congestion control algorithm of quic. The other aspects of the protocol have been implemented. . . Regarding congestion control, I can only refer to the implementation of go, but I still don't know how to implement it. If you only use bbr, you can use it directly.

@ibigbug
Copy link
Member

ibigbug commented Sep 16, 2024

No worries. Thanks for the update. I might be able to take it over when I get some time.

@eauxxs
Copy link
Contributor Author

eauxxs commented Sep 17, 2024

I'm very sorry for taking so long. It's okay, I will rebase to the latest branch first. Then try to make a usable version. I like this project very much. . . I will give you feedback in time if I encounter any problems later.

@ibigbug
Copy link
Member

ibigbug commented Sep 17, 2024

Much appreciated!

@lmmqxyx404
Copy link

6e4b2a8 这个分支的代码我在我本地 ubuntu22.04 机器上跑了下 hysteria2 代理,发现建立连接时就报错。
通过 wireshaek 抓包后发现,
Initial 连接时的 Crypto Frame 包含了 handshake 握手信息, 其中 Extension::signature_algorithms 为空,导致 client 发出的信息不正常。 分析了代码后,我发现可能是 tls_config 这个变量初始化有问题。
在我改了supported_verify_schemes 这个函数后。客户端发出的 handshake 正常,但是服务端的响应,客户端无法正常解析。
[Failed to create decryption context: Secrets are not available]


I ran the hysteria2 proxy on my local Ubuntu 22.04 machine using the code from branch 6e4b2a8, and encountered an error when establishing a connection.

After capturing packets, I found that during the initial connection, the Crypto frame contained handshake information, but the Extension::signature_algorithms field was empty. This caused the client to send abnormal information. After analyzing the code, I found that the issue might be with the initialization of the tls_config variable.

After modifying the supported_verify_schemes function, the handshake sent by the client became normal, but the server’s response could not be correctly parsed by the client. The error message is:

[Failed to create decryption context: Secrets are not available]

@eauxxs
Copy link
Contributor Author

eauxxs commented Sep 19, 2024

@lmmqxyx404 谢谢你的review。目前这个最新的提交只是基于最新的分支进行rebase。因为rustls,h3-quinn,quinn版本的更新,所以以前的代码也不可用了。这次pr也更新到了相关依赖的最新版本,而且有些方法重写了,但是我还没有时间来得及测试,如果你那边发现了问题,可以在这个分支上提交,一起工作。也可以另开一个分支,重用一些这个pr的代码,如果能用的到的话。

@lmmqxyx404
Copy link

@eauxxs 我倒是挺想把这个功能实现的,不过主要是我能力有限。不知道改的方向,只好做一些琐碎的工作。

如果大哥有什么好的思路,就在这一起讨论下吧,万望不吝赐教。

@lmmqxyx404
Copy link

我对于服务端的响应理解有误,原始go实现的 hysteria2 服务端响应被抓包后,也是一样会报错。这个问题还需要继续分析

@lmmqxyx404
Copy link

lmmqxyx404 commented Oct 12, 2024

@eauxxs @ibigbug 我这边修改代码已经让hysteria2 协议跑起来了
总的来说只要改动两处代码。

  1. supported_verify_schemes 前面已经说过了
let any = session
           .congestion_state()
           .into_any()
           .downcast::<DynController>()
           .unwrap();
       any.set_controller(Box::new(Burtal::new(0, session.clone())));

改为

match session
            .congestion_state()
            .into_any()
            .downcast::<DynController>()
        {
            Ok(any) => {
                any.set_controller(Box::new(Burtal::new(0, session.clone())));
            }
            Err(err) => {
                tracing::error!("Failed to downcast congestion controller");
            }
        }

@ibigbug
Copy link
Member

ibigbug commented Oct 12, 2024

@eauxxs 看看?

@eauxxs
Copy link
Contributor Author

eauxxs commented Oct 15, 2024

@lmmqxyx404 @ibigbug 这些都是些小问题,主要的问题是拥塞控制,还有一个问题是端口跳跃的问题。目前拥塞控制需要帮助。。

@lmmqxyx404
Copy link

@lmmqxyx404 @ibigbug 这些都是些小问题,主要的问题是拥塞控制,还有一个问题是端口跳跃的问题。目前拥塞控制需要帮助。。

具体是什么问题呢?能不能具体说说,如果容易解决,我最近有空,可以再试着去解决下。

@ibigbug ibigbug merged commit 6f15468 into Watfaq:master Oct 16, 2024
2 of 24 checks passed
@ibigbug ibigbug mentioned this pull request Oct 16, 2024
12 tasks
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

Successfully merging this pull request may close these issues.

5 participants