mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-06-02 18:58:10 +02:00
Finalize refactorings of contacts and bloom module
This commit is contained in:
parent
cd780b122d
commit
22697403f7
|
@ -4,7 +4,7 @@
|
||||||
#include "ens/storage.h"
|
#include "ens/storage.h"
|
||||||
#include "exposure-notification.h"
|
#include "exposure-notification.h"
|
||||||
|
|
||||||
typedef struct bloom_filter {
|
typedef struct {
|
||||||
uint8_t* data;
|
uint8_t* data;
|
||||||
size_t size;
|
size_t size;
|
||||||
} bloom_filter_t;
|
} bloom_filter_t;
|
||||||
|
|
|
@ -37,7 +37,7 @@ void print_key(_ENBaseKey* key) {
|
||||||
|
|
||||||
void print_rpi(rolling_proximity_identifier_t* rpi) {
|
void print_rpi(rolling_proximity_identifier_t* rpi) {
|
||||||
for (int i = 0; i < sizeof(rolling_proximity_identifier_t); i++) {
|
for (int i = 0; i < sizeof(rolling_proximity_identifier_t); i++) {
|
||||||
printk("%02x", rpi->data[i]);
|
printk("%02x", rpi->b[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,12 +48,7 @@ void print_aem(associated_encrypted_metadata_t* aem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int register_record(record_t* record) {
|
int register_record(record_t* record) {
|
||||||
int rc = add_record(record);
|
return add_record(record);
|
||||||
if (rc) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
// rc = bloom_add_record(record);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +63,7 @@ int get_number_of_infected_for_multiple_intervals_simple(infected_for_interval_i
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
record_t* current;
|
record_t* current;
|
||||||
while (current = ens_records_iterator_next(&iterator)) {
|
while ((current = ens_records_iterator_next(&iterator))) {
|
||||||
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
||||||
sizeof(rolling_proximity_identifier_t)) == 0) {
|
sizeof(rolling_proximity_identifier_t)) == 0) {
|
||||||
ctx[i].infected++;
|
ctx[i].infected++;
|
||||||
|
@ -92,7 +87,7 @@ void fill_bloom_with_stored_records(bloom_filter_t* bloom) {
|
||||||
|
|
||||||
// fill bloom filter with records
|
// fill bloom filter with records
|
||||||
record_t* current;
|
record_t* current;
|
||||||
while (current = ens_records_iterator_next(&iterator)) {
|
while ((current = ens_records_iterator_next(&iterator))) {
|
||||||
bloom_add_record(bloom, &(current->rolling_proximity_identifier));
|
bloom_add_record(bloom, &(current->rolling_proximity_identifier));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +95,7 @@ void fill_bloom_with_stored_records(bloom_filter_t* bloom) {
|
||||||
/**
|
/**
|
||||||
* Fill the bloom filter with flash records and test passed RPIs against it.
|
* Fill the bloom filter with flash records and test passed RPIs against it.
|
||||||
*/
|
*/
|
||||||
int64_t test_bloom_performance(infected_for_interval_ident_ctx_t* ctx, int count) {
|
int64_t bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
||||||
bloom_filter_t* bloom = bloom_init(get_num_records() * 2);
|
bloom_filter_t* bloom = bloom_init(get_num_records() * 2);
|
||||||
if (!bloom) {
|
if (!bloom) {
|
||||||
printk("bloom init failed\n");
|
printk("bloom init failed\n");
|
||||||
|
@ -211,7 +206,7 @@ int reverse_bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
record_t* current;
|
record_t* current;
|
||||||
while (current = ens_records_iterator_next(&iterator)) {
|
while ((current = ens_records_iterator_next(&iterator))) {
|
||||||
if (bloom_probably_has_record(bloom, &(current->rolling_proximity_identifier))) {
|
if (bloom_probably_has_record(bloom, &(current->rolling_proximity_identifier))) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
||||||
|
@ -220,10 +215,6 @@ int reverse_bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
||||||
amount++;
|
amount++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// TODO lome: maybe dont require orderred array, so this is not useful
|
|
||||||
if (current->timestamp > ctx[i].search_end) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,52 +257,46 @@ void setup_test_data() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INFECTED_INTERVALS_COUNT 2000
|
|
||||||
// setup our ordered array with infected RPIs
|
|
||||||
static infected_for_interval_ident_ctx_t infectedIntervals[INFECTED_INTERVALS_COUNT];
|
|
||||||
|
|
||||||
printk("Starting measurements with %d RPIs to seach and an infection rate of %d\n", INFECTED_INTERVALS_COUNT,
|
|
||||||
CONFIG_TEST_INFECTED_RATE);
|
|
||||||
|
|
||||||
// measure_perf(get_number_of_infected_for_multiple_intervals_dumb, "dumb", infectedIntervals,
|
|
||||||
// INFECTED_INTERVALS_COUNT);
|
|
||||||
// measure_perf(get_number_of_infected_for_multiple_intervals_simple, "simple", infectedIntervals,
|
|
||||||
// INFECTED_INTERVALS_COUNT);
|
|
||||||
// measure_perf(get_number_of_infected_for_multiple_intervals_optimized, "optimized", infectedIntervals,
|
|
||||||
// INFECTED_INTERVALS_COUNT);
|
|
||||||
|
|
||||||
// measure_perf(test_bloom_performance, "bloom", infectedIntervals, INFECTED_INTERVALS_COUNT);
|
|
||||||
|
|
||||||
measure_perf(reverse_bloom_filter, "bloom reverse", infectedIntervals, INFECTED_INTERVALS_COUNT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_contacts() {
|
int init_contacts() {
|
||||||
#if CONFIG_CONTACTS_PERFORM_RISC_CHECK_TEST
|
#if CONFIG_CONTACTS_PERFORM_RISC_CHECK_TEST
|
||||||
|
reset_record_storage();
|
||||||
setup_test_data();
|
setup_test_data();
|
||||||
|
|
||||||
|
// setup our ordered array with infected RPIs
|
||||||
|
static infected_for_interval_ident_ctx_t infectedIntervals[CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT];
|
||||||
|
|
||||||
|
printk("Starting measurements with %d RPIs to seach and an infection rate of %d\n",
|
||||||
|
CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT, CONFIG_TEST_INFECTED_RATE);
|
||||||
|
|
||||||
|
measure_perf(check_possible_contacts_for_intervals, "bloom reverse", infectedIntervals,
|
||||||
|
CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check for a list of specified interval identifiers, whether they were probably met or not.
|
|
||||||
* @param ctx list of interval identifiers to check
|
|
||||||
* @param count amount of identifiers to check
|
|
||||||
* @return the amount of met intervals, -ERRNO on error
|
|
||||||
*/
|
|
||||||
int check_possible_contacts_for_intervals(infected_for_interval_ident_ctx_t* ctx, int count) {
|
int check_possible_contacts_for_intervals(infected_for_interval_ident_ctx_t* ctx, int count) {
|
||||||
|
#if CONFIG_CONTACTS_BLOOM_REVERSE
|
||||||
return reverse_bloom_filter(ctx, count);
|
return reverse_bloom_filter(ctx, count);
|
||||||
|
#else
|
||||||
|
return bloom_filter(ctx, count);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
int check_possible_contacts_for_periods(period_key_information_t periodKeyInformation[], int count) {
|
||||||
ENPeriodKey periodKey;
|
for (int i = 0; i < count; i++) {
|
||||||
time_t start;
|
static infected_for_interval_ident_ctx_t intervalIdents[EN_TEK_ROLLING_PERIOD];
|
||||||
time_t end;
|
int periodStart = en_get_interval_number(periodKeyInformation[i].start);
|
||||||
int met;
|
for (int interval = 0; interval < EN_TEK_ROLLING_PERIOD; interval++) {
|
||||||
} period_key_information_t;
|
en_derive_interval_identifier(&intervalIdents[interval].interval_identifier,
|
||||||
|
&periodKeyInformation[i].periodKey, periodStart + interval);
|
||||||
// TODO lome: needed?
|
}
|
||||||
int check_possible_contacts_for_periods(period_key_information_t* periodKey, int count) {
|
int rc = check_possible_contacts_for_intervals(intervalIdents, 0);
|
||||||
infected_for_interval_ident_ctx_t intervalIdents[count * 144];
|
if (rc < 0) {
|
||||||
return check_possible_contacts_for_intervals(intervalIdents, 0);
|
return rc;
|
||||||
|
}
|
||||||
|
periodKeyInformation[i].met = rc;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,12 @@ typedef struct {
|
||||||
time_t search_end;
|
time_t search_end;
|
||||||
} __packed infected_for_interval_ident_ctx_t;
|
} __packed infected_for_interval_ident_ctx_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ENPeriodKey periodKey;
|
||||||
|
time_t start;
|
||||||
|
int met;
|
||||||
|
} __packed period_key_information_t;
|
||||||
|
|
||||||
typedef int (*test_func_t)(infected_for_interval_ident_ctx_t* infectedIntervals, int count);
|
typedef int (*test_func_t)(infected_for_interval_ident_ctx_t* infectedIntervals, int count);
|
||||||
|
|
||||||
void print_key(_ENBaseKey* key);
|
void print_key(_ENBaseKey* key);
|
||||||
|
@ -37,25 +43,24 @@ void print_aem(associated_encrypted_metadata_t* aem);
|
||||||
int register_record(record_t* record);
|
int register_record(record_t* record);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of infected records for a given PeriodKey.
|
* Initialize the contacts module.
|
||||||
*
|
|
||||||
* @param key the PeriodKey
|
|
||||||
* @param timestamp the timestamp of the period
|
|
||||||
*
|
|
||||||
* @returns the number of infected records or -ERRNO in case of an error
|
|
||||||
*/
|
*/
|
||||||
int get_number_of_infected_for_period(ENPeriodKey* key, time_t timestamp);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the number of infected records for multiple IntervalIdentifier.
|
|
||||||
*
|
|
||||||
* @param ctx array of period keys and timestamps with field "infected" for the number of infected records
|
|
||||||
* @param count the number of periods in the array
|
|
||||||
*
|
|
||||||
* @returns 0 in case of success, -ERRNO in case of an error
|
|
||||||
*/
|
|
||||||
// int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count);
|
|
||||||
|
|
||||||
int init_contacts();
|
int init_contacts();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for a list of specified interval identifiers, whether they were probably met or not.
|
||||||
|
* @param ctx list of interval identifiers to check
|
||||||
|
* @param count amount of identifiers to check
|
||||||
|
* @return the amount of met intervals, -ERRNO on error
|
||||||
|
*/
|
||||||
|
int check_possible_contacts_for_intervals(infected_for_interval_ident_ctx_t* ctx, int count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for a list of specified period keys, whether they were probably met or not.
|
||||||
|
* @param ctx list of period keys and their meta information to check
|
||||||
|
* @param count amount of period keys to check
|
||||||
|
* @return -ERRNO on error, 0 otherwise
|
||||||
|
*/
|
||||||
|
int check_possible_contacts_for_periods(period_key_information_t periodKeyInformation[], int count);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,23 +7,22 @@
|
||||||
#ifndef COVID_TYPES_H
|
#ifndef COVID_TYPES_H
|
||||||
#define COVID_TYPES_H
|
#define COVID_TYPES_H
|
||||||
|
|
||||||
|
#include <exposure-notification.h>
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
|
|
||||||
#define COVID_ROLLING_PROXIMITY_IDENTIFIER_LEN 16
|
#define COVID_ROLLING_PROXIMITY_IDENTIFIER_LEN 16
|
||||||
|
|
||||||
typedef struct rolling_proximity_identifier {
|
typedef ENIntervalIdentifier rolling_proximity_identifier_t;
|
||||||
uint8_t data[COVID_ROLLING_PROXIMITY_IDENTIFIER_LEN];
|
|
||||||
} __packed rolling_proximity_identifier_t;
|
|
||||||
|
|
||||||
typedef struct bt_metadata {
|
typedef struct bt_metadata {
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
uint8_t tx_power;
|
uint8_t tx_power;
|
||||||
uint8_t rsv1;
|
uint8_t rsv1;
|
||||||
uint8_t rsv2;
|
uint8_t rsv2;
|
||||||
} __packed bt_metadata_t;
|
} __packed bt_metadata_t;
|
||||||
|
|
||||||
//typedef struct bt_metadata bt_metadata_t;
|
// typedef struct bt_metadata bt_metadata_t;
|
||||||
|
|
||||||
typedef struct associated_encrypted_metadata {
|
typedef struct associated_encrypted_metadata {
|
||||||
uint8_t data[sizeof(bt_metadata_t)];
|
uint8_t data[sizeof(bt_metadata_t)];
|
||||||
|
|
|
@ -108,7 +108,7 @@ int init_record_storage(bool clean) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int reset_record_storage() {
|
void reset_record_storage() {
|
||||||
k_mutex_lock(&info_fs_lock, K_FOREVER);
|
k_mutex_lock(&info_fs_lock, K_FOREVER);
|
||||||
record_information.count = 0;
|
record_information.count = 0;
|
||||||
record_information.oldest_contact = 0;
|
record_information.oldest_contact = 0;
|
||||||
|
|
|
@ -32,7 +32,7 @@ int init_record_storage(bool clean);
|
||||||
/**
|
/**
|
||||||
* Reset state of record storage.
|
* Reset state of record storage.
|
||||||
*/
|
*/
|
||||||
int reset_record_storage();
|
void reset_record_storage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the record with number sn into the destination struct
|
* Loads the record with number sn into the destination struct
|
||||||
|
|
|
@ -41,6 +41,17 @@ config CONTACTS_PERFORM_RISC_CHECK_TEST
|
||||||
bool ""
|
bool ""
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
Flag for performing tests.
|
Flag for performing tests. WARNING: This deletes all currently stored records.
|
||||||
|
|
||||||
|
config CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT
|
||||||
|
int ""
|
||||||
|
default 1024
|
||||||
|
help
|
||||||
|
Amount of interval identifiers to test against stored test data.
|
||||||
|
|
||||||
|
config CONFIG_CONTACTS_BLOOM_REVERSE
|
||||||
|
bool ""
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Flag for toggling between bloom variants. Yes means, that the reverse bloom filter is used.
|
||||||
endmenu
|
endmenu
|
||||||
|
|
Loading…
Reference in New Issue
Block a user