#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <assert.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>

#include <ccn/ccn.h>
#include <ccn/uri.h>
#include <ccn/keystore.h>
#include <ccn/signing.h>
#include <ccn/schedule.h>
#include <ccn/hashtb.h>
#include <ccn/sync.h>
#include <ccn/seqwriter.h>

#include "nlsr.h"
#include "nlsr_sync.h"
#include "nlsr_lsdb.h"
#include "utility.h"
#include "nlsr_km.h"
#include "nlsr_km_util.h"


char *
hex_string(unsigned char *s, size_t l)
{
	const char *hex_digits = "0123456789abcdef";
	char *r;
	int i;
	r = calloc(1, 1 + 2 * l);
	for (i = 0; i < l; i++) {
		r[2*i] = hex_digits[(s[i]>>4) & 0xf];
		r[1+2*i] = hex_digits[s[i] & 0xf];
	}
	return(r);
}

/**
* call back function from sync. Receive notification of updates in sync.
* This function calls process_content_from_sync to handle incoming content
* from sync.
*/

int
sync_cb(struct ccns_name_closure *nc,
		struct ccn_charbuf *lhash,
		struct ccn_charbuf *rhash,
		struct ccn_charbuf *name)
{
	nlsr_lock();
	int res;
	struct ccn_charbuf *content_name; 
	struct ccn_indexbuf *content_comps;
	struct ccn_indexbuf *name_comps;
	
	content_comps = ccn_indexbuf_create();
	res = ccn_name_split(name, content_comps);
	if ( res < 0 )
		return 0;
	
	if (content_comps->n < 2)
		return 0;

	content_name = ccn_charbuf_create();
	ccn_name_init(content_name);
	
	res = ccn_name_append_components( content_name,	name->buf,
			content_comps->buf[0], content_comps->buf[content_comps->n - 1]);

	if ( res < 0)
		return 0;

	// for debugging
	struct ccn_charbuf *temp=ccn_charbuf_create();
	ccn_uri_append(temp, content_name->buf, content_name->length, 0);
	if ( nlsr->debugging )
		printf("Name before chopping: %s \n",ccn_charbuf_as_string(temp));
	ccn_charbuf_destroy(&temp);

	name_comps = ccn_indexbuf_create();
	res=ccn_name_split (content_name, name_comps);
	if (res < 0)
		return 0;		

	if ( nlsr->debugging )
	{
		printf("Number of components in name = %d \n",res);
		printf("Number of components in name as indexbuf->n = %d \n",
				(int)name_comps->n);
	}

	ccn_name_chop(content_name, name_comps, -3);
	if ( nlsr->debugging )
		printf("Number of components in name as indexbuf->n after chopping= %d \n"
				, (int)name_comps->n);	

	//for debugging 
	struct ccn_charbuf *temp1=ccn_charbuf_create();
	ccn_uri_append(temp1, content_name->buf, content_name->length, 0);
	if ( nlsr->debugging )
		printf("Name after chopping: %s \n",ccn_charbuf_as_string(temp1));
	ccn_charbuf_destroy(&temp1);

	//main method that processes contents from the sync
	process_content_from_sync(content_name, name_comps);
	
	ccn_charbuf_destroy(&content_name);
	ccn_indexbuf_destroy(&content_comps);
	ccn_indexbuf_destroy(&name_comps);

	nlsr_unlock();
	return(0);
}


/**
* this function retrieve part of name from interest name and put it in name_part
*/

void
get_name_part(struct name_prefix *name_part,struct ccn_charbuf * interest_ccnb, 
		struct ccn_indexbuf *interest_comps, int offset)
{
	int lsa_position=0;
	
	struct ccn_indexbuf *components=ccn_indexbuf_create();
	struct ccn_charbuf *name=ccn_charbuf_create();
	ccn_name_from_uri(name,nlsr->slice_prefix);
	ccn_name_split (name, components);
	lsa_position=components->n-2;
	ccn_charbuf_destroy(&name);

	struct ccn_charbuf *temp=ccn_charbuf_create();
	ccn_name_init(temp);	
	ccn_name_append_components( temp,	interest_ccnb->buf,
								interest_comps->buf[lsa_position+1], 
								interest_comps->buf[interest_comps->n - 1]);

