Update with Locking
diff --git a/nlsr.c b/nlsr.c
index 9f16325..1576bc4 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -60,6 +60,18 @@
     NULL
 };
 
+void
+my_lock(void)
+{
+	nlsr->semaphor=1;
+}
+
+void 
+my_unlock(void)
+{
+	nlsr->semaphor=0;
+}
+
 void 
 process_command_router_name(char *command)
 {
@@ -160,7 +172,7 @@
 	nbr->neighbor=ccn_charbuf_create();
 	ccn_charbuf_append_string(nbr->neighbor,rtr_name);
 	nbr->face=face_id;
-	nbr->status=0;	
+	nbr->status=NBR_DOWN;	
 
 	
 
@@ -462,6 +474,8 @@
 	nlsr->lsdb_synch_interval = LSDB_SYNCH_INTERVAL;
 	nlsr->interest_retry = INTEREST_RETRY;
 	nlsr->interest_resend_time = INTEREST_RESEND_TIME;
+
+	nlsr->semaphor=0;
 	
 
 }
@@ -519,14 +533,17 @@
 
 	nlsr->sched = ccn_schedule_create(nlsr, &ndn_rtr_ticker);
 
-	nlsr->event_build_name_lsa = ccn_schedule_event(nlsr->sched, 500, &initial_build_name_lsa, NULL, 0);
+	nlsr->event_build_name_lsa = ccn_schedule_event(nlsr->sched, 100, &initial_build_name_lsa, NULL, 0);
 	nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1000000, &send_info_interest, NULL, 0);
 	
 
 	while(1)
 	{
-		ccn_schedule_run(nlsr->sched);
-        	res = ccn_run(nlsr->ccn, 500);
+		if(nlsr->semaphor !=1)
+		{
+			ccn_schedule_run(nlsr->sched);
+        		res = ccn_run(nlsr->ccn, 500);
+		}
 
 	}
 	
diff --git a/nlsr.h b/nlsr.h
index 0cd71e8..144742c 100644
--- a/nlsr.h
+++ b/nlsr.h
@@ -58,6 +58,8 @@
 	long int lsdb_synch_interval;
 	int interest_retry;
 	long int interest_resend_time;
+
+	int semaphor;
 	
 };
 
@@ -78,7 +80,8 @@
 void add_name_prefix_to_npl(struct name_prefix *name_prefix);
 void print_name_prefix_from_npl(void);
 
-
+void my_lock(void);
+void my_unlock(void);
 
 
 
diff --git a/nlsr_adl.c b/nlsr_adl.c
index 767d7bd..de6ad07 100644
--- a/nlsr_adl.c
+++ b/nlsr_adl.c
@@ -103,7 +103,11 @@
 	if (res == HT_OLD_ENTRY)
 	{
 		nnbr=e->data;
-		nnbr->status=status;
+		if ( nnbr->status!=status )
+		{
+			nnbr->status=status;
+			nlsr->adj_build_flag++;
+		}
 	}
 	else if(res == HT_NEW_ENTRY)
 	{
diff --git a/nlsr_adl.h b/nlsr_adl.h
index dc2e899..1bcb381 100644
--- a/nlsr_adl.h
+++ b/nlsr_adl.h
@@ -1,6 +1,9 @@
 #ifndef _NLSR_ADL_H_
 #define _NLSR_ADL_H_
 
+#define NBR_ACTIVE 1
+#define NBR_DOWN 0
+
 void add_adjacent_to_adl(struct ndn_neighbor *nbr);
 void print_adjacent_from_adl(void);
 void update_adjacent_status_to_adl(struct ccn_charbuf *nbr, int status);
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index c8c4160..b6b115e 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -123,6 +123,7 @@
 int 
 initial_build_name_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
 {
+	my_lock();	
 	printf("initial_build_name_lsa called \n");	
 	int i, npl_element;
 	struct name_prefix *np;
@@ -161,9 +162,9 @@
 	hashtb_end(e);
 
 	print_name_lsdb();
-
+	
+	my_unlock();
 	//nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 1, &send_info_interest, NULL, 0);
-
 	return 0;
 }
 
@@ -215,10 +216,13 @@
 int 
 install_adj_lsa(struct ccn_schedule *sched, void *clienth, struct ccn_scheduled_event *ev, int flags)
 {
+	my_lock();
+		
 	printf("install_adj_lsa called \n");
 
 	ev = ccn_schedule_event(nlsr->sched, 1000000, &install_adj_lsa, NULL, 0);
 
+	my_unlock();
 	return 0;
 	
 }
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index 52edb16..af79e3a 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -45,6 +45,7 @@
 incoming_interest(struct ccn_closure *selfp,
         enum ccn_upcall_kind kind, struct ccn_upcall_info *info)
 {
+	my_lock();
     
     switch (kind) {
         case CCN_UPCALL_FINAL:
@@ -87,6 +88,7 @@
             break;
     }
 
+	my_unlock();
     return CCN_UPCALL_RESULT_OK;
 }
 
@@ -95,6 +97,7 @@
         enum ccn_upcall_kind kind, struct ccn_upcall_info* info)
 {
 
+	my_lock();
 
     switch(kind) {
         case CCN_UPCALL_FINAL:
@@ -125,6 +128,7 @@
             return CCN_UPCALL_RESULT_ERR;
     }
 
+	my_unlock();
     return CCN_UPCALL_RESULT_OK;
 }
 
