Skip to content

Commit

Permalink
store rounded down contact date
Browse files Browse the repository at this point in the history
  • Loading branch information
stmitt committed Apr 28, 2020
1 parent 6e6c58f commit 4e18a17
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Sources/DP3TSDK/Cryptography/DP3TCryptoModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ class DP3TCryptoModule {
// generate all ephIDs for day
let ephIDs = Set(try DP3TCryptoModule.createEphIDs(secretKey: secretKeyForDay))
// check all handshakes if they match any of the ephIDs
for contact in contactsOnDay {
// make sure that all contact date is before bucket date
for contact in contactsOnDay where bucketDate >= contact.date {
if ephIDs.contains(contact.ephID) {
matchingContacts.append(contact)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/DP3TSDK/Database/ContactsStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ContactsStorage {
/// - Parameter contact: the Contact to add
func add(contact: Contact) {
let insert = table.insert(
dateColumn <- Date(timeIntervalSince1970: contact.day.timestamp).millisecondsSince1970,
dateColumn <- contact.date.millisecondsSince1970,
ephIDColumn <- contact.ephID,
windowCountColumn <- contact.windowCount,
associatedKnownCaseColumn <- contact.associatedKnownCase
Expand Down Expand Up @@ -104,7 +104,7 @@ class ContactsStorage {
guard row[associatedKnownCaseColumn] == nil else { continue }
let model = Contact(identifier: row[idColumn],
ephID: row[ephIDColumn],
day: DayDate(date: Date(milliseconds: row[dateColumn])),
date: Date(milliseconds: row[dateColumn]),
windowCount: row[windowCountColumn],
associatedKnownCase: row[associatedKnownCaseColumn])
contacts.append(model)
Expand Down
2 changes: 1 addition & 1 deletion Sources/DP3TSDK/Models/Contact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
struct Contact {
let identifier: Int?
let ephID: EphID
let day: DayDate
let date: Date
let windowCount: Int
let associatedKnownCase: Int?
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/DP3TSDK/utils/ContactFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ enum ContactFactory {
}

if numberOfMatchingWindows != 0 {
let day = DayDate(date: firstValue.0)
let timestamp = firstValue.0.timeIntervalSince1970
let bucketTimestamp = timestamp - timestamp.truncatingRemainder(dividingBy: NetworkingConstants.batchLength)
return Contact(identifier: nil,
ephID: ephID,
day: day,
date: Date(timeIntervalSince1970: bucketTimestamp),
windowCount: numberOfMatchingWindows,
associatedKnownCase: nil)
}
Expand Down

0 comments on commit 4e18a17

Please sign in to comment.