Skip to content
Snippets Groups Projects
Commit 0c29cd26 authored by Jake Taylor's avatar Jake Taylor
Browse files

Changes by Benjamin

parent fc6bc486
Branches
Tags
2 merge requests!53Release,!26Protonet
...@@ -31,6 +31,9 @@ type Network struct { ...@@ -31,6 +31,9 @@ type Network struct {
FastPolling bool FastPolling bool
// Messages will not be sent to Rounds containing these Nodes // Messages will not be sent to Rounds containing these Nodes
BlacklistedNodes []string BlacklistedNodes []string
// Determines if the state of every round processed is tracked in ram.
// This is very memory intensive and is primarily used for debugging
VerboseRoundTracking bool
Rounds Rounds
Messages Messages
...@@ -50,6 +53,7 @@ func GetDefaultNetwork() Network { ...@@ -50,6 +53,7 @@ func GetDefaultNetwork() Network {
KnownRoundsThreshold: 1500, //5 rounds/sec * 60 sec/min * 5 min KnownRoundsThreshold: 1500, //5 rounds/sec * 60 sec/min * 5 min
FastPolling: true, FastPolling: true,
BlacklistedNodes: make([]string, 0), BlacklistedNodes: make([]string, 0),
VerboseRoundTracking: false,
} }
n.Rounds = GetDefaultRounds() n.Rounds = GetDefaultRounds()
n.Messages = GetDefaultMessage() n.Messages = GetDefaultMessage()
......
...@@ -113,8 +113,9 @@ func LoadUnknownRounds(kv *versioned.KV, ...@@ -113,8 +113,9 @@ func LoadUnknownRounds(kv *versioned.KV,
// in params, it removes from the map // in params, it removes from the map
// Afterwards it adds the roundToAdd to the map if an entry isn't present // Afterwards it adds the roundToAdd to the map if an entry isn't present
// Finally it saves the modified map to disk. // Finally it saves the modified map to disk.
// The abandon function can be used to pass the abandoned round somewhere else
func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool, func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool,
roundsToAdd []id.Round) []id.Round { roundsToAdd []id.Round, abandon func(round id.Round)) []id.Round {
returnSlice := make([]id.Round, 0) returnSlice := make([]id.Round, 0)
urs.mux.Lock() urs.mux.Lock()
defer urs.mux.Unlock() defer urs.mux.Unlock()
...@@ -132,6 +133,8 @@ func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool, ...@@ -132,6 +133,8 @@ func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool,
// If the round has been checked the maximum amount, // If the round has been checked the maximum amount,
// the rond is removed from the map // the rond is removed from the map
if totalChecks > urs.params.MaxChecks { if totalChecks > urs.params.MaxChecks {
localRnd := rnd
go abandon(localRnd)
delete(urs.rounds, rnd) delete(urs.rounds, rnd)
} }
} }
......
...@@ -86,7 +86,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) {
} }
// Iterate over initial map // Iterate over initial map
received := store.Iterate(mockChecker, nil) received := store.Iterate(mockChecker, nil, func(round id.Round) { return })
// Check the received list for 2 conditions: // Check the received list for 2 conditions:
// a) that returned rounds are no longer in the map // a) that returned rounds are no longer in the map
...@@ -106,7 +106,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { ...@@ -106,7 +106,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) {
} }
// Add even round list to map // Add even round list to map
received = store.Iterate(mockChecker, roundListEven) received = store.Iterate(mockChecker, roundListEven, func(round id.Round) { return })
if len(received) != 0 { if len(received) != 0 {
t.Errorf("Second iteration should return an empty list (no even rounds are left)."+ t.Errorf("Second iteration should return an empty list (no even rounds are left)."+
...@@ -116,7 +116,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { ...@@ -116,7 +116,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) {
// Iterate over map until all rounds have checks incremented over // Iterate over map until all rounds have checks incremented over
// maxCheck // maxCheck
for i := 0; i < defaultMaxCheck+1; i++ { for i := 0; i < defaultMaxCheck+1; i++ {
_ = store.Iterate(mockChecker, []id.Round{}) _ = store.Iterate(mockChecker, []id.Round{}, func(round id.Round) { return })
} }
...@@ -172,7 +172,7 @@ func TestLoadUnknownRoundsStore(t *testing.T) { ...@@ -172,7 +172,7 @@ func TestLoadUnknownRoundsStore(t *testing.T) {
// Check that LoadStore works after iterate call (which implicitly saves) // Check that LoadStore works after iterate call (which implicitly saves)
mockChecker := func(round id.Round) bool { return false } mockChecker := func(round id.Round) bool { return false }
received := store.Iterate(mockChecker, nil) received := store.Iterate(mockChecker, nil, func(round id.Round) { return })
// Iterate is being called as a dummy, should not return anything // Iterate is being called as a dummy, should not return anything
if len(received) != 0 { if len(received) != 0 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment