Skip to content
Snippets Groups Projects
Commit c49079c6 authored by Josh Brooks's avatar Josh Brooks
Browse files

Clean up code

parent 2dfb1d79
No related branches found
No related tags found
1 merge request!58Revert "Modify waiting lock"
...@@ -8,7 +8,6 @@ package dataStructures ...@@ -8,7 +8,6 @@ package dataStructures
import ( import (
"container/list" "container/list"
"fmt"
"github.com/golang-collections/collections/set" "github.com/golang-collections/collections/set"
"github.com/pkg/errors" "github.com/pkg/errors"
pb "gitlab.com/elixxir/comms/mixmessages" pb "gitlab.com/elixxir/comms/mixmessages"
...@@ -59,7 +58,6 @@ func (wr *WaitingRounds) Insert(newRound *Round) { ...@@ -59,7 +58,6 @@ func (wr *WaitingRounds) Insert(newRound *Round) {
for e := wr.rounds.Back(); e != nil; e = e.Prev() { for e := wr.rounds.Back(); e != nil; e = e.Prev() {
// If the new round is larger, than add it before // If the new round is larger, than add it before
extractedRound := e.Value.(*Round) extractedRound := e.Value.(*Round)
// todo: check no panics occur
if getTime(newRound) > getTime(extractedRound) { if getTime(newRound) > getTime(extractedRound) {
wr.rounds.InsertAfter(newRound, e) wr.rounds.InsertAfter(newRound, e)
...@@ -96,7 +94,6 @@ func (wr *WaitingRounds) remove(newRound *Round) { ...@@ -96,7 +94,6 @@ func (wr *WaitingRounds) remove(newRound *Round) {
// Look for a node with a matching ID from the list // Look for a node with a matching ID from the list
for e := wr.rounds.Back(); e != nil; e = e.Prev() { for e := wr.rounds.Back(); e != nil; e = e.Prev() {
extractedRound := e.Value.(*Round) extractedRound := e.Value.(*Round)
// todo: check no panics occur
if extractedRound.info.ID == newRound.info.ID { if extractedRound.info.ID == newRound.info.ID {
wr.rounds.Remove(e) wr.rounds.Remove(e)
return return
...@@ -118,7 +115,6 @@ func (wr *WaitingRounds) getFurthest(exclude *set.Set) *Round { ...@@ -118,7 +115,6 @@ func (wr *WaitingRounds) getFurthest(exclude *set.Set) *Round {
// If no rounds are excluded, return the last round in the list // If no rounds are excluded, return the last round in the list
if exclude == nil { if exclude == nil {
fmt.Println("exclude is nil ")
return wr.rounds.Back().Value.(*Round) return wr.rounds.Back().Value.(*Round)
} }
...@@ -126,9 +122,6 @@ func (wr *WaitingRounds) getFurthest(exclude *set.Set) *Round { ...@@ -126,9 +122,6 @@ func (wr *WaitingRounds) getFurthest(exclude *set.Set) *Round {
// Return the last non-excluded round in the list // Return the last non-excluded round in the list
for e := wr.rounds.Back(); e != nil; e = e.Prev() { for e := wr.rounds.Back(); e != nil; e = e.Prev() {
r := e.Value.(*Round) r := e.Value.(*Round)
fmt.Printf("r val: %v\n", r)
fmt.Printf("r info: %v\n", r.info)
if !exclude.Has(r) { if !exclude.Has(r) {
return r return r
} }
...@@ -150,7 +143,6 @@ func (wr *WaitingRounds) GetSlice() []*pb.RoundInfo { ...@@ -150,7 +143,6 @@ func (wr *WaitingRounds) GetSlice() []*pb.RoundInfo {
for e, i := wr.rounds.Front(), 0; e != nil; e, i = e.Next(), i+1 { for e, i := wr.rounds.Front(), 0; e != nil; e, i = e.Next(), i+1 {
iter++ iter++
extractedRound := e.Value.(*Round) extractedRound := e.Value.(*Round)
// todo: check no panics occur
if getTime(extractedRound) > now { if getTime(extractedRound) > now {
roundInfos = append(roundInfos, extractedRound.info) roundInfos = append(roundInfos, extractedRound.info)
} }
......
...@@ -462,15 +462,15 @@ func (i *Instance) RoundUpdate(info *pb.RoundInfo) error { ...@@ -462,15 +462,15 @@ func (i *Instance) RoundUpdate(info *pb.RoundInfo) error {
} }
rnd := ds.NewRound(info, perm.GetPubKey()) rnd := ds.NewRound(info, perm.GetPubKey())
if i.validationLevel == Strict {
// todo: modify here
err := signature.Verify(info, perm.GetPubKey()) err := signature.Verify(info, perm.GetPubKey())
if err != nil { if err != nil {
return errors.WithMessage(err, fmt.Sprintf("Could not validate "+ return errors.WithMessage(err, fmt.Sprintf("Could not validate "+
"the roundInfo signature: %+v", info)) "the roundInfo signature: %+v", info))
} }
}
err = i.roundUpdates.AddRound(rnd) err := i.roundUpdates.AddRound(rnd)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
package network package network
import "fmt"
// Level of validation types for pulling our round structure // Level of validation types for pulling our round structure
// Strict: Signatures are checked every time (intended for nodes) // Strict: Signatures are checked every time (intended for nodes)
// Lazy: Only check we're involved, only verifies the first retrieval // Lazy: Only check we're involved, only verifies the first retrieval
...@@ -17,3 +19,17 @@ const ( ...@@ -17,3 +19,17 @@ const (
Lazy Lazy
None None
) )
// Stringer for ValidationType
func (s ValidationType) String() string {
switch s {
case Strict:
return "Strict"
case Lazy:
return "Lazy"
case None:
return "None"
default:
return fmt.Sprintf("UNKNOWN STATE: %d", s)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment