Adding Verified Key to List and Check List First
diff --git a/nlsr.c b/nlsr.c
index 1580dcc..e4183ee 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -41,6 +41,7 @@
#include "nlsr_sync.h"
#include "nlsr_face.h"
#include "nlsr_fib.h"
+#include "nlsr_km.h"
#define ON_ERROR_DESTROY(resval) \
@@ -1198,11 +1199,13 @@
destroy_all_face_by_nlsr();
destroy_faces_for_nbrs();
+
destroy_adl();
destroy_npl();
destroy_lsdb();
destroy_npt();
destroy_routing_table();
+ destroy_keys();
if ( nlsr->slice != NULL )
ccns_slice_destroy(&nlsr->slice);
@@ -1296,6 +1299,7 @@
nlsr->npl = hashtb_create(sizeof(struct name_prefix_list_entry), NULL);
nlsr->npt = hashtb_create(sizeof(struct npt_entry), NULL);
nlsr->routing_table = hashtb_create(sizeof(struct routing_table_entry), NULL);
+ nlsr->keys = hashtb_create(sizeof(struct nlsr_key), NULL);
nlsr->lsdb=(struct linkStateDatabase *)malloc(sizeof(struct linkStateDatabase));
nlsr->lsdb->adj_lsdb = hashtb_create(sizeof(struct alsa), NULL);
diff --git a/nlsr.h b/nlsr.h
index 7ecb9d0..045a9d3 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -62,6 +62,7 @@
struct hashtb *rev_map;
struct hashtb *npt;
struct hashtb *routing_table;
+ struct hashtb *keys;
struct linkStateDatabase *lsdb;
diff --git a/nlsr_km.c b/nlsr_km.c
index 32d6102..f745d91 100644
--- a/nlsr_km.c
+++ b/nlsr_km.c
@@ -17,6 +17,7 @@
#include "nlsr.h"
#include "nlsr_km.h"
#include "nlsr_km_util.h"
+#include "utility.h"
int
sign_content_with_user_defined_keystore(struct ccn_charbuf *content_name,
@@ -454,3 +455,108 @@
return ret;
}
+void
+destroy_keys(void)
+{
+ int i, key_element;
+ struct nlsr_key *key;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->keys, e);
+ key_element=hashtb_n(nlsr->keys);
+
+ for(i=0;i<key_element;i++)
+ {
+ key=e->data;
+ free(key->key_name);
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+ if( nlsr->keys )
+ hashtb_destroy(&nlsr->keys);
+
+}
+
+void
+print_keys(void){
+
+ if ( nlsr->debugging )
+ printf("print_keys called \n");
+ if ( nlsr->detailed_logging )
+ writeLogg(__FILE__,__FUNCTION__,__LINE__,"print_keys called \n");
+
+ int i, key_element;
+ struct nlsr_key *key;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+
+ hashtb_start(nlsr->keys, e);
+ key_element=hashtb_n(nlsr->keys);
+
+ for(i=0;i<key_element;i++)
+ {
+ key=e->data;
+
+ if ( nlsr->debugging )
+ printf("Key : %s \n",key->key_name);
+
+ hashtb_next(e);
+ }
+
+ hashtb_end(e);
+
+}
+
+int
+does_key_exist(char *keyname){
+ if (nlsr->debugging)
+ {
+ printf("does_key_exist called\n");
+ printf("Keyname : %s \n",keyname);
+ }
+
+ int ret=0;
+
+ unsigned *v;
+ v = hashtb_lookup(nlsr->keys, keyname, strlen(keyname));
+ if (v != NULL){
+ ret = 1;
+ if (nlsr->debugging)
+ printf("Key Found\n");
+ }
+
+ return ret;
+}
+
+void
+add_key(char *keyname){
+ if (nlsr->debugging)
+ {
+ printf("add_key called\n");
+ printf("Keyname : %s \n",keyname);
+ }
+
+ struct nlsr_key *key;
+
+ struct hashtb_enumerator ee;
+ struct hashtb_enumerator *e = ⅇ
+ int res;
+
+ hashtb_start(nlsr->keys, e);
+ res = hashtb_seek(e, keyname, strlen(keyname), 0);
+
+ if(res == HT_NEW_ENTRY )
+ {
+ key=e->data;
+ key->key_name=(char *)calloc(strlen(keyname)+1,sizeof(char));
+ memcpy(key->key_name,keyname,strlen(keyname)+1);
+ }
+
+ if (nlsr->debugging)
+ print_keys();
+}
diff --git a/nlsr_km.h b/nlsr_km.h
index bb935fa..65c2dca 100644
--- a/nlsr_km.h
+++ b/nlsr_km.h
@@ -11,6 +11,9 @@
};
+struct nlsr_key{
+ char *key_name;
+};
int
@@ -33,4 +36,9 @@
struct ccn_parsed_ContentObject *pco,
int content_type);
+void add_key(char *keyname);
+int does_key_exist(char *keyname);
+
+void destroy_keys(void);
+
#endif
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index 3a724d5..2fdf091 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -510,14 +510,34 @@
if ( contain_key_name(info->content_ccnb, info->pco) == 1){
+ int res_verify=-1;
+ int key_exists=0;
+ struct ccn_charbuf *key_name=get_key_name(info->content_ccnb, info->pco);
+ struct ccn_charbuf *key_uri = ccn_charbuf_create();
+ ccn_uri_append(key_uri, key_name->buf, key_name->length, 0);
+ key_exists=does_key_exist(ccn_charbuf_as_string(key_uri));
+ int key_type=get_key_type_from_key_name(key_name);
+
+ if ( res_verify == 1 && key_type == NLSR_KEY ){
+ res_verify=0;
+ }
+ else{
+ res_verify=verify_key(info->content_ccnb,info->pco,0);
+ }
- int res_verify=verify_key(info->content_ccnb,info->pco,0);
+ //int res_verify=verify_key(info->content_ccnb,info->pco,0);
if ( res_verify != 0 ){
if ( nlsr->debugging )
printf("Error in verfiying keys !! :( \n");
+ ccn_charbuf_destroy(&key_name);
+ ccn_charbuf_destroy(&key_uri);
}
else{
+ if ( key_exists == 0 )
+ add_key(ccn_charbuf_as_string(key_uri));
+ ccn_charbuf_destroy(&key_name);
+ ccn_charbuf_destroy(&key_uri);
if ( nlsr->debugging )
printf("Key verification is successful :)\n");
update_adjacent_timed_out_zero_to_adl(nbr);
diff --git a/nlsr_sync.c b/nlsr_sync.c
index b0058e7..b893022 100644
--- a/nlsr_sync.c
+++ b/nlsr_sync.c
@@ -251,14 +251,32 @@
if ( nlsr->debugging )
printf("Content Parsing result: %d\n",chk_cont);
if ( contain_key_name(ptr, &pcobuf1) == 1){
-
- int res_verify=verify_key(ptr,&pcobuf1,1);
+ int res_verify=-1;
+ int key_exists=0;
+ struct ccn_charbuf *key_name=get_key_name(ptr, &pcobuf1);
+ struct ccn_charbuf *key_uri = ccn_charbuf_create();
+ ccn_uri_append(key_uri, key_name->buf, key_name->length, 0);
+ key_exists=does_key_exist(ccn_charbuf_as_string(key_uri));
+ int key_type=get_key_type_from_key_name(key_name);
+
+ if ( key_exists == 1 && key_type == NLSR_KEY ){
+ res_verify=0;
+ }
+ else{
+ res_verify=verify_key(ptr,&pcobuf1,1);
+ }
if ( res_verify != 0 ){
if ( nlsr->debugging )
printf("Error in verfiying keys !! :( \n");
+ ccn_charbuf_destroy(&key_name);
+ ccn_charbuf_destroy(&key_uri);
}
else{
+ if ( key_exists == 0 )
+ add_key(ccn_charbuf_as_string(key_uri));
+ ccn_charbuf_destroy(&key_name);
+ ccn_charbuf_destroy(&key_uri);
if ( nlsr->debugging )
printf("Key verification is successful :)\n");
ptr_in=ptr;