	struct ccn_charbuf *temp1=ccn_charbuf_create();
	ccn_uri_append(temp1, temp->buf, temp->length, 0);

	name_part->name=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1,
																sizeof(char));
	memcpy(name_part->name,ccn_charbuf_as_string(temp1),
										strlen(ccn_charbuf_as_string(temp1)));
	name_part->name[strlen(ccn_charbuf_as_string(temp1))]='\0';
	name_part->length=strlen(ccn_charbuf_as_string(temp1))+1;

	ccn_charbuf_destroy(&temp1);
	ccn_charbuf_destroy(&temp);
	ccn_indexbuf_destroy(&components);

	if ( nlsr->debugging )
		printf("Name Part: %s \n",name_part->name);
	
}


/**
* Get content value by content name and put the content value in content_data
*/


int 
get_content_by_content_name(char *content_name, unsigned char **content_data,
							char *orig_router)
{
	
	int ret=-1;
	struct ccn_charbuf *name = NULL;
	struct ccn_charbuf *templ = NULL;
	struct ccn_charbuf *resultbuf = NULL;
	struct ccn_parsed_ContentObject pcobuf = { 0 };
	int res;
	int allow_stale = 1;
	int content_only = 1;
	int scope = -1;
	const unsigned char *ptr,*ptr_in; 
	size_t length,length_in;
	int resolve_version = CCN_V_HIGHEST;
	int timeout_ms = 3000;
	const unsigned lifetime_default = CCN_INTEREST_LIFETIME_SEC << 12;
	unsigned lifetime_l12 = lifetime_default;
	int get_flags = 0;

	name = ccn_charbuf_create();
	res = ccn_name_from_uri(name,content_name);
	if (res < 0) {
		fprintf(stderr, "Bad ccn URI: %s\n", content_name);
		ccn_charbuf_destroy(&name);
		return ret;
	}

	if (allow_stale || lifetime_l12 != lifetime_default || scope != -1) {
		templ = ccn_charbuf_create();
		ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
		ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
		ccn_charbuf_append_closer(templ); /* </Name> */
		if (allow_stale) {
			ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
			ccnb_append_number(templ,
					CCN_AOK_DEFAULT | CCN_AOK_STALE);
			ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */
		}
		if (scope != -1) {
			ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
		}
		if (lifetime_l12 != lifetime_default) {
			/*
			 * Choose the interest lifetime so there are at least 3
			 * expressions (in the unsatisfied case).
			 */
			unsigned char buf[3] = { 0 };
			int i;
			for (i = sizeof(buf) - 1; i >= 0; i--, lifetime_l12 >>= 8)
				buf[i] = lifetime_l12 & 0xff;
			ccnb_append_tagged_blob(templ, CCN_DTAG_InterestLifetime, buf, 
					sizeof(buf));
		}
		ccn_charbuf_append_closer(templ); /* </Interest> */
	}
	resultbuf = ccn_charbuf_create();
	if (resolve_version != 0) {
		res = ccn_resolve_version(nlsr->ccn, name, resolve_version, 500);
		if (res >= 0) {
			ccn_uri_append(resultbuf, name->buf, name->length, 1);
			resultbuf->length = 0;
		}
	}
	res = ccn_get(nlsr->ccn, name, templ, timeout_ms, resultbuf, &pcobuf, NULL, 
			get_flags);
	if (res >= 0) {
		ptr = resultbuf->buf;
		length = resultbuf->length;
		if (content_only){
			ccn_content_get_value(ptr, length, &pcobuf, &ptr, &length);
			struct ccn_parsed_ContentObject pcobuf1 = { 0 };
			int chk_cont=ccn_parse_ContentObject(ptr,length,&pcobuf1,NULL);
			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);

				if ( res_verify != 0 ){
					if ( nlsr->debugging )
						printf("Error in verfiying keys !! :( \n");
				}
				else{
					if ( nlsr->debugging )
						printf("Key verification is successful :)\n");
					ptr_in=resultbuf->buf;
					length_in=resultbuf->length;
					ccn_content_get_value(ptr_in, length_in, &pcobuf1, 
															&ptr_in, &length_in);
					*content_data = (unsigned char *) calloc(length_in, 
																sizeof(char *));
					memcpy (*content_data, ptr_in, length_in);
					ret=0;
				}
			}
		}
	}

	ccn_charbuf_destroy(&resultbuf);
	ccn_charbuf_destroy(&templ);
	ccn_charbuf_destroy(&name);

	return ret;   
}

