Skip to content

Commit 1b4f46b

Browse files
committed
update sd and ac param
1 parent 94fd17a commit 1b4f46b

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

app-support/access-control.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
#include "../util/msg-queue.h"
2323
#include "../util/uniform-time.h"
2424

25-
#define KEY_LIFTIMTE 10000000
25+
#define KEY_LIFTIME 60000
2626

2727
/* Logging Level: ERROR, DEBUG */
2828
#define ENABLE_NDN_LOG_ERROR 1
2929
#define ENABLE_NDN_LOG_DEBUG 1
3030
#include "../util/logger.h"
3131

32+
#if ENABLE_NDN_LOG_DEBUG
33+
static ndn_time_us_t m_measure_tp1 = 0;
34+
static ndn_time_us_t m_measure_tp2 = 0;
35+
#endif
36+
3237
/* Encoding buffer for Access Control module */
3338
static uint8_t ac_buf[1024];
3439

@@ -140,8 +145,8 @@ _on_ac_notification(const uint8_t* interest, uint32_t interest_size, void* userd
140145
ndn_decoder_t decoder;
141146
decoder_init(&decoder, notification.name.components[4].value, notification.name.components[4].size);
142147
decoder_get_uint32_value(&decoder, &keyid);
143-
if (key && key->key_id == keyid) {
144-
NDN_LOG_DEBUG("[ACCESSCTL] Enforced update for Service %u, KeyID %ld\n",
148+
if (key && key->key_id <= keyid) {
149+
NDN_LOG_DEBUG("[ACCESSCTL] Enforced update for Service %u, KeyID %lu\n",
145150
notification.name.components[3].value[0], keyid);
146151
for (int i = 0; i < 10; i++) {
147152
if (_ac_self_state.self_services[i] == notification.name.components[3].value[0])
@@ -203,7 +208,7 @@ _on_ekey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
203208
NDN_LOG_DEBUG("[ACCESSCTL] AES KeyID = %lu \n", keyid);
204209

205210
// set lifetime
206-
expires_in = KEY_LIFTIMTE;
211+
expires_in = KEY_LIFTIME;
207212
// if exist the same key, renew the payload
208213
uint8_t service;
209214
memcpy(&service, &data.name.components[3].value, sizeof(service));
@@ -213,7 +218,7 @@ _on_ekey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
213218
NDN_LOG_DEBUG("[ACCESSCTL] Update KeyID for service %u\n", service);
214219
for (int i = 0; i < 10; i++) {
215220
if (_ac_self_state.self_services[i] == service) {
216-
//_ac_self_state.ekeys[i].key_id = keyid;
221+
_ac_self_state.ekeys[i].key_id = keyid;
217222
_ac_self_state.ekeys[i].expires_at = expires_in + now;
218223
NDN_LOG_DEBUG("[ACCESSCTL] New expiration time is %ld, New keyid is %u\n",
219224
_ac_self_state.ekeys[i].expires_at, _ac_self_state.ekeys[i].key_id);
@@ -243,6 +248,11 @@ _on_ekey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
243248
NDN_LOG_ERROR("[ACCESSCTL] No empty AES key in local key storage\n");
244249
}
245250
}
251+
#if ENABLE_NDN_LOG_DEBUG
252+
m_measure_tp2 = ndn_time_now_us();
253+
NDN_LOG_DEBUG("[ACCESSCTL] Key update: %lluus\n", m_measure_tp2 - m_measure_tp1);
254+
#endif
255+
246256
// _ac_timeout();
247257
}
248258

@@ -298,7 +308,7 @@ _on_dkey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
298308
NDN_LOG_DEBUG("[ACCESSCTL] AES KeyID = %lu \n", keyid);
299309

300310
// set lifetime to 3000ms
301-
expires_in = KEY_LIFTIMTE;
311+
expires_in = KEY_LIFTIME;
302312
// if exist the same key, renew the payload
303313
uint8_t service;
304314
memcpy(&service, &data.name.components[3].value, sizeof(service));
@@ -308,7 +318,7 @@ _on_dkey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
308318
NDN_LOG_DEBUG("[ACCESSCTL] Update KeyID for service %u\n", service);
309319
for (int i = 0; i < 10; i++) {
310320
if (_ac_self_state.access_services[i] == service) {
311-
//_ac_self_state.access_keys[i].key_id += 1;
321+
_ac_self_state.ekeys[i].key_id = keyid;
312322
_ac_self_state.access_keys[i].expires_at = expires_in + now;
313323
NDN_LOG_DEBUG("[ACCESSCTL] New expiration time is %ld, New keyid is %u\n",
314324
_ac_self_state.access_keys[i].expires_at, _ac_self_state.access_keys[i].key_id);
@@ -404,6 +414,9 @@ _express_ekey_interest(uint8_t service)
404414
}
405415
NDN_LOG_DEBUG("[ACCESSCTL] Send EncryptionKey Interest with Name: ");
406416
NDN_LOG_DEBUG_NAME(&interest.name);
417+
#if ENABLE_NDN_LOG_DEBUG
418+
m_measure_tp1 = ndn_time_now_us();
419+
#endif
407420
return NDN_SUCCESS;
408421
}
409422

@@ -532,16 +545,21 @@ ndn_ac_after_bootstrapping()
532545

533546
// register for notification interest
534547
ndn_name_t name;
548+
ndn_name_init(&name);
535549
ndn_key_storage_t* storage = ndn_key_storage_get_instance();
536550
int ret = -1;
537551
ret = ndn_name_append_component(&name, &storage->self_identity[0].components[0]);
552+
NDN_LOG_ERROR_NAME(&name);
538553
if (ret != 0) return;
539554
uint8_t ac = NDN_SD_AC;
540555
ret = ndn_name_append_bytes_component(&name, &ac, 1);
541-
if (ret != 0) return;
556+
557+
// ret = ndn_name_append_string_component(&name, "AC", strlen("AC"));
558+
// if (ret != 0) return;
542559
ret = ndn_name_append_string_component(&name, "NOTIFY", strlen("NOTIFY"));
543560
if (ret != 0) return;
544561
ret = ndn_forwarder_register_name_prefix(&name, _on_ac_notification, NULL);
562+
NDN_LOG_ERROR_NAME(&name);
545563
if (ret != 0) {
546564
NDN_LOG_ERROR("[ACCESSCTL] Cannot register notification prefix: ");
547565
NDN_LOG_ERROR_NAME(&name);

app-support/service-discovery.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
extern "C" {
2121
#endif
2222

23-
const static uint32_t SD_ADV_INTERVAL = 30000;
23+
const static uint32_t SD_ADV_INTERVAL = 1800000;
2424

2525
/**
2626
* 1. Service Discovery protocol spec:

0 commit comments

Comments
 (0)