-
Notifications
You must be signed in to change notification settings - Fork 2
/
client-update-monitor.go
56 lines (51 loc) · 1.4 KB
/
client-update-monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package monitor
import (
"encoding/json"
"fmt"
"net/http"
"github.com/jik18001/CTngV2/definition"
"github.com/jik18001/CTngV2/util"
//"CTng/crypto"
//"bytes"
//"time"
//"strings"
//"strconv"
//"github.com/gorilla/mux"
)
type ClientUpdate struct {
STHs []definition.Gossip_object
REVs []definition.Gossip_object
POM_CONs []definition.Gossip_object
POM_ACCs []definition.Gossip_object
MonitorID string
//Period here means the update period, the client udpate object can contain more information than just the period
Period string
// PoMsig string
}
func PrepareClientUpdate(context *MonitorContext, filepath string) (*ClientUpdate, error) {
var clientupdate ClientUpdate
// read from filepath
bytes, err := util.ReadByte(filepath)
if err != nil {
return nil, err
}
err = json.Unmarshal(bytes, &clientupdate)
if err != nil {
return nil, err
}
return &clientupdate, nil
}
func requestupdate(c *MonitorContext, w http.ResponseWriter, r *http.Request) {
var periodnum string
err := json.NewDecoder(r.Body).Decode(&periodnum)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
//get the file path
filepath := c.StorageDirectory + "/Period_" + periodnum + "/ClientUpdate.json"
ctupdate, _ := PrepareClientUpdate(c, filepath)
fmt.Println(ctupdate.Period)
msg, _ := json.Marshal(ctupdate)
json.NewEncoder(w).Encode(msg)
fmt.Println("Update request Processed")
}