// InfluxDB writes interest processing time to influxDB. // // The data collected can be viewed with: SELECT "value" FROM :name WHERE "name" = ':interest_name'. func InfluxDB(client influxdb.Client, db, name string, tags map[string]string) mux.Middleware { return func(next mux.Handler) mux.Handler { return mux.HandlerFunc(func(w ndn.Sender, i *ndn.Interest) { before := time.Now() next.ServeNDN(w, i) t := make(map[string]string) for k, v := range tags { t[k] = v } t["name"] = i.Name.String() pt, _ := influxdb.NewPoint(name, t, map[string]interface{}{ "value": float64(time.Since(before)) / float64(time.Millisecond), }, time.Now()) bp, _ := influxdb.NewBatchPoints(influxdb.BatchPointsConfig{ Database: db, }) bp.AddPoint(pt) err := client.Write(bp) if err != nil { log.Println(err) return } }) } }
func FileServer(from, to string) (string, mux.Handler) { return from, mux.HandlerFunc(func(w ndn.Sender, i *ndn.Interest) { //content, err := ioutil.ReadFile(to + filepath.Clean(strings.TrimPrefix(i.Name.String(), from))) //if err != nil { // return //} file, err := os.Open(to + filepath.Clean(strings.TrimPrefix(i.Name.String(), from))) if err != nil { return } fileInfo, _ := file.Stat() var fileSize int64 = fileInfo.Size() bytes := make([]byte, fileSize) buffer := bufio.NewReader(file) _, err = buffer.Read(bytes) w.SendData(&ndn.Data{ Name: i.Name, Content: bytes, }) }) }