Skip to content

Commit

Permalink
Timemap removed, afterfunc implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
jik18001 committed Apr 19, 2022
1 parent 988d8b8 commit 12b1a90
Showing 1 changed file with 24 additions and 42 deletions.
66 changes: 24 additions & 42 deletions CTng/server/Monitor_ng.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"time"
)

const PROTOCOL = "http://"

//Accused = Domain name of the accused entity (logger etc.)
//should be a monitor functionality
func Monitor_accuseEntity(c *crypto.CryptoConfig, Accused string) (gossip.Gossip_object, error) {
Expand Down Expand Up @@ -39,7 +41,6 @@ func Monitor_accuseEntity(c *crypto.CryptoConfig, Accused string) (gossip.Gossip
return accusation, nil
}

//just reused Finn's code for sending gossip object, changed owner URL to Gossiper URL
func Monitor_send_to_gossiper(c *monitor.MonitorContext, g gossip.Gossip_object) {
// Convert gossip object to JSON
msg, err := json.Marshal(g)
Expand Down Expand Up @@ -69,17 +70,19 @@ func Monitor_process_valid_object(c *monitor.MonitorContext, g gossip.Gossip_obj
if err != nil {
fmt.Printf(err.Error())
}
c.Timer_Loggers.m[v] = time.Now().Unix()
Monitor_send_to_gossiper(c, g)
time.After(time.Duration(c.Config.Public.Gossip_wait_time))
pom_err := Monitor_check_entity_pom(c, v)
//if there is no conflicting information/PoM send the Threshold signed version to the gossiper
if pom_err == nil {
g.Type = gossip.STH_FRAG
g.Signature[0] = sig_frag.String()
g.Signer = c.Config.Crypto.SelfID.String()
Monitor_send_to_gossiper(c, g)
f := func() {
pom_err := Monitor_check_entity_pom(c, v)
//if there is no conflicting information/PoM send the Threshold signed version to the gossiper
if pom_err == nil {
g.Type = gossip.STH_FRAG
g.Signature[0] = sig_frag.String()
g.Signer = c.Config.Crypto.SelfID.String()
Monitor_send_to_gossiper(c, g)
}

}
time.AfterFunc(time.Duration(c.Config.Public.Gossip_wait_time), f)
return
}
}
Expand All @@ -91,16 +94,18 @@ func Monitor_process_valid_object(c *monitor.MonitorContext, g gossip.Gossip_obj
if err != nil {
fmt.Printf(err.Error())
}
c.Timer_CAs.m[v] = time.Now().Unix()
Monitor_send_to_gossiper(c, g)
time.After(time.Duration(c.Config.Public.Gossip_wait_time))
pom_err := Monitor_check_entity_pom(c, v)
if pom_err == nil {
g.Type = gossip.REVOCATION_FRAG
g.Signature[0] = sig_frag.String()
g.Signer = c.Config.Crypto.SelfID.String()
Monitor_send_to_gossiper(c, g)
f := func() {
pom_err := Monitor_check_entity_pom(c, v)
if pom_err == nil {
g.Type = gossip.REVOCATION_FRAG
g.Signature[0] = sig_frag.String()
g.Signer = c.Config.Crypto.SelfID.String()
Monitor_send_to_gossiper(c, g)
}

}
time.AfterFunc(time.Duration(c.Config.Public.Gossip_wait_time), f)
return
}
}
Expand Down Expand Up @@ -140,29 +145,6 @@ func Monitor_handle_gossip(c *monitor.MonitorContext, w http.ResponseWriter, r *
http.Error(w, err.Error(), http.StatusOK)
return
}
//detect inactivity of CAs and loggers
if time.Now().Unix()-c.Timer_CAs_LastCheckIn >= int64(c.Config.Public.MRD) {
for key, element := range c.Timer_CAs.m {
//CA didn't give update in this MRD, accuse as inactive
if time.Now().Unix() > element+int64(c.Config.Public.MRD) {
fmt.Println("This CA is inactive: " + key + ".")
obj, err := Monitor_accuseEntity(c.Config.Crypto, key)
Monitor_send_to_gossiper(c, obj)
http.Error(w, err.Error(), http.StatusOK)
}
}
c.Timer_CAs_LastCheckIn = time.Now().Unix()
for key, element := range c.Timer_Loggers.m {
//Logger didn't give update in this MMD, accuse as inactive
if time.Now().Unix() > element+int64(c.Config.Public.MMD) {
fmt.Println("This Logger is inactive: " + key + ".")
obj, err := Monitor_accuseEntity(c.Config.Crypto, key)
Monitor_send_to_gossiper(c, obj)
http.Error(w, err.Error(), http.StatusOK)
}
}
c.Timer_Loggers_LastCheckIn = time.Now().Unix()
}
// Check for duplicate object.
_, found := c.GetObject(gossip_obj.GetID(int64(c.Config.Public.Gossip_wait_time)))
if found {
Expand All @@ -172,7 +154,7 @@ func Monitor_handle_gossip(c *monitor.MonitorContext, w http.ResponseWriter, r *
// processDuplicateObject(c, gossip_obj, stored_obj)
return
} else {
fmt.Println(GREEN+"Recieved new, valid", gossip_obj.Type, "from "+getSenderURL(r)+".", RESET)
fmt.Println("Recieved new, valid", gossip_obj.Type, "from "+getSenderURL(r)+".")
Monitor_process_valid_object(c, gossip_obj)
c.SaveStorage()
}
Expand Down

0 comments on commit 12b1a90

Please sign in to comment.