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

Changes by Benjamin

parent fc6bc486
No related branches found
No related tags found
2 merge requests!53Release,!26Protonet
......@@ -31,6 +31,9 @@ type Network struct {
FastPolling bool
// Messages will not be sent to Rounds containing these Nodes
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
Messages
......@@ -50,6 +53,7 @@ func GetDefaultNetwork() Network {
KnownRoundsThreshold: 1500, //5 rounds/sec * 60 sec/min * 5 min
FastPolling: true,
BlacklistedNodes: make([]string, 0),
VerboseRoundTracking: false,
}
n.Rounds = GetDefaultRounds()
n.Messages = GetDefaultMessage()
......
......@@ -113,8 +113,9 @@ func LoadUnknownRounds(kv *versioned.KV,
// in params, it removes from the map
// Afterwards it adds the roundToAdd to the map if an entry isn't present
// 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,
roundsToAdd []id.Round) []id.Round {
roundsToAdd []id.Round, abandon func(round id.Round)) []id.Round {
returnSlice := make([]id.Round, 0)
urs.mux.Lock()
defer urs.mux.Unlock()
......@@ -132,6 +133,8 @@ func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool,
// If the round has been checked the maximum amount,
// the rond is removed from the map
if totalChecks > urs.params.MaxChecks {
localRnd := rnd
go abandon(localRnd)
delete(urs.rounds, rnd)
}
}
......
......@@ -86,7 +86,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) {
}
// 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:
// a) that returned rounds are no longer in the map
......@@ -106,7 +106,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) {
}
// 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 {
t.Errorf("Second iteration should return an empty list (no even rounds are left)."+
......@@ -116,7 +116,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) {
// Iterate over map until all rounds have checks incremented over
// maxCheck
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) {
// Check that LoadStore works after iterate call (which implicitly saves)
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
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