From c33ed23761cd642178f3e7c59ac742230c67079a Mon Sep 17 00:00:00 2001 From: tfn18001 Date: Wed, 20 Apr 2022 15:29:42 -0400 Subject: [PATCH] Gossip Documentation --- CTng/gossip/Pom_Readme.md | 2 -- CTng/gossip/Readme.md | 16 ++++++++++++++++ CTng/gossip/accusations.go | 4 ++++ CTng/gossip/gossip_object.go | 35 +++++------------------------------ CTng/gossip/gossiper.go | 2 -- CTng/gossip/process_object.go | 7 ++++--- CTng/gossip/types.go | 6 +++++- 7 files changed, 34 insertions(+), 38 deletions(-) delete mode 100644 CTng/gossip/Pom_Readme.md create mode 100644 CTng/gossip/Readme.md diff --git a/CTng/gossip/Pom_Readme.md b/CTng/gossip/Pom_Readme.md deleted file mode 100644 index df957d6..0000000 --- a/CTng/gossip/Pom_Readme.md +++ /dev/null @@ -1,2 +0,0 @@ -This file mainly deals with Proof of Misbehavior generated after receiving threshold number of accusations (as part of the process accusations). -This file also contains the process accusations function for the gossiper to invoke. diff --git a/CTng/gossip/Readme.md b/CTng/gossip/Readme.md new file mode 100644 index 0000000..881c107 --- /dev/null +++ b/CTng/gossip/Readme.md @@ -0,0 +1,16 @@ +# Gossip Package + +## Contents +- `process_object.go`: Functions for processing a new object (valid, invalid, or duplicate) +- `gossiper.go`: Functions for actions that the Gossiper can complete as a client + - Sending to Owner + - Gossiping to connections + - Accusing (unused currently) +- `gossip_object.go`: Functions for working with Gossip Objects +- `accusations.go`: Describes the system for keeping track of accusations of each entity (with `accusation_validation.go` calls). +- Note that many calls are made between these files and the HTTP server. in the future, more gossiper logic could be moved from the server package to this one. + +## `Types.go` +- Defines the Gossip Object and explains some design choices with Gossip_object_IDs. + - Defines constants for the field types of CTng +- Defines the Gossiper Context object for managing server state \ No newline at end of file diff --git a/CTng/gossip/accusations.go b/CTng/gossip/accusations.go index 3b58008..1fe87b2 100644 --- a/CTng/gossip/accusations.go +++ b/CTng/gossip/accusations.go @@ -6,6 +6,10 @@ import ( "fmt" ) +/*This file mainly deals with Proof of Misbehavior generated after receiving threshold number of accusations (as part of the process accusations). +This file also contains the process accusations function for the gossiper to invoke. +*/ + func Process_Accusation(new_acc Gossip_object, accs *AccusationDB, c *crypto.CryptoConfig) (*Gossip_object, bool, error) { // Convert signature string p_sig, err := crypto.SigFragmentFromString(new_acc.Signature[0]) diff --git a/CTng/gossip/gossip_object.go b/CTng/gossip/gossip_object.go index 3b64d7c..b672d02 100644 --- a/CTng/gossip/gossip_object.go +++ b/CTng/gossip/gossip_object.go @@ -1,13 +1,11 @@ package gossip import ( - "CTng/config" "CTng/crypto" "encoding/json" "errors" "fmt" "log" - "reflect" "time" ) @@ -54,34 +52,9 @@ func unpack_object(obj []byte) (depacked Gossip_object) { return depack } -//checks if Gossip_object_ID already exists in map returns bool rn but I want to change it to just add the object to storage -func check_object_data(conf *config.Gossiper_config, obj Gossip_object, stor Gossip_Storage) { - obj_ID := obj.GetID(conf.Public.Period_interval) - // if object exists, make sure values match - if stored_object, exists := stor[obj_ID]; exists { - - check_stored := reflect.ValueOf(&stored_object).Elem() - given_object := reflect.ValueOf(&obj).Elem() - - for i := 0; i < check_stored.NumField(); i++ { - temp_stored := check_stored.Field(i).Interface() - temp_given := given_object.Field(i).Interface() - if temp_given == temp_stored { - continue - } else { - log.Fatal("Error given object does not match stored object") - } - } - - } else { - stor[obj_ID] = obj - } - -} - //verify gossip pom takes a gossip object as input func Verify_gossip_pom(g Gossip_object, c *crypto.CryptoConfig) error { - if g.Type == "http://ctng.uconn.edu/001" { + if g.Type == GOSSIP_POM { //gossip pom refers to Pom generated due to conflicting information //From Finn's gossiper design, gossip poms are defaulted to have 2 non empty fields for signature and paypload if g.Signature[1] != "" && g.Payload[1] != "" { @@ -141,7 +114,6 @@ func Verfiy_PayloadThreshold(g Gossip_object, c *crypto.CryptoConfig) error { // Verifies RSAsig matches payload, wait.... i think this just works out of the box with what we have func Verify_RSAPayload(g Gossip_object, c *crypto.CryptoConfig) error { if g.Signature[0] != "" && g.Payload[0] != "" { - // TODO: convert RSASig from and to a string. sig, err := crypto.RSASigFromString(g.Signature[0]) if err != nil { return errors.New(No_Sig_Match) @@ -153,7 +125,10 @@ func Verify_RSAPayload(g Gossip_object, c *crypto.CryptoConfig) error { } } -//Verifies Gossip object based on Type +//Verifies Gossip object based on the type: +//STH and Revocations use RSA +//Trusted information Fragments use BLS SigFragments +//PoMs use Threshold signatures func (g Gossip_object) Verify(c *crypto.CryptoConfig) error { // If everything Verified correctly, we return nil switch g.Type { diff --git a/CTng/gossip/gossiper.go b/CTng/gossip/gossiper.go index 369a93f..bd0ac9e 100644 --- a/CTng/gossip/gossiper.go +++ b/CTng/gossip/gossiper.go @@ -80,7 +80,5 @@ func SendToOwner(c *GossiperContext, obj Gossip_object) { defer resp.Body.Close() 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 ea00818..d38fcfd 100644 --- a/CTng/gossip/process_object.go +++ b/CTng/gossip/process_object.go @@ -46,7 +46,7 @@ func ProcessValidObject(c *GossiperContext, obj Gossip_object) { // Process a valid gossip object which is a duplicate to another one. // 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) err { +func ProcessDuplicateObject(c *GossiperContext, obj Gossip_object, dup Gossip_object) error { if obj.Signature == dup.Signature && obj.Payload == dup.Payload { return nil @@ -63,8 +63,9 @@ func ProcessDuplicateObject(c *GossiperContext, obj Gossip_object, dup Gossip_ob c.StoreObject(pom) c.HasPom[obj.Payload[0]] = true // Currently, we don't send PoMs. but if we did, we could do it here. - SendToOwner(c, pom) - return errors.New("Proof of Misbhevior Generated") + // Send to owner. + defer SendToOwner(c, pom) + return errors.New("Proof of Misbehavior Generated") } } diff --git a/CTng/gossip/types.go b/CTng/gossip/types.go index 9757de4..b2a6647 100644 --- a/CTng/gossip/types.go +++ b/CTng/gossip/types.go @@ -58,6 +58,8 @@ type Gossip_object struct { Payload [2]string `json:"payload,omitempty"` } +// The identifier for a Gossip Object is the (Application,Type,Signer,Period) tuple. +// Gossip_object.GetID(time Period) returns the ID of an object, accepting a period to be used for conversion. type Gossip_object_ID struct { Application string `json:"application"` Type string `json:"type"` @@ -65,6 +67,7 @@ type Gossip_object_ID struct { Period string `json:"period"` } +//Simple mapping of object IDs to objects. type Gossip_Storage map[Gossip_object_ID]Gossip_object // Gossiper Context @@ -84,6 +87,7 @@ type GossiperContext struct { HasPom map[string]bool } +// Saves the Storage object to the value in c.StorageFile. func (c *GossiperContext) SaveStorage() error { storageList := []Gossip_object{} for _, gossipObject := range *c.Storage { @@ -93,7 +97,7 @@ func (c *GossiperContext) SaveStorage() error { return err } -// Read every gossip object from c.StorageFile(). +// Read every gossip object from c.StorageFile. // Store all files in c.Storage by their ID. func (c *GossiperContext) LoadStorage() error { storageList := []Gossip_object{}