/**
* Handle incoming lsa content, Calls functions to install lsa into lsdb
*/

void 
process_incoming_sync_content_lsa( unsigned char *content_data)
{


	if ( nlsr->debugging )
		printf("process_incoming_sync_content_lsa called \n");	

	char *sep="|";
	char *rem;
	char *orig_router;
	char *orl;
	int orig_router_length;
	char *lst;
	int ls_type;
	char *lsid;
	long int ls_id;
	char *isvld;
	int isValid;
	char *num_link;
	int no_link;
	char *np;
	char *np_length;
	int name_length;
	char *data;
	char *orig_time;


	if ( nlsr->debugging )
		printf("LSA Data \n");

	if( strlen((char *)content_data ) > 0 )
	{

		orig_router=strtok_r((char *)content_data,sep,&rem);
		orl=strtok_r(NULL,sep,&rem);
		orig_router_length=atoi(orl);

		if ( nlsr->debugging )
		{
			printf("	Orig Router Name  : %s\n",orig_router);
			printf("	Orig Router Length: %d\n",orig_router_length);
		}

		lst=strtok_r(NULL,sep,&rem);		
		ls_type=atoi(lst);

		if ( nlsr->debugging )
			printf("	LS Type  : %d\n",ls_type);

		if ( ls_type == LS_TYPE_NAME )
		{
			lsid=strtok_r(NULL,sep,&rem);
			ls_id=atoi(lsid);
			orig_time=strtok_r(NULL,sep,&rem);
			isvld=strtok_r(NULL,sep,&rem);
			isValid=atoi(isvld);
			np=strtok_r(NULL,sep,&rem);
			np_length=strtok_r(NULL,sep,&rem);
			name_length=atoi(np_length);
			if ( nlsr->debugging )
			{
				printf("	LS ID  : %ld\n",ls_id);
				printf("	isValid  : %d\n",isValid);
				printf("	Name Prefix : %s\n",np);
				printf("	Orig Time   : %s\n",orig_time);
				printf("	Name Prefix length: %d\n",name_length);
			}

			build_and_install_others_name_lsa(orig_router,ls_type,ls_id,
														orig_time,isValid,np);

			print_name_lsdb();

		}
		else if ( ls_type == LS_TYPE_ADJ )
		{
			orig_time=strtok_r(NULL,sep,&rem);
			num_link=strtok_r(NULL,sep,&rem);
			no_link=atoi(num_link);
			data=rem;

			if ( nlsr->debugging )
			{
				printf("	Orig Time   : %s\n",orig_time);
				printf("	No Link  : %d\n",no_link);
				printf("	Data  : %s\n",data);
			}
			build_and_install_others_adj_lsa(orig_router,ls_type,orig_time,
																no_link,data);
		}
		else if ( ls_type == LS_TYPE_COR )
		{
			orig_time=strtok_r(NULL,sep,&rem);
			char *cor_r=strtok_r(NULL,sep,&rem);
			char *cor_theta=strtok_r(NULL,sep,&rem);

			double r, theta;
			r=strtod(cor_r,NULL);
			theta=strtod(cor_theta,NULL);

			if ( nlsr->debugging )
			{
				printf("	Orig Time   : %s\n",orig_time);
				printf("	Cor R	    : %f\n",r);
				printf("	Cor Theta   : %f\n",theta);
			}
			build_and_install_others_cor_lsa(orig_router,ls_type,orig_time, 
													(double)r, (double)theta);	
		}

	}
}

/**
* Check LSA whether its new. If new retrieve the LSA content and call 
* process_incoming_sync_content_lsa with content_data
*/

void
process_content_from_sync (struct ccn_charbuf *content_name, 
								struct ccn_indexbuf *components)
{
	if (nlsr->debugging)
		printf("process_content_from_sync called \n");
	size_t comp_size;
	char *lst;
	char *lsid;
	const unsigned char *second_last_comp;
	const unsigned char *third_last_comp;
	const unsigned char *origtime;
	char *sep=".";
	char *rem;
	char *second_comp_type;

