1
0
mirror of https://github.com/CovidBraceletPrj/CovidBracelet.git synced 2024-12-05 00:55:43 +01:00

Sequence Numbers: Introduce GET_MASKED_SN macro

This commit is contained in:
H1ghBre4k3r 2021-05-03 21:47:02 +02:00 committed by Patrick Rathje
parent 30615a895d
commit b3a2a6919b
3 changed files with 6 additions and 14 deletions

View File

@ -1,13 +1,9 @@
#include "sequencenumber.h"
record_sequence_number_t sn_mask(record_sequence_number_t sn) {
return (sn & SN_MASK);
}
int sn_equal(record_sequence_number_t a, record_sequence_number_t b) {
return sn_mask(a) == sn_mask(b);
return GET_MASKED_SN(a) == GET_MASKED_SN(b);
}
record_sequence_number_t sn_increment(record_sequence_number_t sn) {
return sn_mask(++sn);
return GET_MASKED_SN(++sn);
}

View File

@ -6,16 +6,12 @@
// mask for sequence numbers (2^24 - 1)
#define SN_MASK 16777215
typedef uint32_t record_sequence_number_t;
/**
* Mask a given sequence number to get rid of MSB.
* TODO: maybe as #define?
*
* @param sn sequence number to mask
* @return masked sequence number
*/
record_sequence_number_t sn_mask(record_sequence_number_t sn);
#define GET_MASKED_SN(x) (x & SN_MASK)
typedef uint32_t record_sequence_number_t;
/**
* Compare to sequence numbers for equality.

View File

@ -163,7 +163,7 @@ int delete_contact(record_sequence_number_t sn) {
// TODO lome: do we need lock here aswell?
record_sequence_number_t get_latest_sequence_number() {
return sn_mask(contact_information.oldest_contact + contact_information.count);
return GET_MASKED_SN((contact_information.oldest_contact + contact_information.count));
}
record_sequence_number_t get_oldest_sequence_number() {