diff --git a/network/follow.go b/network/follow.go index 870f63c85f8561e7d2e89fb5c499b624fabc8c3c..ec9e10a47cec044b0aa2b8e44ac93e53edd3f941 100644 --- a/network/follow.go +++ b/network/follow.go @@ -315,18 +315,9 @@ func (m *manager) follow(report interfaces.ClientErrorReport, rng csprng.Source, 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 - filterList := make([]*rounds.RemoteFilter, 0, filtersEnd-filtersStart) - for i := filtersStart; i < filtersEnd; i++ { + filterList := make([]*rounds.RemoteFilter, 0, len(pollResp.Filters.Filters)) + for i := range pollResp.Filters.Filters { if len(pollResp.Filters.Filters[i].Filter) != 0 { filterList = append(filterList, rounds.NewRemoteFilter(pollResp.Filters.Filters[i])) } diff --git a/network/rounds/remoteFilters.go b/network/rounds/remoteFilters.go index 7a434be073e51118d22adae682c27d2e3ad83b50..6753c4110716e83d08b55eb2f585b4e82ada1180 100644 --- a/network/rounds/remoteFilters.go +++ b/network/rounds/remoteFilters.go @@ -11,7 +11,6 @@ import ( jww "github.com/spf13/jwalterweatherman" bloom "gitlab.com/elixxir/bloomfilter" "gitlab.com/elixxir/client/interfaces" - "gitlab.com/elixxir/client/storage/reception" "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/xx_network/primitives/id" ) @@ -48,37 +47,3 @@ func (rf *RemoteFilter) FirstRound() id.Round { func (rf *RemoteFilter) LastRound() id.Round { 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 -} diff --git a/network/rounds/remoteFilters_test.go b/network/rounds/remoteFilters_test.go index a04d7f51c7f580402744fef7a5b1f128d5f23332..51d26973d9f024142ed89b04e57d8f7117992268 100644 --- a/network/rounds/remoteFilters_test.go +++ b/network/rounds/remoteFilters_test.go @@ -11,15 +11,12 @@ import ( jww "github.com/spf13/jwalterweatherman" bloom "gitlab.com/elixxir/bloomfilter" "gitlab.com/elixxir/client/interfaces" - "gitlab.com/elixxir/client/storage/reception" "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" - "gitlab.com/xx_network/primitives/id/ephemeral" "os" "reflect" "testing" - "time" ) func TestMain(m *testing.M) { @@ -101,113 +98,4 @@ func TestRemoteFilter_FirstLastRound(t *testing.T) { "\n\tExpected: %v\n\tReceived: %v", receivedLastRound, firstRound+uint64(roundRange)) } -} - -// 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") - } - -} +} \ No newline at end of file