From a460c45d2e12deb1b61fc94de7eca999b68bc22a Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 1 Aug 2011 13:59:02 +0200 Subject: [PATCH] just use println --- _examples/funkensturm/config_delay.go | 30 +++++++++++------------ _examples/funkensturm/config_rproxy.go | 4 ++-- _examples/funkensturm/funkensturm.go | 33 +++++++++----------------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/_examples/funkensturm/config_delay.go b/_examples/funkensturm/config_delay.go index 50f6d99d..4acb3193 100644 --- a/_examples/funkensturm/config_delay.go +++ b/_examples/funkensturm/config_delay.go @@ -33,29 +33,27 @@ func delay(m *dns.Msg) (buf []byte) { ok1 bool o *dns.Msg ) - if previous, ok1 = checkDelay(); !ok1 { - println("Info: Dropping: too often") - time.Sleep(NSECDELAY) - return - } - println("Info: Ok: let it through") - for _, c := range qr { - o = c.Client.Exchange(m, c.Addr) - } - buf, _ = o.Pack() - return + if previous, ok1 = checkDelay(); !ok1 { + println("Dropping: too often") + time.Sleep(NSECDELAY) + return + } + println("Ok: let it through") + for _, c := range qr { + o = c.Client.Exchange(m, c.Addr) + } + buf, _ = o.Pack() + return } // Return the configration func NewFunkenSturm() *FunkenSturm { f := new(FunkenSturm) - f.Funk = make([]*Funk, 1) - // Not concurrent save f.Setup = func() bool { previous = time.Nanoseconds(); return true } - f.Funk[0] = NewFunk(1) - f.Funk[0].Matches[0].Op = AND - f.Funk[0].Matches[0].Func = match + f.Funk = make([]*Funk, 1) + f.Funk[0] = NewFunk() + f.Funk[0].Match = match f.Funk[0].Action = delay return f } diff --git a/_examples/funkensturm/config_rproxy.go b/_examples/funkensturm/config_rproxy.go index dbf9e12c..6860b95f 100644 --- a/_examples/funkensturm/config_rproxy.go +++ b/_examples/funkensturm/config_rproxy.go @@ -91,8 +91,8 @@ func NewFunkenSturm() *FunkenSturm { f := new(FunkenSturm) f.Funk = make([]*Funk, 1) f.Setup = func() bool { cache = NewCache(); return true } - f.Funk[0] = NewFunk(1) - f.Funk[0].Matches[0].Func = func(m *dns.Msg) (*dns.Msg, bool) { return m, true } + f.Funk[0] = NewFunk() + f.Funk[0].Match = func(m *dns.Msg) (*dns.Msg, bool) { return m, true } f.Funk[0].Action = checkcache return f } diff --git a/_examples/funkensturm/funkensturm.go b/_examples/funkensturm/funkensturm.go index b29a8ef0..5a98edf6 100644 --- a/_examples/funkensturm/funkensturm.go +++ b/_examples/funkensturm/funkensturm.go @@ -10,7 +10,6 @@ import ( "os" "log" "flag" - "fmt" "dns" "os/signal" "strings" @@ -32,8 +31,8 @@ type FunkClient struct { // the matches are successfull (return true) the action is // performed type Funk struct { - Match func(*dns.Msg) (*dns.Msg, bool) - Action func(*dns.Msg) []byte + Match func(*dns.Msg) (*dns.Msg, bool) + Action func(*dns.Msg) []byte } func NewFunk() *Funk { @@ -41,20 +40,11 @@ func NewFunk() *Funk { return f } -// A complete config for Funkensturm. All matches in the Matches slice are -// chained together: incoming dns.Msg -> Match[0] -> dns.Msg -> Match[1] -> dns.Msg -> ... -// The dns.Msg output of Match[n] is the input for Match[n+1]. -// -// The final outcome (does a packet match or not?) is calculated as follows: -// true Match[0].Op Match[0].Func() Match[1].Op Match[1].Func() ... -// The result of this matching is given to the action function. That last -// function decides "what to do with the packet" is the match(es) return 'true' -// There is no NewFunkenSturm() because that is what needs to be done in the -// configuration file. +// Hold the information. type FunkenSturm struct { - Setup func() bool // Inital setup (for extra resolvers, or loading keys, or ...) - Default func(*dns.Msg) []byte // Default action is all fails - Funk []*Funk // The configuration + Setup func() bool // Inital setup (for extra resolvers, or loading keys, or ...) + Default func(*dns.Msg) []byte // Default action is all fails + Funk []*Funk // The configuration } func doFunkenSturm(pkt *dns.Msg) (ret []byte) { @@ -66,12 +56,12 @@ func doFunkenSturm(pkt *dns.Msg) (ret []byte) { // Loop through the Funks and decide what to do with // the packet. for _, f := range f.Funk { - if m, ok := f.Match(pkt); ok { + if m, ok := f.Match(pkt); ok { ret = f.Action(m) return } } - ret = f.Default(pkt) + ret = f.Default(pkt) return } @@ -83,7 +73,7 @@ func serve(w dns.ResponseWriter, req *dns.Msg) { func listenAndServe(add, net string) { if err := dns.ListenAndServe(add, net, nil); err != nil { - fmt.Printf("Failed to setup: " + net + " " + add + "\n") + println("Failed to setup: ", net, " ", add) } } @@ -93,7 +83,6 @@ func main() { cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file") verbose = flag.Bool("verbose", false, "Print packet as it flows through") flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: %s\n", os.Args[0]) flag.PrintDefaults() } flag.Parse() @@ -117,7 +106,7 @@ func main() { f = NewFunkenSturm() ok := f.Setup() if !ok { - fmt.Fprintf(os.Stderr, "Setup failed") + println("Setup failed") return } @@ -129,7 +118,7 @@ forever: for { select { case <-signal.Incoming: - fmt.Printf("Signal received, stopping\n") + println("Signal received, stopping") break forever } }