@@ -218,6 +222,47 @@
 	ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E_Content]-info->pco->offset[CCN_PCO_B_Content], info->pco, &content_data, &length);
 
 	printf("Info Value: %s \n",(char *)content_data);
+
+
+	int res,i;
+	int nlsr_position=0;
+	int name_comps=(int)info->interest_comps->n;
+
+	for(i=0;i<name_comps;i++)
+	{
+		res=ccn_name_comp_strcmp(info->interest_ccnb,info->interest_comps,i,"nlsr");
+		if( res == 0)
+		{
+			nlsr_position=i;
+			break;
+		}	
+	}
+	
+	struct ccn_charbuf *nbr;
+	nbr=ccn_charbuf_create();
+
+	
+	const unsigned char *comp_ptr1;
+	size_t comp_size;
+	for(i=0;i<nlsr_position;i++)
+	{
+		res=ccn_name_comp_get(info->interest_ccnb, info->interest_comps,i,&comp_ptr1, &comp_size);
+		//printf("%s \n",comp_ptr1);
+		ccn_charbuf_append_string(nbr,"/");
+		ccn_charbuf_append_string(nbr,(const char *)comp_ptr1);	
+	}
+
+	ccn_charbuf_append_string(nbr,"\0");	
+	printf("Info Content received for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
+	
+	update_adjacent_timed_out_zero_to_adl(nbr);
+	update_adjacent_status_to_adl(nbr,NBR_ACTIVE);
+
+	print_adjacent_from_adl();
+
+	nlsr->event_build_adj_lsa = ccn_schedule_event(nlsr->sched, 1, &install_adj_lsa, NULL, 0);
+
+	ccn_charbuf_destroy(&nbr);	
 	
 
 }
@@ -308,7 +353,7 @@
 	ccn_charbuf_append_string(nbr,"\0");	
 	printf("Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
 
-	update_adjacent_status_to_adl(nbr,1);
+	//update_adjacent_status_to_adl(nbr,1);
 
 	ccn_charbuf_destroy(&nbr);	
 }
@@ -351,6 +396,9 @@
 	printf("Info Interest Timed out for Neighbor: %s\n",ccn_charbuf_as_string(nbr));
 
 	update_adjacent_timed_out_to_adl(nbr,1);
+
+	print_adjacent_from_adl();	
+
 	int timed_out=get_timed_out_number(nbr);
 	if(timed_out<nlsr->interest_retry && timed_out>0) // use configured variables 
 	{
@@ -540,7 +588,7 @@
 send_lsdb_interest(struct ccn_schedule *sched, void *clienth,
         struct ccn_scheduled_event *ev, int flags)
 {
-
+	my_lock();
 	struct ccn_charbuf *name;
 	long int rnum;
 	char rnumstr[20];
@@ -618,6 +666,7 @@
 
 	nlsr->event_send_lsdb_interest = ccn_schedule_event(nlsr->sched, 60000000, &send_lsdb_interest, NULL, 0);
 
+	my_unlock();
 	return 0;
 
 }
@@ -628,6 +677,7 @@
         struct ccn_scheduled_event *ev, int flags)
 {
 
+	my_lock();
 	struct ccn_charbuf *name;
 	long int rnum;
 	char rnumstr[20];
@@ -708,6 +758,7 @@
 
 	//nlsr->event_send_info_interest = ccn_schedule_event(nlsr->sched, 20000000, &send_info_interest, NULL, 0);
 
+	my_unlock();
 	return 0;
 
 }
@@ -717,6 +768,7 @@
 send_info_interest_to_neighbor(struct ccn_charbuf *nbr)
 {
 
+	my_lock();
 	struct ccn_charbuf *name;
 	long int rnum;
 	char rnumstr[20];
@@ -776,4 +828,6 @@
 	ccn_charbuf_destroy(&templ);
 	ccn_charbuf_destroy(&name);
 
+	my_unlock();
+
 }