go-bgp

a collection of golang BGP tools to monitor, archive and serve
git clone git://git.2f30.org/go-bgp
Log | Files | Refs | README

commit 45d38afd3229304a1d6893ed350bd33edb47f7ce
parent 42e2b4e39d199a002c2b34ef71282a0cc9f915ac
Author: dsp <dsp@2f30.org>
Date:   Mon, 16 Feb 2015 22:24:01 -0700

removal of commented code and gofmt

Diffstat:
Marchive/api.go | 6+++---
Marchive/archive.go | 96+++++++++++++++++++++++--------------------------------------------------------
Mcmd/archive_server.go | 2+-
3 files changed, 32 insertions(+), 72 deletions(-)

diff --git a/archive/api.go b/archive/api.go @@ -1,11 +1,11 @@ package archive import ( - "net/http" - "net/url" "errors" "fmt" "log" + "net/http" + "net/url" ) const ( @@ -20,7 +20,7 @@ var ( errbaddate = errors.New("dates should be in a YYYYMMDDHHMM format and start should be earlier than end") errempty = errors.New("archive empty") errdate = errors.New("no such date in archive") - errbadtype = errors.New(fmt.Sprintf("Supported file types:%v",ftypestrings[1:ftypesize-1])) + errbadtype = errors.New(fmt.Sprintf("Supported file types:%v", ftypestrings[1:ftypesize-1])) ) type Resource interface { diff --git a/archive/archive.go b/archive/archive.go @@ -6,10 +6,11 @@ import ( //"io/ioutil" //"bytes" "bufio" - "errors" "compress/bzip2" + "errors" mrt "go-bgp/mrt" "io" + "net/url" "os" "path/filepath" "sort" @@ -18,10 +19,9 @@ import ( "sync" "time" "unicode" - "net/url" ) -//constants for archentryfile.ftype +//constants for archentryfile.ftype const ( unknownfile = iota mrtfile @@ -30,14 +30,14 @@ const ( ) var ( - ftypestrings = [ftypesize]string { + ftypestrings = [ftypesize]string{ "UNKNOWN", "MRT", "XML", } - errbadft = errors.New("error: unknown file type") - errparsedate = errors.New("error: parsing date") - errbadscan = errors.New("bufio scanner failed") + errbadft = errors.New("error: unknown file type") + errparsedate = errors.New("error: parsing date") + errbadscan = errors.New("bufio scanner failed") ) type reply struct { @@ -54,11 +54,11 @@ type archive interface { } type queryParams struct { - from time.Time - to time.Time - rtype int - rch chan reply - wg *sync.WaitGroup + from time.Time + to time.Time + rtype int + rch chan reply + wg *sync.WaitGroup } type xmlstring struct { @@ -97,7 +97,7 @@ type fsarchive struct { rootpathstr string entryfiles *timeentryslice tempentryfiles timeentryslice //once we finish operating on that, we change the entryfiles pointer - curyr int //in case we need to walk dirs to find dates,these keep state + curyr int //in case we need to walk dirs to find dates,these keep state curmon int curday int reqchan chan string @@ -114,7 +114,7 @@ type fsarchive struct { } type fsarconf struct { - ar *fsarchive + ar *fsarchive PutNotAllowed PostNotAllowed DeleteNotAllowed @@ -156,13 +156,13 @@ func (fsc *fsarconf) Get(values url.Values) (int, chan reply) { func (fsa *fsarchive) Get(values url.Values) (int, chan reply) { var ( - grwg sync.WaitGroup - ftype int + grwg sync.WaitGroup + ftype int ) retc := make(chan reply) timeAstrs, ok1 := values["start"] timeBstrs, ok2 := values["end"] - tpstr, ok3 := values["type"] + tpstr, ok3 := values["type"] if len(timeAstrs) != len(timeBstrs) || !ok1 || !ok2 { retc <- reply{data: nil, err: errbadreq} goto done @@ -176,7 +176,7 @@ func (fsa *fsarchive) Get(values url.Values) (int, chan reply) { ftype = tpi break } - if tpi == ftypesize - 1 { //we didn't find it let the user know + if tpi == ftypesize-1 { //we didn't find it let the user know log.Printf("unknown return type %s in request", tpstr[0]) retc <- reply{data: nil, err: errbadtype} goto done @@ -219,8 +219,8 @@ func (fsar *fsarchive) Query(qp queryParams) { ef := *fsar.entryfiles var ( scanner *bufio.Scanner - date time.Time - err error + date time.Time + err error ) defer wg.Done() //case no files in archive @@ -248,7 +248,7 @@ func (fsar *fsarchive) Query(qp queryParams) { continue } ft := ef[k].ftype - scanner , err = getScanner(file, ft) + scanner, err = getScanner(file, ft) if err != nil { log.Println("failed acquiring bufio scanner on: ", ef[k].path, " ", err) continue @@ -272,46 +272,6 @@ func (fsar *fsarchive) Query(qp queryParams) { } else if date.After(tb) { break //XXX: this is correct only on ordered files (increasing dates) } - /* - - if ef[k].ftype == mrtfile { - data := scanner.Bytes() - hdr, errh := mrt.NewMrtHdr(data[:mrt.MrtHdr_size]) - if errh != nil { - log.Printf("error in creating MRT header:%s", errh) - rc <- reply{data: nil, err: errh} - continue - } - date := time.Unix(int64(hdr.Mrt_timestamp), 0) - log.Printf("scanned mrt with date:%s", date) - } else if ef[k].ftype == xmlfile { - str := scanner.Text() - dateindi := strings.Index(str, "<DATETIME>") - if dateindi == -1 { - log.Println("could not locate DATETIME string in xml msg: ", str) - continue - } - dateindi = dateindi + 10 // go to start of date data - dateindj := strings.Index(str[dateindi:], "</DATETIME>") - if dateindj == -1 { - log.Println("could not locate closing </DATETIME> string in xml msg: ", str) - continue - } - dateindj = dateindj + dateindi // to return it to the relative start of line pos - xmldate, derr := time.Parse(time.RFC3339, str[dateindi:dateindj]) - if derr != nil { - log.Println("could not parse datetime: %s\n", derr) - continue - } - //log.Printf("parse xml message date: %s\n", xmldate) - if xmldate.After(ta) && xmldate.Before(tb) { - //buf.WriteString(fmt.Sprintf("%s\n",str)) - rc <- reply{data: []byte(fmt.Sprintf("%s\n", str)), err: nil} - } else if xmldate.After(tb) { //only later measurements in this file. leaving - break - } - } - */ } if err := scanner.Err(); err != nil && err != io.EOF { log.Printf("file scanner error:%s\n", err) @@ -343,14 +303,14 @@ func getScanner(f *os.File, ft int) (scanner *bufio.Scanner, err error) { func getDate(data []byte, ftype int) (t time.Time, err error) { switch ftype { - case mrtfile : + case mrtfile: hdr, err := mrt.NewMrtHdr(data[:mrt.MrtHdr_size]) if err != nil { log.Printf("getDate: error in creating MRT header:%s", err) } else { t = time.Unix(int64(hdr.Mrt_timestamp), 0) } - case xmlfile : + case xmlfile: str := string(data) dateindi := strings.Index(str, "<DATETIME>") if dateindi == -1 { @@ -397,9 +357,9 @@ func getFirstDate(path string, ftype int) (date time.Time, err error) { return } -func (fsa *fsarchive) visit(path string,f os.FileInfo, err error) error { +func (fsa *fsarchive) visit(path string, f os.FileInfo, err error) error { var ( - ft int + ft int ) fname := f.Name() log.Print("examining: ", fname) @@ -411,12 +371,12 @@ func (fsa *fsarchive) visit(path string,f os.FileInfo, err error) error { numind := strings.IndexFunc(fname, unicode.IsDigit) extind := strings.LastIndex(fname, ".bz2") xmlind := strings.LastIndex(fname, ".xml") - if (extind == -1 && xmlind == -1) || numind == -1 { - log.Printf("file: %s not in foo.YYYYMMDD.HHMM.[xml].bz2... format. extind:%d numberind:%d xmlind:%d",fname, extind, numind, xmlind) + if (extind == -1 && xmlind == -1) || numind == -1 { + log.Printf("file: %s not in foo.YYYYMMDD.HHMM.[xml].bz2... format. extind:%d numberind:%d xmlind:%d", fname, extind, numind, xmlind) return nil } if extind-numind != 13 && xmlind-numind != 13 { - log.Printf("file: %s not in foo.YYYYMMDD.HHMM.[xml].bz2... format. extind:%d numberind:%d xmlind:%d",fname, extind, numind, xmlind) + log.Printf("file: %s not in foo.YYYYMMDD.HHMM.[xml].bz2... format. extind:%d numberind:%d xmlind:%d", fname, extind, numind, xmlind) return nil } if xmlind != -1 { diff --git a/cmd/archive_server.go b/cmd/archive_server.go @@ -14,7 +14,7 @@ func main() { } basedirstr := os.Args[1] ribmrtar := ar.NewFsArchive(basedirstr, "RIBS") - ribmrtar.SetDelta(time.Hour*2) + ribmrtar.SetDelta(time.Hour * 2) wg1 := &sync.WaitGroup{} mrtreqc := ribmrtar.Serve(wg1, ribmrtar) mrtreqc <- "SCAN"