plugins/meta/bandwith: traffic shaping plugin

Add chained plugin to add a tbf qdisc to shape ingress/egress traffic
This commit is contained in:
DennisDenuto
2018-01-07 19:15:17 -08:00
committed by Gabriel Rosenhouse
parent 372bb5e826
commit b78e535055
8 changed files with 1236 additions and 5 deletions

View File

@ -7,8 +7,13 @@
package main
import (
"bufio"
"fmt"
"io"
"net"
"os"
"strings"
"time"
)
func main() {
@ -31,8 +36,22 @@ func main() {
}
func handleConnection(conn net.Conn) {
buf := make([]byte, 512)
nBytesRead, _ := conn.Read(buf)
conn.Write(buf[0:nBytesRead])
conn.Close()
conn.SetReadDeadline(time.Now().Add(1 * time.Minute))
content, err := bufio.NewReader(conn).ReadString('\n')
if err != nil && err != io.EOF {
fmt.Fprint(os.Stderr, err.Error())
return
}
conn.SetWriteDeadline(time.Now().Add(1 * time.Minute))
if _, err = conn.Write([]byte(strings.TrimSuffix(content, "\n"))); err != nil {
fmt.Fprint(os.Stderr, err.Error())
return
}
if err = conn.Close(); err != nil {
fmt.Fprint(os.Stderr, err.Error())
return
}
}