	int ls_type;
	long int ls_id=0;

	unsigned char *content_data = NULL;

	char *time_stamp=get_current_timestamp_micro_v2();

	struct ccn_charbuf *uri = ccn_charbuf_create();
	ccn_uri_append(uri, content_name->buf, content_name->length, 0);	

	struct name_prefix *orig_router=(struct name_prefix *)
								calloc( 1, sizeof(struct name_prefix));

	ccn_name_comp_get( content_name->buf, components, 
					  components->n-1-2, &second_last_comp, &comp_size);
	
	if (nlsr->debugging)
		printf("2nd Last Component: %s \n", second_last_comp);

	second_comp_type=strtok_r((char *)second_last_comp, sep, &rem);
	if (second_comp_type == NULL || rem == NULL)
	{
		printf ("Error: unable to tokenize the string: %s, calling exit()\n",
													(char *)second_last_comp); 
		exit(0);
	}

	if ( strcmp( second_comp_type, "lsId" ) == 0 )
	{	
		lsid=rem;
		ls_id=atoi(rem);
		ccn_name_comp_get(content_name->buf, components,components->n-2-2,
												&third_last_comp, &comp_size);
		lst=strtok_r((char *)third_last_comp,sep,&rem);
		lst=rem;
		ls_type=atoi(lst);
		ccn_name_comp_get(content_name->buf, components,components->n-2,
														&origtime, &comp_size);
		ccn_name_chop(content_name,components,-3);
		get_name_part(orig_router,content_name,components,0);

		if ( nlsr->debugging )
			printf("Orig Router: %s Ls Type: %d Ls id: %ld Orig Time: %s\n",
									orig_router->name,ls_type,ls_id,origtime);

		int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
		if ( nlsr->debugging )
			printf("LSA Life time: %d\n",lsa_life_time);

		if ( strcmp(orig_router->name,nlsr->router_name) != 0 
				&& (lsa_life_time < nlsr->router_dead_interval) )
		{
			int is_new_name_lsa=check_is_new_name_lsa(orig_router->name,
									(char *)lst,(char *)lsid,(char *)origtime);
			if ( is_new_name_lsa == 1 )
			{
				if ( nlsr->debugging )
					printf("New NAME LSA.....\n");	
				int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);
				if ( chk_con == 0 ){
					if ( nlsr->debugging )
						printf("Content Data: %s \n",content_data);
					process_incoming_sync_content_lsa(content_data);
				}
				else{
					if ( nlsr->debugging )
						printf("Verification failed. No content given back\n");
				}
			}
			else 
			{
				if ( nlsr->debugging )
					printf("Name LSA / Newer Name LSA already xists in LSDB\n");
				int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri)
											, &content_data,orig_router->name);

