Skip to content

Commit

Permalink
Gossip Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tfn18001 committed Apr 20, 2022
1 parent c38ea10 commit c33ed23
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 38 deletions.
2 changes: 0 additions & 2 deletions CTng/gossip/Pom_Readme.md

This file was deleted.

16 changes: 16 additions & 0 deletions CTng/gossip/Readme.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions CTng/gossip/accusations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
35 changes: 5 additions & 30 deletions CTng/gossip/gossip_object.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package gossip

import (
"CTng/config"
"CTng/crypto"
"encoding/json"
"errors"
"fmt"
"log"
"reflect"
"time"
)

Expand Down Expand Up @@ -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] != "" {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions CTng/gossip/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}
7 changes: 4 additions & 3 deletions CTng/gossip/process_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
}

Expand Down
6 changes: 5 additions & 1 deletion CTng/gossip/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ 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"`
Signer string `json:"signer"`
Period string `json:"period"`
}

//Simple mapping of object IDs to objects.
type Gossip_Storage map[Gossip_object_ID]Gossip_object

// Gossiper Context
Expand All @@ -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 {
Expand All @@ -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{}
Expand Down

0 comments on commit c33ed23

Please sign in to comment.