Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zealws committed May 23, 2016
1 parent b4acb24 commit f69fd6b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/daemon/atcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion utils/test-cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

if [ "$(whoami)" != "root" ] ; then
sudo "$0"
Expand Down
2 changes: 1 addition & 1 deletion utils/test-setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

if [ "$(whoami)" != "root" ] ; then
sudo "$0"
Expand Down
20 changes: 20 additions & 0 deletions utils/test-status.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f69fd6b

Please sign in to comment.