				if ( chk_con == 0 ){
					if ( nlsr->debugging )
						printf("Content Data: %s \n",content_data);
					process_incoming_sync_content_lsa(content_data);
				}
				else{
					if ( nlsr->debugging )
						printf("Verification failed. No content given back\n");
				}
			}
		}
		else 
		{
			if ( nlsr->debugging )
				printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
		}
	}
	else
	{
		ls_type=atoi(rem);
		lst=rem;
		if(ls_type == LS_TYPE_ADJ)
		{
			ccn_name_comp_get(content_name->buf, components,components->n-2, 
														&origtime, &comp_size);
			ccn_name_chop(content_name,components,-2);
			get_name_part(orig_router,content_name,components,0);

			if ( nlsr->debugging )
				printf("Orig Router: %s Ls Type: %d Orig Time: %s\n",
											orig_router->name,ls_type,origtime);

			int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
			if ( nlsr->debugging )
				printf("LSA Life time: %d\n",lsa_life_time);

			if ( strcmp(orig_router->name,nlsr->router_name) != 0 
				&& (lsa_life_time < nlsr->router_dead_interval) )
			{
				int is_new_adj_lsa = check_is_new_adj_lsa( orig_router->name, 
													(char *)lst, (char *)origtime);
				if ( is_new_adj_lsa == 1 )
				{
					if ( nlsr->debugging )
						printf("New Adj LSA.....\n");	
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);

					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}		
				}
				else
				{
					if ( nlsr->debugging )
						printf("Adj LSA / Newer Adj LSA already exists in LSDB\n");
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);
					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}
				}
			}
			else 
			{
				if ( nlsr->debugging )
					printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
			}
		}
		else if(ls_type == LS_TYPE_COR)
		{
			ccn_name_comp_get(content_name->buf, components, components->n-2, 
														&origtime, &comp_size);
			ccn_name_chop(content_name,components,-2);
			get_name_part(orig_router,content_name,components,0);

			if ( nlsr->debugging )
				printf("Orig Router: %s Ls Type: %d Orig Time: %s\n", 
											orig_router->name,ls_type,origtime);

			int lsa_life_time=get_time_diff(time_stamp,(char *)origtime);
			if ( nlsr->debugging )
				printf("LSA Life time: %d\n",lsa_life_time);

			if ( strcmp(orig_router->name,nlsr->router_name) != 0 
				&& (lsa_life_time < nlsr->router_dead_interval) )	
			{
				int is_new_cor_lsa=check_is_new_cor_lsa( orig_router->name, 
												(char *)lst,(char *) origtime);
				if ( is_new_cor_lsa == 1 )
				{
					if ( nlsr->debugging )
						printf("New Cor LSA.....\n");	
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
																&content_data,
															orig_router->name);

					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}		
				}
				else
				{
					if ( nlsr->debugging )
						printf("Cor LSA / Newer Cor LSA already exists in LSDB\n");
					int chk_con=get_content_by_content_name(ccn_charbuf_as_string(uri), 
												&content_data,orig_router->name);
					if ( chk_con == 0 ){
						if ( nlsr->debugging )
							printf("Content Data: %s \n",content_data);
						process_incoming_sync_content_lsa(content_data);
					}
					else{
						if ( nlsr->debugging )
							printf("Verification failed. No content given back\n");
					}
				}
			}
			else 
			{	
				if ( nlsr->debugging )
					printf("Lsa is older than Router LSA refresh time/ Dead Interval\n");
			}

		}
	}

	if(content_data)
		free(content_data);

	if (orig_router->name)
		free(orig_router->name);
	if (orig_router)
		free(orig_router);
	ccn_charbuf_destroy(&uri);
	//01/31/2013	
	free(time_stamp);
}

/**
* This function performs same functionality as ccnsyncwatch
*/


int
sync_monitor(char *topo_prefix, char *slice_prefix)
{

	struct ccn_charbuf *prefix = ccn_charbuf_create();
	struct ccn_charbuf *topo = ccn_charbuf_create(); 
	
	nlsr->closure=(struct ccns_name_closure *) 
						calloc(1,sizeof(struct ccns_name_closure)); // leak

	nlsr->slice = ccns_slice_create();

	ccn_charbuf_reset(prefix);
	ccn_name_from_uri(prefix, slice_prefix);

	ccn_charbuf_reset(topo);
	ccn_name_from_uri(topo, topo_prefix);

	ccns_slice_set_topo_prefix(nlsr->slice, topo, prefix);
	nlsr->closure->callback = &sync_cb;
	nlsr->ccns = ccns_open(nlsr->ccn, nlsr->slice, nlsr->closure, NULL, NULL);

	ccn_charbuf_destroy(&prefix);
	ccn_charbuf_destroy(&topo);
	return 0;
}

struct ccn_charbuf *
make_template(int scope)
{
	struct ccn_charbuf *templ = NULL;
	templ = ccn_charbuf_create();
	ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG);
	ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG);
	ccn_charbuf_append_closer(templ); /* </Name> */
	if (0 <= scope && scope <= 2)
		ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
	ccn_charbuf_append_closer(templ); /* </Interest> */
	return(templ);
}

/**
* Write signed data to repo
*/


