change tc instead of replacing it
This commit is contained in:
16
main.go
16
main.go
@@ -12,7 +12,6 @@ import (
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
@@ -29,7 +28,6 @@ type Conf struct {
|
||||
ConformationPPP int `yaml:"conformation_ppp"`
|
||||
LogLevel string `yaml:"log_level"`
|
||||
UploadInterface string `yaml:"upload_interface"`
|
||||
CakeOptions string `yaml:"cake_options"`
|
||||
ThrottlePingThreshold int64 `yaml:"throttle_ping_threshold"`
|
||||
TryRestoringAfter int `yaml:"try_restoring_after"`
|
||||
}
|
||||
@@ -62,10 +60,7 @@ func (m UploadManager) Upload() (int, error) {
|
||||
}
|
||||
|
||||
func (m UploadManager) SetUpload(upload int) (int, error) {
|
||||
m.clearTC()
|
||||
args := []string{"qdisc", "add", "dev", conf.UploadInterface, "root", "cake", "bandwidth", fmt.Sprintf("%dMbit", upload)}
|
||||
args = append(args, strings.Split(conf.CakeOptions, " ")...)
|
||||
tcCmd := exec.Command("tc", args...)
|
||||
tcCmd := exec.Command("tc", "qdisc", "change", "dev", conf.UploadInterface, "root", "cake", "bandwidth", fmt.Sprintf("%dMbit", upload))
|
||||
log.Debugf("[TC] exec %s", tcCmd.String())
|
||||
out, err := tcCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
@@ -75,15 +70,6 @@ func (m UploadManager) SetUpload(upload int) (int, error) {
|
||||
return upload, nil
|
||||
}
|
||||
|
||||
func (m UploadManager) clearTC() {
|
||||
tcCmd := exec.Command("tc", "qdisc", "del", "dev", conf.UploadInterface, "root")
|
||||
log.Debugf("[TC] exec %s", tcCmd.String())
|
||||
out, err := tcCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Debugf("[TC] executing %s failed with: %v (%s)", tcCmd.String(), err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func doPing(host string, count int, interval time.Duration) (*ping.Statistics, error) {
|
||||
log.Debugf("[PING] starting to ping %s with %d packages", host, count)
|
||||
pinger, err := ping.NewPinger(host)
|
||||
|
Reference in New Issue
Block a user