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: support bandwidth configuration #645

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion component/outbound/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func NewGlobalOption(global *config.Global, log *logrus.Logger) *GlobalOption {
ExtraOption: D.ExtraOption{
AllowInsecure: global.AllowInsecure,
TlsImplementation: global.TlsImplementation,
UtlsImitate: global.UtlsImitate},
UtlsImitate: global.UtlsImitate,
BandwidthMaxTx: global.BandwidthMaxTx,
BandwidthMaxRx: global.BandwidthMaxRx},
Log: log,
TcpCheckOptionRaw: TcpCheckOptionRaw{Raw: global.TcpCheckUrl, Log: log, ResolverNetwork: common.MagicNetwork("udp", global.SoMarkFromDae, global.Mptcp), Method: global.TcpCheckHttpMethod},
CheckDnsOptionRaw: CheckDnsOptionRaw{Raw: global.UdpCheckDns, ResolverNetwork: common.MagicNetwork("udp", global.SoMarkFromDae, global.Mptcp), Somark: global.SoMarkFromDae},
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type Global struct {
UtlsImitate string `mapstructure:"utls_imitate" default:"chrome_auto"`
PprofPort uint16 `mapstructure:"pprof_port" default:"0"`
Mptcp bool `mapstructure:"mptcp" default:"false"`
// TODO: support input in human-readable format (e.g., 100Mbps, 1Gbps)
BandwidthMaxTx uint64 `mapstructure:"bandwidth_max_tx" default:"0"`
BandwidthMaxRx uint64 `mapstructure:"bandwidth_max_rx" default:"0"`
}

type Utls struct {
Expand Down
5 changes: 5 additions & 0 deletions example.dae
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ global {
# Multipath TCP (MPTCP) support. If is true, dae will try to use MPTCP to connect all nodes, but it will only take
# effects when the node supports MPTCP. It can use for load balance and failover to multiple interfaces and IPs.
mptcp: false

# The maximum bandwidth for accessing the Internet. It is useful for some specific protocols (e.g., Hysteria2),
# which will perform better with bandwith information provided. The unit is **byte** per second.
bandwidth_max_tx: 26214400 # 200Mbps == 25MB/s == 26214400 B/s uplink
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not easily add global parameters. Besides, there are not many protocols that support bandwidth settings (as far as I know). It is sufficient to design a bandwidth query parameter in the URI schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do not easily add global parameters. Besides, there are not many protocols that support bandwidth settings (as far as I know). It is sufficient to design a bandwidth query parameter in the URI schema.

@douglarek Thanks for the review.

The upstream PR also includes supports for importing maxTx and maxRx from the URI scheme, and these have higher priority over global configurations.

There are several reasons to consider adding bandwidth settings as a global option:

  1. When using subscriptions with URIs provided by external sources, you might not have control over the URI parameters they include.
  2. In principle, a URI should contain only server-related details, ensuring it can be shared across devices without modifications. Bandwidth preferences, on the other hand, are client-specific and shouldn’t be universally shared.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do not easily add global parameters. Besides, there are not many protocols that support bandwidth settings (as far as I know). It is sufficient to design a bandwidth query parameter in the URI schema.

@douglarek Thanks for the review.

The upstream PR also includes supports for importing maxTx and maxRx from the URI scheme, and these have higher priority over global configurations.

There are several reasons to consider adding bandwidth settings as a global option:

1. When using subscriptions with URIs provided by external sources, you might not have control over the URI parameters they include.

2. In principle, a URI should contain only server-related details, ensuring it can be shared across devices without modifications. Bandwidth preferences, on the other hand, are client-specific and shouldn’t be universally shared.

Regarding what you mentioned in point 1, I think the idea is good, but its actual implementation may not be perfect. If you have two subscriptions and their bandwidths are different, this global setting would not be useful. Regarding 2, this is actually intentional and cannot be considered a general rule. This is essentially a major pitfall set by the protocol designer.

bandwidth_max_rx: 131072000 # 1Gbps == 125MB/s == 131072000 B/s downlink
}

# Subscriptions defined here will be resolved as nodes and merged as a part of the global node pool.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ require (
google.golang.org/grpc v1.57.0 // indirect
)

// replace github.com/daeuniverse/outbound => ../outbound
replace github.com/daeuniverse/outbound => github.com/mnixry/outbound v0.0.0-20240921063838-5f2aa05357f0

// replace github.com/daeuniverse/quic-go => ../quic-go

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d h1:hnC39MjR7xt5kZjrKlef7DXKFDkiX8MIcDXYC/6Jf9Q=
github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d/go.mod h1:VGWGgv7pCP5WGyHGUyb9+nq/gW0yBm+i/GfCNATOJ1M=
github.com/daeuniverse/outbound v0.0.0-20240911144232-d470a59233a5 h1:L450vqT1TO+Ygzd8buBMna8d4/0asT0q74qitGTWSl4=
github.com/daeuniverse/outbound v0.0.0-20240911144232-d470a59233a5/go.mod h1:0dkFMC58MVUWMB19jwQuXEg1G16uAIAtdAU7v+yWXYs=
github.com/daeuniverse/quic-go v0.0.0-20240413031024-943f218e0810 h1:YtEYouFaNrg9sV9vf3UabvKShKn6sD0QaCdOxCwaF3g=
github.com/daeuniverse/quic-go v0.0.0-20240413031024-943f218e0810/go.mod h1:61o2uZUGLrlv1i+oO2rx9sVX0vbf8cHzdSHt7h6lMnM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -113,6 +111,8 @@ github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Cl
github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=
github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4=
github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY=
github.com/mnixry/outbound v0.0.0-20240921063838-5f2aa05357f0 h1:+5MvVaE0Guqe+UaRFRjA43jmvbnKcmZoA+v6yHfezxs=
github.com/mnixry/outbound v0.0.0-20240921063838-5f2aa05357f0/go.mod h1:0dkFMC58MVUWMB19jwQuXEg1G16uAIAtdAU7v+yWXYs=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
Loading