int
write_data_to_repo(char *data, char *name_prefix)
{

	nlsr_lock();
	if ( nlsr->debugging )
	{
		printf("write_data_to_repo called\n");
		printf("Content Name: %s \n",name_prefix);
		printf("Content Data: %s \n",data);
	}

	struct ccn *temp_ccn;
	temp_ccn=ccn_create();
	int ccn_fd=ccn_connect(temp_ccn, NULL);
	if(ccn_fd == -1)
	{
		fprintf(stderr,"Could not connect to ccnd for Data Writing\n");
		writeLogg(__FILE__,__FUNCTION__,__LINE__, 
						"Could not connect to ccnd for Data Writing\n");
		return -1;
	}

	struct ccn_charbuf *name = NULL;
	struct ccn_seqwriter *w = NULL;
	int blocksize = 4096;
	int freshness = -1;
	int scope = 1;
	int res;
	size_t blockread;
	struct ccn_charbuf *templ;

	name = ccn_charbuf_create();
	res = ccn_name_from_uri(name, name_prefix);
	if (res < 0) {
		fprintf(stderr, "bad CCN URI: %s\n",name_prefix);
		return -1;
	}

	w = ccn_seqw_create(temp_ccn, name);
	if (w == NULL) {
		fprintf(stderr, "ccn_seqw_create failed\n");
		return -1;
	}
	ccn_seqw_set_block_limits(w, blocksize, blocksize);
	if (freshness > -1)
		ccn_seqw_set_freshness(w, freshness);

	struct ccn_charbuf *name_v = ccn_charbuf_create();
	ccn_seqw_get_name(w, name_v);
	ccn_name_from_uri(name_v, "%C1.R.sw");
	ccn_name_append_nonce(name_v);
	templ = make_template(scope);
	res = ccn_get(temp_ccn, name_v, templ, 60000, NULL, NULL, NULL, 0);
	ccn_charbuf_destroy(&templ);
	ccn_charbuf_destroy(&name_v);
	if (res < 0) {
		fprintf(stderr, "No response from repository\n");
		return -1;
	}

	struct ccn_charbuf *resultbuf=ccn_charbuf_create();

	sign_content_with_user_defined_keystore(name,
										resultbuf,
										data,
										strlen(data),
										nlsr->keystore_path,
										nlsr->keystore_passphrase,
										nlsr->root_key_prefix,
										nlsr->site_name,
										nlsr->router_name);	


	blockread=resultbuf->length;

	if (blockread > 0) {
		res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);	
		while (res == -1) {
			ccn_run(temp_ccn,1);
			res = ccn_seqw_write(w, resultbuf->buf, resultbuf->length);	
		}
	}

	ccn_seqw_close(w);
	ccn_run(temp_ccn, 1);
	ccn_charbuf_destroy(&name);
	ccn_destroy(&temp_ccn);
	ccn_charbuf_destroy(&resultbuf);

	nlsr_unlock();
	return 0;
}

/**
*	Create slice for sync/repo
*/


int
create_sync_slice(char *topo_prefix, char *slice_prefix)
{
	int res;
	struct ccn *handle; 
	struct ccns_slice *slice;
	struct ccn_charbuf *prefix = ccn_charbuf_create();
	struct ccn_charbuf *topo = ccn_charbuf_create();
	struct ccn_charbuf *clause = ccn_charbuf_create();
	struct ccn_charbuf *slice_name = ccn_charbuf_create();
	struct ccn_charbuf *slice_uri = ccn_charbuf_create();

	if (prefix == NULL || topo == NULL || clause == NULL ||
			slice_name == NULL || slice_uri == NULL) {
		fprintf(stderr, "Unable to allocate required memory.\n");
		return -1;
	}

	handle = ccn_create();
	res = ccn_connect(handle, NULL);
	if (0 > res) {
		fprintf(stderr, "Unable to connect to ccnd.\n");
		return -1;
	}    

	slice = ccns_slice_create();

	ccn_charbuf_reset(topo);
	ccn_name_from_uri(topo, topo_prefix);
	ccn_charbuf_reset(prefix);
	ccn_name_from_uri(prefix,slice_prefix );
	ccns_slice_set_topo_prefix(slice, topo, prefix);


	res = ccns_write_slice(handle, slice, slice_name);

	//01/31/2013
	ccns_slice_destroy(&slice);
	ccn_destroy(&handle);
	ccn_charbuf_destroy(&prefix);
	ccn_charbuf_destroy(&topo);
	ccn_charbuf_destroy(&clause);
	ccn_charbuf_destroy(&slice_name);
	ccn_charbuf_destroy(&slice_uri);

	return 0;
}


