Browse Source

Sync : re-impl of sync message expiry based on message reception time stamp

doc_update_sequoia
Edouard Tisserant 6 years ago
parent
commit
bc4b76924a
4 changed files with 13 additions and 90 deletions
  1. +1
    -2
      asn.1/devicegroup.asn1
  2. +0
    -32
      src/map_asn1.c
  3. +0
    -40
      src/map_asn1.h
  4. +12
    -16
      src/sync_impl.c

+ 1
- 2
asn.1/devicegroup.asn1 View File

@ -27,9 +27,8 @@ DeviceGroup-Protocol ::= SEQUENCE {
sequence INTEGER, /* always increases */
me Identity, /* identity of the sender */
state INTEGER, /* state the sender is in */
devicegroup BOOLEAN,
devicegroup BOOLEAN
/* signals if this message is coming from a device group member */
expiry GeneralizedTime
},
payload CHOICE {


+ 0
- 32
src/map_asn1.c View File

@ -178,35 +178,3 @@ enomem:
return NULL;
}
timestamp *GeneralizedTime_to_timestamp(GeneralizedTime_t * asntime, timestamp *result)
{
assert(asntime);
if (!asntime)
return NULL;
time_t smpltime = asn_GT2time(asntime, NULL, 0);
if (!result){
result = new_timestamp(smpltime);
}
else
gmtime_r(&smpltime, result);
return result;
}
time_t GeneralizedTime_to_time_t(GeneralizedTime_t * asntime)
{
return asn_GT2time(asntime, NULL, 0);
}
GeneralizedTime_t *timestamp_to_GeneralizedTime(timestamp * ts, GeneralizedTime_t *result)
{
assert(ts);
if (!ts)
return NULL;
GeneralizedTime_t *asntime = asn_time2GT(result, ts, 0);
return asntime;
}

+ 0
- 40
src/map_asn1.h View File

@ -4,7 +4,6 @@
#include "identity_list.h"
#include "../asn.1/Identity.h"
#include "../asn.1/IdentityList.h"
#include "../asn.1/GeneralizedTime.h"
#ifdef __cplusplus
extern "C" {
@ -75,45 +74,6 @@ IdentityList_t *IdentityList_from_identity_list(
identity_list *IdentityList_to_identity_list(IdentityList_t *list, identity_list *result);
// GeneralizedTime_to_timestamp() - convert ASN.1 GeneralizedTime to timestamp
//
// params:
// asntime (in) ASN.1 GeneralizedTime to convert
// result (inout) timestamp to update or NULL to alloc a new one
//
// return value:
// pointer to allocated timestamp
//
// caveat:
// if a new timestamp is allocated, the ownership goes to the caller
timestamp *GeneralizedTime_to_timestamp(GeneralizedTime_t * asntime, timestamp *result);
// GeneralizedTime_to_time_t() - convert ASN.1 GeneralizedTime to time_t
//
// params:
// asntime (in) ASN.1 GeneralizedTime to convert
//
// return value:
// resulting time_t
//
time_t GeneralizedTime_to_time_t(GeneralizedTime_t * asntime);
// timestamp_GeneralizedTime_to() - convert ASN.1 timestamp to GeneralizedTime
//
// params:
// ts (in) timestam to convert
// result (inout) GeneralizedTime_t to update or NULL to alloc a new one
//
// return value:
// pointer to allocated ASN.1 GeneralizedTime
//
// caveat:
// if a new GeneralizedTime is allocated, the ownership goes to the caller
GeneralizedTime_t *timestamp_to_GeneralizedTime(timestamp * ts, GeneralizedTime_t *result);
#ifdef __cplusplus
}
#endif


+ 12
- 16
src/sync_impl.c View File

@ -204,6 +204,9 @@ PEP_STATUS inject_DeviceState_event(
return status;
}
// Ten minutes
#define SYNC_MSG_EXPIRE_DELTA (60 * 10)
PEP_STATUS receive_DeviceState_msg(
PEP_SESSION session,
message *src,
@ -228,6 +231,7 @@ PEP_STATUS receive_DeviceState_msg(
&msg, bl->value, bl->size);
if (msg) {
PEP_STATUS status = PEP_STATUS_OK;
char *user_id = strndup((char *) msg->header.me.user_id->buf,
msg->header.me.user_id->size);
@ -238,15 +242,17 @@ PEP_STATUS receive_DeviceState_msg(
}
// check message expiry
time_t expiry = GeneralizedTime_to_time_t(&msg->header.expiry);
time_t now = time(NULL);
if(expiry != 0 && now != 0 && expiry < now){
expired = true;
goto free_all;
if(src->recv) {
time_t expiry = timegm(src->recv) + SYNC_MSG_EXPIRE_DELTA;
time_t now = time(NULL);
if(expiry != 0 && now != 0 && expiry < now){
expired = true;
goto free_all;
}
}
int32_t value = (int32_t) msg->header.sequence;
PEP_STATUS status = sequence_value(session, (char *) user_id,
status = sequence_value(session, (char *) user_id,
&value);
if (status == PEP_STATUS_OK) {
@ -399,9 +405,6 @@ void free_DeviceGroup_Protocol_msg(DeviceGroup_Protocol_t *msg)
ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
}
// Ten minutes
#define SYNC_MSG_EXPIRE_DELTA (60 * 10)
PEP_STATUS unicast_msg(
PEP_SESSION session,
const Identity partner,
@ -465,13 +468,6 @@ PEP_STATUS unicast_msg(
else
msg->header.devicegroup = 0;
timestamp *expiry = new_timestamp(time(NULL) + SYNC_MSG_EXPIRE_DELTA);
if(timestamp_to_GeneralizedTime(expiry, &msg->header.expiry) == NULL){
free_timestamp(expiry);
goto enomem;
}
free_timestamp(expiry);
if (asn_check_constraints(&asn_DEF_DeviceGroup_Protocol, msg, NULL, NULL)) {
status = PEP_CONTRAINTS_VIOLATED;
goto error;


Loading…
Cancel
Save