diff --git a/CTng/ctng.go b/CTng/ctng.go index e7e8eb3..c9af215 100644 --- a/CTng/ctng.go +++ b/CTng/ctng.go @@ -5,6 +5,7 @@ import ( "CTng/gossip" "CTng/monitor" "CTng/server" + "CTng/testData/fakeCA" fakeLogger "CTng/testData/fakeLogger" "fmt" "os" @@ -51,13 +52,14 @@ func main() { Config: &conf, Storage: storage, StorageFile: "monitor_data.json", + HasPom: make(map[string]bool), } ctx.Config = &conf server.StartMonitorServer(&ctx) case "logger": fakeLogger.RunLogger(os.Args[2]) case "ca": - // fakeCA.runCA(os.Args[2]) + fakeCA.RunCA(os.Args[2]) default: fmt.Println(helpText) } diff --git a/CTng/gossip/gossiper.go b/CTng/gossip/gossiper.go index bd0ac9e..2823408 100644 --- a/CTng/gossip/gossiper.go +++ b/CTng/gossip/gossiper.go @@ -38,9 +38,9 @@ func GossipData(c *GossiperContext, gossip_obj Gossip_object) error { // Send the gossip object to all connected gossipers. for _, url := range c.Config.Connected_Gossipers { - if c.HasPom[url] { - continue - } + // if c.HasPom[url] { + // continue + // } // HTTP POST the data to the url or IP address. resp, err := c.Client.Post("http://"+url+"/gossip/push-data", "application/json", bytes.NewBuffer(msg)) if err != nil { @@ -58,7 +58,9 @@ func GossipData(c *GossiperContext, gossip_obj Gossip_object) error { // Alernatively, we could return the response from this function. defer resp.Body.Close() // do something with the response? - fmt.Println("Gossiped to " + url + " and recieved " + resp.Status) + if c.Verbose { + fmt.Println("Gossiped to " + url + " and recieved " + resp.Status) + } } return nil } @@ -78,7 +80,9 @@ func SendToOwner(c *GossiperContext, obj Gossip_object) { // Close the response, mentioned by http.Post // Alernatively, we could return the response from this function. defer resp.Body.Close() - fmt.Println("Owner responded with " + resp.Status) + if c.Verbose { + fmt.Println("Owner responded with " + resp.Status) + } } // Handling errors from owner could go here. } diff --git a/CTng/gossip/process_object.go b/CTng/gossip/process_object.go index dc79776..cfb6d04 100644 --- a/CTng/gossip/process_object.go +++ b/CTng/gossip/process_object.go @@ -25,6 +25,7 @@ func ProcessValidObject(c *GossiperContext, obj Gossip_object) { SendToOwner(c, obj) err = GossipData(c, obj) case GOSSIP_POM: + c.HasPom[obj.Payload[0]] = true SendToOwner(c, obj) err = GossipData(c, obj) case REVOCATION_FRAG: @@ -33,6 +34,7 @@ func ProcessValidObject(c *GossiperContext, obj Gossip_object) { ProcessAccusation(c, obj) err = GossipData(c, obj) case APPLICATION_POM: + c.HasPom[obj.Payload[0]] = true SendToOwner(c, obj) err = GossipData(c, obj) default: @@ -47,8 +49,8 @@ func ProcessValidObject(c *GossiperContext, obj Gossip_object) { // If the signature/payload is identical, then we can safely ignore the duplicate. // Otherwise, we generate a PoM for two objects sent in the same period. func ProcessDuplicateObject(c *GossiperContext, obj Gossip_object, dup Gossip_object) error { - if obj.Signature == dup.Signature && - obj.Payload == dup.Payload { + if obj.Signature[0] == dup.Signature[0] && + obj.Payload[0] == dup.Payload[0] { return nil } else { // Generate PoM @@ -77,7 +79,7 @@ func ProcessInvalidObject(obj Gossip_object, e error) { func ProcessAccusation(c *GossiperContext, acc Gossip_object) { pom, shouldGossip, err := Process_Accusation(acc, c.Accusations, c.Config.Crypto) - if err != nil { + if err != nil && shouldGossip { fmt.Println(util.RED+err.Error(), util.RESET) } else { fmt.Println(util.YELLOW+"Processed accusation against", acc.Payload[0], util.RESET) diff --git a/CTng/gossip/types.go b/CTng/gossip/types.go index b2a6647..6ce5a0d 100644 --- a/CTng/gossip/types.go +++ b/CTng/gossip/types.go @@ -30,6 +30,33 @@ const ( APPLICATION_POM = "http://ctng.uconn.edu/304" ) +func TypeString(t string) string { + switch t { + case GOSSIP_POM: + return "GOSSIP_POM" + case STH: + return "STH" + case REVOCATION: + return "REVOCATION" + case STH_FRAG: + return "STH_FRAG" + case REVOCATION_FRAG: + return "REVOCATION_FRAG" + case ACCUSATION_FRAG: + return "ACCUSATION_FRAG" + case STH_FULL: + return "STH_FULL" + case REVOCATION_FULL: + return "REVOCATION_FULL" + case ACCUSATION_POM: + return "ACCUSATION_POM" + case APPLICATION_POM: + return "APPLICATION_POM" + default: + return "UNKNOWN" + } +} + // Types of errors that can occur when parsing a Gossip_object const ( No_Sig_Match = "Signatures don't match" @@ -83,8 +110,9 @@ type GossiperContext struct { StorageFile string // Where storage can be stored. // Client: used for HTTP connections, allows for timeouts // and more control over the connections we make. - Client *http.Client - HasPom map[string]bool + Client *http.Client + HasPom map[string]bool + Verbose bool } // Saves the Storage object to the value in c.StorageFile. diff --git a/CTng/monitor/monitor.go b/CTng/monitor/monitor.go index 0f031ba..43fdc33 100644 --- a/CTng/monitor/monitor.go +++ b/CTng/monitor/monitor.go @@ -5,7 +5,6 @@ import ( "CTng/util" "bytes" "encoding/json" - "errors" "fmt" "io/ioutil" "log" @@ -27,7 +26,7 @@ func QueryLoggers(c *MonitorContext) { sthResp, err := http.Get(PROTOCOL + logger + "/ctng/v2/get-sth/") if err != nil { log.Println(err) - AccuseEntity(c, logger) + // AccuseEntity(c, logger) continue } @@ -36,13 +35,13 @@ func QueryLoggers(c *MonitorContext) { err = json.Unmarshal(sthBody, &STH) if err != nil { log.Println(util.RED+err.Error(), util.RESET) - AccuseEntity(c, logger) + // AccuseEntity(c, logger) continue } err = STH.Verify(c.Config.Crypto) if err != nil { log.Println(util.RED+"STH signature verification failed", err.Error(), util.RESET) - AccuseEntity(c, logger) + // AccuseEntity(c, logger) } else { Process_valid_object(c, STH) } @@ -134,20 +133,15 @@ func Send_to_gossiper(c *MonitorContext, g gossip.Gossip_object) { // Close the response, mentioned by http.Post // Alernatively, we could return the response from this function. defer resp.Body.Close() - fmt.Println(util.BLUE+"Sent Object to Gossiper, Recieved "+resp.Status, util.RESET) + fmt.Println(util.BLUE+"Sent", gossip.TypeString(g.Type), "to Gossiper, Recieved "+resp.Status, util.RESET) } } //this function takes the name of the entity as input and check if there is a POM against it //this should be invoked after the monitor receives the information from its loggers and CAs prior to threshold signning it -func Check_entity_pom(c *MonitorContext, name string) error { - for _, v := range *c.Storage { - if v.Payload[0] == name && (v.Type == gossip.ACCUSATION_POM || v.Type == gossip.APPLICATION_POM || v.Type == gossip.GOSSIP_POM) { - return errors.New("There exists a proof of misbehavior against this entity") - } - } - return nil +func Check_entity_pom(c *MonitorContext, name string) bool { + return c.HasPom[name] } func IsLogger(c *MonitorContext, loggerURL string) bool { diff --git a/CTng/monitor/monitor_process.go b/CTng/monitor/monitor_process.go index 947f021..a591b1a 100644 --- a/CTng/monitor/monitor_process.go +++ b/CTng/monitor/monitor_process.go @@ -2,6 +2,7 @@ package monitor import ( "CTng/gossip" + "CTng/util" "fmt" "time" ) @@ -13,13 +14,14 @@ func Process_valid_object(c *MonitorContext, g gossip.Gossip_object) { if IsLogger(c, g.Signer) && g.Type == gossip.STH { Send_to_gossiper(c, g) f := func() { + fmt.Println(util.BLUE, "Signing Revocation of", g.Signer, util.RESET) sig_frag, err := c.Config.Crypto.ThresholdSign(g.Payload[0]) if err != nil { fmt.Println(err.Error()) } pom_err := Check_entity_pom(c, g.Signer) //if there is no conflicting information/PoM send the Threshold signed version to the gossiper - if pom_err == nil { + if pom_err == false { g.Type = gossip.STH_FRAG g.Signature[0] = sig_frag.String() g.Signer = c.Config.Crypto.SelfID.String() @@ -39,8 +41,9 @@ func Process_valid_object(c *MonitorContext, g gossip.Gossip_object) { } Send_to_gossiper(c, g) f := func() { + fmt.Println(util.BLUE, "Signing Revocation of", g.Signer, util.RESET) pom_err := Check_entity_pom(c, g.Signer) - if pom_err == nil { + if pom_err == false { g.Type = gossip.REVOCATION_FRAG g.Signature[0] = sig_frag.String() g.Signer = c.Config.Crypto.SelfID.String() @@ -48,13 +51,18 @@ func Process_valid_object(c *MonitorContext, g gossip.Gossip_object) { } } - time.AfterFunc(time.Duration(c.Config.Public.Gossip_wait_time), f) + time.AfterFunc(time.Duration(c.Config.Public.Gossip_wait_time)*time.Second, f) return + } - //if the object is from its own gossiper - // Note didn't implement the directory separation here*************************************************************** - if g.Type == gossip.ACCUSATION_POM || g.Type == gossip.GOSSIP_POM || g.Type == gossip.APPLICATION_POM || g.Type == gossip.REVOCATION_FULL || g.Type == gossip.STH_FULL { + if g.Type == gossip.ACCUSATION_POM || g.Type == gossip.GOSSIP_POM || g.Type == gossip.APPLICATION_POM { + fmt.Println("Processing POM") + c.HasPom[g.Payload[0]] = true c.StoreObject(g) return } + //if the object is from its own gossiper + // Note didn't implement the directory separation here*************************************************************** + c.StoreObject(g) + return } diff --git a/CTng/monitor/types.go b/CTng/monitor/types.go index 1ff4716..27100d0 100644 --- a/CTng/monitor/types.go +++ b/CTng/monitor/types.go @@ -19,7 +19,9 @@ type MonitorContext struct { // The below could be used to prevent a Monitor from sending duplicate Accusations, // Currently, if a monitor accuses two entities in the same Period, it will trigger a gossip PoM. // Therefore, a monitor can only accuse once per Period. I believe this is a temporary solution. + HasPom map[string]bool HasAccused bool + Verbose bool Client *http.Client } diff --git a/CTng/server/Gossiper_server.go b/CTng/server/Gossiper_server.go index cc000d2..7b385bd 100644 --- a/CTng/server/Gossiper_server.go +++ b/CTng/server/Gossiper_server.go @@ -131,7 +131,9 @@ func handleGossip(c *gossip.GossiperContext, w http.ResponseWriter, r *http.Requ stored_obj, found := c.GetObject(gossip_obj.GetID(c.Config.Public.Period_interval)) if found { // If the object is already stored, still return OK.{ - fmt.Println("Duplicate:", gossip_obj.Type, getSenderURL(r)+".") + if c.Verbose { + fmt.Println("Ignoring Duplicate ", gossip_obj.Type) + } err := gossip.ProcessDuplicateObject(c, gossip_obj, stored_obj) if err != nil { http.Error(w, err.Error(), http.StatusOK) @@ -139,7 +141,7 @@ func handleGossip(c *gossip.GossiperContext, w http.ResponseWriter, r *http.Requ http.Error(w, "Recieved Duplicate Object.", http.StatusOK) return } else { - fmt.Println(util.GREEN+"Recieved new, valid", gossip_obj.Type, "from "+getSenderURL(r)+".", util.RESET) + fmt.Println(util.GREEN+"Recieved new, valid", gossip.TypeString(gossip_obj.Type), "from "+getSenderURL(r)+".", util.RESET) gossip.ProcessValidObject(c, gossip_obj) c.SaveStorage() } @@ -179,12 +181,12 @@ func handleOwnerGossip(c *gossip.GossiperContext, w http.ResponseWriter, r *http if err != nil { http.Error(w, "Duplicate Object recieved!", http.StatusOK) } else { - http.Error(w, err.Error(), http.StatusOK) + http.Error(w, "", http.StatusOK) } return } else { // Prints the body of the post request to the server console - fmt.Println(util.GREEN+"Recieved new, valid", gossip_obj.Type, "from owner.", util.RESET) + fmt.Println(util.GREEN+"Recieved new, valid", gossip.TypeString(gossip_obj.Type), "from owner.", util.RESET) gossip.ProcessValidObject(c, gossip_obj) c.SaveStorage() } diff --git a/CTng/server/Monitor_server.go b/CTng/server/Monitor_server.go index 91ee0a6..1cdc256 100644 --- a/CTng/server/Monitor_server.go +++ b/CTng/server/Monitor_server.go @@ -157,7 +157,7 @@ func handle_gossip(c *monitor.MonitorContext, w http.ResponseWriter, r *http.Req // processDuplicateObject(c, gossip_obj, stored_obj) return } else { - fmt.Println("Recieved new, valid", gossip_obj.Type, "from "+getSenderURL(r)+".") + fmt.Println("Recieved new, valid", gossip.TypeString(gossip_obj.Type), "from "+getSenderURL(r)+".") monitor.Process_valid_object(c, gossip_obj) c.SaveStorage() }