Skip to content
Snippets Groups Projects
Commit a97d4205 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

removed filtering of the filters because it is un-needed.

parent fe02e5a7
No related branches found
No related tags found
1 merge request!170Release
...@@ -315,18 +315,9 @@ func (m *manager) follow(report interfaces.ClientErrorReport, rng csprng.Source, ...@@ -315,18 +315,9 @@ func (m *manager) follow(report interfaces.ClientErrorReport, rng csprng.Source,
return return
} }
//get the range fo filters which are valid for the identity
filtersStart, filtersEnd, outOfBounds := rounds.ValidFilterRange(identity, pollResp.Filters)
//check if there are any valid filters returned
if outOfBounds {
jww.WARN.Printf("No filters processed, none in valid range")
return
}
//prepare the filter objects for processing //prepare the filter objects for processing
filterList := make([]*rounds.RemoteFilter, 0, filtersEnd-filtersStart) filterList := make([]*rounds.RemoteFilter, 0, len(pollResp.Filters.Filters))
for i := filtersStart; i < filtersEnd; i++ { for i := range pollResp.Filters.Filters {
if len(pollResp.Filters.Filters[i].Filter) != 0 { if len(pollResp.Filters.Filters[i].Filter) != 0 {
filterList = append(filterList, rounds.NewRemoteFilter(pollResp.Filters.Filters[i])) filterList = append(filterList, rounds.NewRemoteFilter(pollResp.Filters.Filters[i]))
} }
......
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
bloom "gitlab.com/elixxir/bloomfilter" bloom "gitlab.com/elixxir/bloomfilter"
"gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/storage/reception"
"gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
...@@ -48,37 +47,3 @@ func (rf *RemoteFilter) FirstRound() id.Round { ...@@ -48,37 +47,3 @@ func (rf *RemoteFilter) FirstRound() id.Round {
func (rf *RemoteFilter) LastRound() id.Round { func (rf *RemoteFilter) LastRound() id.Round {
return id.Round(rf.data.FirstRound + uint64(rf.data.RoundRange)) return id.Round(rf.data.FirstRound + uint64(rf.data.RoundRange))
} }
// ValidFilterRange calculates which of the returned filters are valid for the identity
func ValidFilterRange(identity reception.IdentityUse, filters *mixmessages.ClientBlooms) (startIdx int, endIdx int, outOfBounds bool) {
outOfBounds = false
firstElementTS := filters.FirstTimestamp
identityStart := identity.StartValid.UnixNano()
identityEnd := identity.EndValid.UnixNano()
startIdx = int((identityStart - firstElementTS) / filters.Period)
if startIdx < 0 {
startIdx = 0
}
if startIdx > len(filters.Filters)-1 {
outOfBounds = true
return startIdx, endIdx, outOfBounds
}
endIdx = int((identityEnd - firstElementTS) / filters.Period)
if endIdx < 0 {
outOfBounds = true
return startIdx, endIdx, outOfBounds
}
if endIdx > len(filters.Filters)-1 {
endIdx = len(filters.Filters) - 1
}
// Add 1 to the end index so that it follows Go's convention; the last index
// is exclusive to the range
return startIdx, endIdx + 1, outOfBounds
}
...@@ -11,15 +11,12 @@ import ( ...@@ -11,15 +11,12 @@ import (
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
bloom "gitlab.com/elixxir/bloomfilter" bloom "gitlab.com/elixxir/bloomfilter"
"gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/storage/reception"
"gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"os" "os"
"reflect" "reflect"
"testing" "testing"
"time"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
...@@ -102,112 +99,3 @@ func TestRemoteFilter_FirstLastRound(t *testing.T) { ...@@ -102,112 +99,3 @@ func TestRemoteFilter_FirstLastRound(t *testing.T) {
} }
} }
\ No newline at end of file
// In bounds test
func TestValidFilterRange(t *testing.T) {
firstRound := uint64(25)
roundRange := uint32(75)
testFilter, err := bloom.InitByParameters(interfaces.BloomFilterSize,
interfaces.BloomFilterHashes)
if err != nil {
t.Fatalf("GetFilter error: "+
"Cannot initialize bloom filter for setup: %v", err)
}
data, err := testFilter.MarshalBinary()
if err != nil {
t.Fatalf("GetFilter error: "+
"Cannot marshal filter for setup: %v", err)
}
// Construct an in bounds value
expectedEphID := ephemeral.Id{1, 2, 3, 4, 5, 6, 7, 8}
requestGateway := id.NewIdFromString(ReturningGateway, id.Gateway, t)
iu := reception.IdentityUse{
Identity: reception.Identity{
EphId: expectedEphID,
Source: requestGateway,
StartValid: time.Now().Add(-12 * time.Hour),
EndValid: time.Now().Add(24 * time.Hour),
},
}
bloomFilter := &mixmessages.ClientBloom{
Filter: data,
FirstRound: firstRound,
RoundRange: roundRange,
}
// Fix for test on Windows machines: provides extra buffer between
// time.Now() for the reception.Identity and the mixmessages.ClientBlooms
time.Sleep(time.Millisecond)
msg := &mixmessages.ClientBlooms{
Period: int64(12 * time.Hour),
FirstTimestamp: time.Now().UnixNano(),
Filters: []*mixmessages.ClientBloom{bloomFilter},
}
start, end, outOfBounds := ValidFilterRange(iu, msg)
if outOfBounds {
t.Errorf("ValidFilterRange error: " +
"Range should not be out of bounds")
}
if start != 0 && end != 1 {
t.Errorf("ValidFilterRange error: "+
"Unexpected indices returned. "+
"\n\tExpected start: %v\n\tReceived start: %v"+
"\n\tExpected end: %v\n\tReceived end: %v", 0, start, 1, end)
}
}
// out of bounds test
func TestValidFilterRange_OutBounds(t *testing.T) {
firstRound := uint64(25)
roundRange := uint32(75)
testFilter, err := bloom.InitByParameters(interfaces.BloomFilterSize,
interfaces.BloomFilterHashes)
if err != nil {
t.Fatalf("GetFilter error: "+
"Cannot initialize bloom filter for setup: %v", err)
}
data, err := testFilter.MarshalBinary()
if err != nil {
t.Fatalf("GetFilter error: "+
"Cannot marshal filter for setup: %v", err)
}
// Construct an in bounds value
expectedEphID := ephemeral.Id{1, 2, 3, 4, 5, 6, 7, 8}
requestGateway := id.NewIdFromString(ReturningGateway, id.Gateway, t)
iu := reception.IdentityUse{
Identity: reception.Identity{
EphId: expectedEphID,
Source: requestGateway,
StartValid: time.Now().Add(-24 * time.Hour),
EndValid: time.Now().Add(-36 * time.Hour),
},
}
bloomFilter := &mixmessages.ClientBloom{
Filter: data,
FirstRound: firstRound,
RoundRange: roundRange,
}
msg := &mixmessages.ClientBlooms{
Period: int64(12 * time.Hour),
FirstTimestamp: time.Now().UnixNano(),
Filters: []*mixmessages.ClientBloom{bloomFilter},
}
_, _, outOfBounds := ValidFilterRange(iu, msg)
if !outOfBounds {
t.Errorf("ValidFilterRange error: " +
"Range should be out of bounds")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment