mirror of
https://github.com/Gouryella/drip.git
synced 2026-03-04 04:43:47 +00:00
- Implement client bandwidth limitation parameter --bandwidth, supporting 1M, 1MB, 1G and other formats - Added parseBandwidth function to parse bandwidth values and verify them - Added bandwidth limit option in HTTP, HTTPS, TCP commands - Pass bandwidth configuration to the server through protocol - Add relevant test cases to verify the bandwidth analysis function feat(server): implements server-side bandwidth limitation function - Add bandwidth limitation logic in connection processing, using token bucket algorithm - Implement an effective rate limiting strategy that minimizes the bandwidth of the client and server - Added QoS limiter and restricted connection wrapper - Integrated bandwidth throttling in HTTP and WebSocket proxies - Added global bandwidth limit and burst multiplier settings in server configuration docs: Updated documentation to describe bandwidth limiting functionality - Add 2025-02-14 version update instructions in README and README_CN - Add bandwidth limit function description and usage examples - Provide client and server configuration examples and parameter descriptions
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"drip/pkg/config"
|
|
)
|
|
|
|
func buildDaemonArgs(tunnelType string, args []string, subdomain string, localAddress string) []string {
|
|
daemonArgs := append([]string{tunnelType}, args...)
|
|
daemonArgs = append(daemonArgs, "--daemon-child")
|
|
|
|
if subdomain != "" {
|
|
daemonArgs = append(daemonArgs, "--subdomain", subdomain)
|
|
}
|
|
if localAddress != "127.0.0.1" {
|
|
daemonArgs = append(daemonArgs, "--address", localAddress)
|
|
}
|
|
if serverURL != "" {
|
|
daemonArgs = append(daemonArgs, "--server", serverURL)
|
|
}
|
|
if authToken != "" {
|
|
daemonArgs = append(daemonArgs, "--token", authToken)
|
|
}
|
|
if authPass != "" {
|
|
daemonArgs = append(daemonArgs, "--auth", authPass)
|
|
}
|
|
if authBearer != "" {
|
|
daemonArgs = append(daemonArgs, "--auth-bearer", authBearer)
|
|
}
|
|
if bandwidth != "" {
|
|
daemonArgs = append(daemonArgs, "--bandwidth", bandwidth)
|
|
}
|
|
if insecure {
|
|
daemonArgs = append(daemonArgs, "--insecure")
|
|
}
|
|
if verbose {
|
|
daemonArgs = append(daemonArgs, "--verbose")
|
|
}
|
|
|
|
return daemonArgs
|
|
}
|
|
|
|
func resolveServerAddrAndToken(tunnelType string, port int) (string, string, error) {
|
|
if serverURL != "" {
|
|
return serverURL, authToken, nil
|
|
}
|
|
|
|
cfg, err := config.LoadClientConfig("")
|
|
if err != nil {
|
|
return "", "", fmt.Errorf(`configuration not found.
|
|
|
|
Please run 'drip config init' first, or use flags:
|
|
drip %s %d --server SERVER:PORT --token TOKEN`, tunnelType, port)
|
|
}
|
|
|
|
if cfg.Server == "" {
|
|
return "", "", fmt.Errorf("server address is required")
|
|
}
|
|
|
|
return cfg.Server, cfg.Token, nil
|
|
}
|
|
|
|
func newDaemonInfo(tunnelType string, port int, subdomain string, serverAddr string) *DaemonInfo {
|
|
return &DaemonInfo{
|
|
PID: os.Getpid(),
|
|
Type: tunnelType,
|
|
Port: port,
|
|
Subdomain: subdomain,
|
|
Server: serverAddr,
|
|
StartTime: time.Now(),
|
|
Executable: os.Args[0],
|
|
}
|
|
}
|