mirror of
https://github.com/rclone/rclone.git
synced 2025-08-16 00:28:09 +02:00
fshttp: add DSCP support with --dscp for QoS with differentiated services
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
@ -29,6 +30,7 @@ var (
|
||||
deleteAfter bool
|
||||
bindAddr string
|
||||
disableFeatures string
|
||||
dscp string
|
||||
uploadHeaders []string
|
||||
downloadHeaders []string
|
||||
headers []string
|
||||
@ -125,6 +127,7 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) {
|
||||
flags.StringArrayVarP(flagSet, &headers, "header", "", nil, "Set HTTP header for all transactions")
|
||||
flags.BoolVarP(flagSet, &ci.RefreshTimes, "refresh-times", "", ci.RefreshTimes, "Refresh the modtime of remote files.")
|
||||
flags.BoolVarP(flagSet, &ci.NoConsole, "no-console", "", ci.NoConsole, "Hide console window. Supported on Windows only.")
|
||||
flags.StringVarP(flagSet, &dscp, "dscp", "", "", "Set DSCP value to connections. Can be value or names, eg. CS1, LE, DF, AF21.")
|
||||
}
|
||||
|
||||
// ParseHeaders converts the strings passed in via the header flags into HTTPOptions
|
||||
@ -254,6 +257,13 @@ func SetFlags(ci *fs.ConfigInfo) {
|
||||
if len(headers) != 0 {
|
||||
ci.Headers = ParseHeaders(headers)
|
||||
}
|
||||
if len(dscp) != 0 {
|
||||
if value, ok := parseDSCP(dscp); ok {
|
||||
ci.TrafficClass = value << 2
|
||||
} else {
|
||||
log.Fatalf("--dscp: Invalid DSCP name: %v", dscp)
|
||||
}
|
||||
}
|
||||
|
||||
// Make the config file absolute
|
||||
configPath, err := filepath.Abs(config.ConfigPath)
|
||||
@ -266,3 +276,61 @@ func SetFlags(ci *fs.ConfigInfo) {
|
||||
ci.MultiThreadSet = multiThreadStreamsFlag != nil && multiThreadStreamsFlag.Changed
|
||||
|
||||
}
|
||||
|
||||
// parseHeaders converts DSCP names to value
|
||||
func parseDSCP(dscp string) (uint8, bool) {
|
||||
if s, err := strconv.ParseUint(dscp, 10, 6); err == nil {
|
||||
return uint8(s), true
|
||||
}
|
||||
dscp = strings.ToUpper(dscp)
|
||||
switch dscp {
|
||||
case "BE":
|
||||
fallthrough
|
||||
case "DF":
|
||||
fallthrough
|
||||
case "CS0":
|
||||
return 0x00, true
|
||||
case "CS1":
|
||||
return 0x08, true
|
||||
case "AF11":
|
||||
return 0x0A, true
|
||||
case "AF12":
|
||||
return 0x0C, true
|
||||
case "AF13":
|
||||
return 0x0E, true
|
||||
case "CS2":
|
||||
return 0x10, true
|
||||
case "AF21":
|
||||
return 0x12, true
|
||||
case "AF22":
|
||||
return 0x14, true
|
||||
case "AF23":
|
||||
return 0x16, true
|
||||
case "CS3":
|
||||
return 0x18, true
|
||||
case "AF31":
|
||||
return 0x1A, true
|
||||
case "AF32":
|
||||
return 0x1C, true
|
||||
case "AF33":
|
||||
return 0x1E, true
|
||||
case "CS4":
|
||||
return 0x20, true
|
||||
case "AF41":
|
||||
return 0x22, true
|
||||
case "AF42":
|
||||
return 0x24, true
|
||||
case "AF43":
|
||||
return 0x26, true
|
||||
case "CS5":
|
||||
return 0x28, true
|
||||
case "EF":
|
||||
return 0x2E, true
|
||||
case "CS6":
|
||||
return 0x30, true
|
||||
case "LE":
|
||||
return 0x01, true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user