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 4abe36f136f908551e2f44eba6c6982926722c88
parent 2f9aae3d512c54281c266c9dd0f9f5d0dd166e38
Author: dsp <dsp@2f30.org>
Date:   Thu, 12 Feb 2015 13:57:45 -0700

exporting fsar.Conf, now fsarconf keeps a pointer to the whole archive. Also implemented SetTimeDelta on the archive to be able to specify different durations

Diffstat:
Marchive/archive.go | 30+++++++++++++++++-------------
Mcmd/archive_server.go | 3+++
2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/archive/archive.go b/archive/archive.go @@ -92,7 +92,7 @@ type fsarchive struct { scanch chan struct{} timedelta time.Duration descriminator string - conf *fsarconf + Conf *fsarconf //present tha archive as a restful resource PutNotAllowed PostNotAllowed @@ -100,13 +100,13 @@ type fsarchive struct { } type fsarconf struct { - arfiles *timeentryslice + ar *fsarchive PutNotAllowed PostNotAllowed DeleteNotAllowed } -//in order not to block in gets, we need to +//in order not to block in the following GETs, we need to //fire a new goroutine to send the reply on the channel // the reason is that we create the channel here and we must //return it to the responsewriter and any sends would block @@ -115,14 +115,14 @@ func (fsc *fsarconf) Get(values url.Values) (int, chan reply) { retc := make(chan reply) go func() { defer close(retc) //must close the chan to let the listener finish. - if fsc.arfiles == nil { - log.Printf("nil arfile in fsarconf. ignoring request\n") + if fsc.ar == nil { + log.Printf("nil archive in fsarconf. ignoring request\n") return } if _, ok := values["range"]; ok { - if len(*fsc.arfiles) > 0 { - f := *fsc.arfiles - dates := fmt.Sprintf("%s - %s\n", f[0].sdate, f[len(f)-1].sdate) + if len(*fsc.ar.entryfiles) > 0 { + f := *fsc.ar.entryfiles + dates := fmt.Sprintf("[From:%s - To:%s . Delta:%s]\n", f[0].sdate, f[len(f)-1].sdate, fsc.ar.timedelta) retc <- reply{data: []byte(dates), err: nil} return } @@ -130,8 +130,8 @@ func (fsc *fsarconf) Get(values url.Values) (int, chan reply) { return } if _, ok := values["files"]; ok { - for _, f := range *fsc.arfiles { - retc <- reply{data: []byte(fmt.Sprintf("%s\n", filepath.Base(f.path))), err: nil} + for _, f := range *fsc.ar.entryfiles { + retc <- reply{data: []byte(fmt.Sprintf("[Filename:%s .Type:%s]\n", filepath.Base(f.path), ftypestrings[f.ftype])), err: nil} } return } @@ -307,6 +307,10 @@ func (fsa *fsarchive) visit(path string,f os.FileInfo, err error) error { return nil } +func (fsa *fsarchive) SetDelta(a time.Duration) { + fsa.timedelta = a +} + func NewFsArchive(path, descr string) *fsarchive { return &fsarchive{ rootpathstr: path, @@ -321,7 +325,7 @@ func NewFsArchive(path, descr string) *fsarchive { scanch: make(chan struct{}), timedelta: 15 * time.Minute, descriminator: descr, - conf: &fsarconf{}, + Conf: &fsarconf{}, } } @@ -418,8 +422,8 @@ func (fsa *fsarchive) Serve(wg *sync.WaitGroup, ar archive) (reqchan chan<- stri fsa.entryfiles = &fsa.tempentryfiles fsa.scanning = false //let the config know - log.Printf("setting conf arfiles from :%v to a slice of len: %v\n", fsa.conf.arfiles, len(*fsa.entryfiles)) - fsa.conf.arfiles = fsa.entryfiles + log.Printf("setting archive conf from :%v to a slice of len: %v\n", fsa.Conf.ar, len(*fsa.entryfiles)) + fsa.Conf.ar = fsa log.Print("fsarchive: scan finished") } } diff --git a/cmd/archive_server.go b/cmd/archive_server.go @@ -5,6 +5,7 @@ import ( "log" "os" "sync" + "time" ) func main() { @@ -13,12 +14,14 @@ func main() { } basedirstr := os.Args[1] ribmrtar := ar.NewFsArchive(basedirstr, "RIBS") + ribmrtar.SetDelta(time.Hour*2) wg1 := &sync.WaitGroup{} mrtreqc := ribmrtar.Serve(wg1, ribmrtar) mrtreqc <- "SCAN" ribmrtar.Scanwg.Wait() api := new(ar.API) api.AddResource(ribmrtar, "/archive/ribs") + api.AddResource(ribmrtar.Conf, "/archive/ribs/conf") api.Start(3000) close(mrtreqc) wg1.Wait()