diff --git a/src/daemon/atcd.go b/src/daemon/atcd.go index e2ddd6a..6089b01 100644 --- a/src/daemon/atcd.go +++ b/src/daemon/atcd.go @@ -3,6 +3,7 @@ package daemon import ( "fmt" "net" + "time" "github.com/facebook/augmented-traffic-control/src/atc_thrift" "github.com/facebook/augmented-traffic-control/src/iptables" @@ -69,11 +70,13 @@ func NewAtcd(db *DbRunner, shaper *ShapingEngine, options *AtcdOptions) atc_thri if options == nil { options = &DefaultAtcdOptions } - return &Atcd{ + d := &Atcd{ db: db, shaper: shaper, options: *options, } + go d.cleanupLoop() + return d } func (atcd *Atcd) GetAtcdInfo() (*atc_thrift.AtcdInfo, error) { @@ -250,8 +253,7 @@ func (atcd *Atcd) LeaveGroup(id int64, to_remove, token string) error { if err := atcd.shaper.LeaveGroup(id, tgt); err != nil { return err } - // FIXME: clean shaper's group too! - defer atcd.db.Cleanup() + defer atcd.Cleanup() return atcd.db.DeleteMember(tgt) } @@ -318,6 +320,19 @@ func (atcd *Atcd) otp(group *DbGroup) *otp.TOTP { } } +func (atcd *Atcd) cleanupLoop() { + for { + time.Sleep(5 * time.Second) + + atcd.Cleanup() + } +} + +func (atcd *Atcd) Cleanup() { + // Clean database + atcd.db.Cleanup() +} + func makeSecret() string { // Can probably find a better source of random secrets than this... return uuid.New() diff --git a/utils/test-cleanup.sh b/utils/test-cleanup.sh index a15aeae..ecc60e2 100755 --- a/utils/test-cleanup.sh +++ b/utils/test-cleanup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [ "$(whoami)" != "root" ] ; then sudo "$0" diff --git a/utils/test-setup.sh b/utils/test-setup.sh index 7a12cb2..cee1013 100755 --- a/utils/test-setup.sh +++ b/utils/test-setup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [ "$(whoami)" != "root" ] ; then sudo "$0" diff --git a/utils/test-status.sh b/utils/test-status.sh new file mode 100755 index 0000000..0fc0ac6 --- /dev/null +++ b/utils/test-status.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +if [ "$(whoami)" != "root" ] ; then + sudo "$0" + exit 0 +fi + +ip netns exec atc iptables -t mangle -nvL FORWARD + +echo + +ip netns exec atc tc qdisc list dev lan0 +ip netns exec atc tc filter list dev lan0 +ip netns exec atc tc class list dev lan0 + +echo + +ip netns exec atc tc qdisc list dev wan0 +ip netns exec atc tc filter list dev wan0 +ip netns exec atc tc class list dev wan0