Example #1
0
static struct ccn_charbuf *
resolve_templ(struct ccn_charbuf *templ, unsigned const char *vcomp, int size)
{
    if (templ == NULL)
        templ = ccn_charbuf_create();
    if (size < 3 || size > 16) {
        ccn_charbuf_destroy(&templ);
        return(NULL);
    }
    templ->length = 0;
    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> */
    ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
    append_filter_all(templ);
    ccn_charbuf_append_tt(templ, CCN_DTAG_Component, CCN_DTAG);
    ccn_charbuf_append_tt(templ, size, CCN_BLOB);
    ccn_charbuf_append(templ, vcomp, size);
    ccn_charbuf_append_closer(templ); /* </Component> */
    append_future_vcomp(templ);
    append_filter_all(templ);
    ccn_charbuf_append_closer(templ); /* </Exclude> */
    answer_highest(templ);
    answer_passive(templ);
    ccn_charbuf_append_closer(templ); /* </Interest> */
    return(templ);
}
Example #2
0
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));
		}
Example #3
0
int build_keylocator_from_key(struct ccn_charbuf** keylocator, struct ccn_pkey* key) {
	int res = 0;
	*keylocator = ccn_charbuf_create();
	ccn_charbuf_append_tt(*keylocator, CCN_DTAG_KeyLocator, CCN_DTAG);
	ccn_charbuf_append_tt(*keylocator, CCN_DTAG_Key, CCN_DTAG);
	res = ccn_append_pubkey_blob(*keylocator, key);
	ccn_charbuf_append_closer(*keylocator); /* </Key> */
	ccn_charbuf_append_closer(*keylocator); /* </KeyLocator> */
	return (res);
}
Example #4
0
/*
 * initialize local data
 */
void init_data(struct ccn_charbuf *local_scope_template,
        struct ccn_charbuf *no_name)
{
    ccn_charbuf_append_tt(local_scope_template, CCN_DTAG_Interest, CCN_DTAG);
    ccn_charbuf_append_tt(local_scope_template, CCN_DTAG_Name, CCN_DTAG);
    ccn_charbuf_append_closer(local_scope_template);    /* </Name> */
    ccnb_tagged_putf(local_scope_template, CCN_DTAG_Scope, "1");
    ccn_charbuf_append_closer(local_scope_template);    /* </Interest> */

    ccn_name_init(no_name);
}
Example #5
0
struct ccn_charbuf* CcnH_localScopeTempl(void) {
	if (CcnH_localScopeTempl_inst == NULL) {
		CcnH_localScopeTempl_inst = ccn_charbuf_create();
		ccn_charbuf_append_tt(CcnH_localScopeTempl_inst, CCN_DTAG_Interest, CCN_DTAG);
		ccn_charbuf_append_tt(CcnH_localScopeTempl_inst, CCN_DTAG_Name, CCN_DTAG);
		ccn_charbuf_append_closer(CcnH_localScopeTempl_inst);
		ccnb_tagged_putf(CcnH_localScopeTempl_inst, CCN_DTAG_Scope, "1");
		ccn_charbuf_append_closer(CcnH_localScopeTempl_inst);
	}
	return CcnH_localScopeTempl_inst;
}
Example #6
0
static struct ccn_charbuf *
create_passive_templ(void)
{
    struct ccn_charbuf *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> */
    answer_passive(templ);
    ccn_charbuf_append_closer(templ); /* </Interest> */
    return(templ);
}
Example #7
0
File: ccnrm.c Project: futtre/ccnx
/***********
<Interest>
  <Name/>
  <AnswerOriginKind>19</AnswerOriginKind>
  <Scope>0</Scope>
</Interest>
**********/
struct ccn_charbuf *
local_scope_rm_template(void)
{
    struct ccn_charbuf *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> */
    ccnb_tagged_putf(templ, CCN_DTAG_AnswerOriginKind, "%2d",
                     (CCN_AOK_EXPIRE | CCN_AOK_DEFAULT));
    ccnb_tagged_putf(templ, CCN_DTAG_Scope, "0");
    ccn_charbuf_append_closer(templ); /* </Interest> */
    return(templ);
}
Example #8
0
/*
 * make_template: construct an interest template containing the specified scope
 *     An unlimited scope is passed in as 3, and the omission of the scope
 *     field from the template indicates this.
 */
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);
}
Example #9
0
static struct ccn_charbuf *
make_data_template(int maxSuffix) {
	// creates a template for interests that only have a name
	// and a segment number
	struct ccn_charbuf *cb = ccn_charbuf_create();
    ccn_charbuf_append_tt(cb, CCN_DTAG_Interest, CCN_DTAG);
    ccn_charbuf_append_tt(cb, CCN_DTAG_Name, CCN_DTAG);
    ccn_charbuf_append_closer(cb); /* </Name> */
    ccn_charbuf_append_tt(cb, CCN_DTAG_MaxSuffixComponents, CCN_DTAG);
    ccnb_append_number(cb, maxSuffix);
    ccn_charbuf_append_closer(cb); /* </MaxSuffixComponents> */
    ccn_charbuf_append_closer(cb); /* </Interest> */
    return(cb);
}
Example #10
0
int NdnMediaProcess::checkInterest()
{
    int res = 0;
    QHash<QString,UserDataBuf *>::iterator it; 
	ruMutex->lock();
    for ( it = qhRemoteUser.begin(); it != qhRemoteUser.end(); ++it ) {
        if (!it.value()->interested) {
            /* Use a template to express our order preference for the first packet. */
            struct ccn_charbuf *templ = ccn_charbuf_create();
            struct ccn_charbuf *path = 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);
            ccn_charbuf_append_tt(templ, CCN_DTAG_ChildSelector, CCN_DTAG);
            ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
            ccn_charbuf_append(templ, "1", 1);	/* low bit 1: rightmost */
            ccn_charbuf_append_closer(templ); /*<ChildSelector>*/
            ccn_charbuf_append_closer(templ);
			ccn_name_from_uri(path, it.key().toLocal8Bit().constData());
			ccn_name_append_str(path, "audio");
            if (res >= 0) {
                if (it.value()->data_buf.callback->p == NULL) {fprintf(stderr, "data_buf.callback is NULL!\n"); exit(1); }
				/*
				int c = 0;
				while (pthread_mutex_trylock(&ccn_mutex) != 0) {
					c++;
					if (c > 10000000) {
						fprintf(stderr, "cannot obtain lock! %s:%d\n", __FILE__, __LINE__);
						std::exit(1);
					}
				}
				*/
				pthread_mutex_lock(&ccn_mutex);
                res = ccn_express_interest(ndnState.ccn, path, it.value()->data_buf.callback, templ);
				pthread_mutex_unlock(&ccn_mutex);
                it.value()->interested = 1;
				fprintf(stderr, "short interest sent\n");
            }
            if (res < 0) {
				fprintf(stderr, "sending the first interest failed\n");
				exit(1);
			}
            ccn_charbuf_destroy(&path);
            ccn_charbuf_destroy(&templ);
        }
    }
	ruMutex->unlock();
    return res;
}
Example #11
0
struct ccn_charbuf *make_template(int allow_caching) {
    if (!allow_caching) {
        struct ccn_charbuf *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> */
        ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
        ccnb_append_number(templ, CCN_AOK_NEW);
        ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */
        ccn_charbuf_append_closer(templ); /* </Interest> */
        return(templ);
    }

    return NULL;
}
Example #12
0
static int
ccn_create_keylocator(ccn_charbuf *c, const ccn_pkey *k)
{
    int res;
    ccn_charbuf_append_tt(c, CCN_DTAG_KeyLocator, CCN_DTAG);
    ccn_charbuf_append_tt(c, CCN_DTAG_Key, CCN_DTAG);
    res = ccn_append_pubkey_blob(c, k);
    if (res < 0)
        return (res);
    else {
        ccn_charbuf_append_closer(c); /* </Key> */
        ccn_charbuf_append_closer(c); /* </KeyLocator> */
    }
    return (0);
}
Example #13
0
struct ccn_charbuf *
make_connect_template()
{
    struct ccn_charbuf *templ = ccn_charbuf_create();
    ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); /* <Interest> */
    ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); /* <Name> */
    ccn_charbuf_append_closer(templ); /* </Name> */

    ccn_charbuf_append_tt(templ, CCN_DTAG_ChildSelector, CCN_DTAG);
    ccnb_append_number(templ,1);
    ccn_charbuf_append_closer(templ);

    ccn_charbuf_append_closer(templ); /* </Interest> */
    return templ;
}
Example #14
0
static PyObject *
Signature_obj_to_ccn(PyObject *py_obj_Signature)
{
	struct ccn_charbuf *signature;
	PyObject *py_signature;
	int r;

	debug("Signature_to_ccn starts \n");

	py_signature = CCNObject_New_charbuf(SIGNATURE, &signature);
	JUMP_IF_NULL(py_signature, error);

	r = ccn_charbuf_append_tt(signature, CCN_DTAG_Signature, CCN_DTAG);
	JUMP_IF_NEG_MEM(r, error);

	r = append_digest_algorithm(signature, py_obj_Signature);
	JUMP_IF_NEG(r, error);

	r = append_witness(signature, py_obj_Signature);
	JUMP_IF_NEG(r, error);

	r = append_signature_bits(signature, py_obj_Signature);
	JUMP_IF_NEG(r, error);

	r = ccn_charbuf_append_closer(signature); /* </Signature> */
	JUMP_IF_NEG_MEM(r, error);

	return py_signature;

error:
	Py_XDECREF(py_signature);
	return NULL;
}
Example #15
0
static int
process_int_attribute(struct ccn_charbuf *interest, enum ccn_dtag tag,
		PyObject *py_obj_Interest, const char *attr_name)
{
	PyObject *py_attr;
	int val, r;

	r = is_attr_set(py_obj_Interest, attr_name, &py_attr);
	if (r <= 0)
		return r;

	val = _pyccn_Int_AsLong(py_attr);
	Py_DECREF(py_attr);
	if (PyErr_Occurred())
		return -1;

#if 0
	r = ccn_charbuf_append_tt(interest, tag, CCN_DTAG);
	JUMP_IF_NEG_MEM(r, error);

	r = ccnb_append_number(interest, val);
	JUMP_IF_NEG_MEM(r, error);

	r = ccn_charbuf_append_closer(interest); /* </Tag> */
	JUMP_IF_NEG_MEM(r, error);
#endif

	r = ccnb_tagged_putf(interest, tag, "%d", val);
	JUMP_IF_NEG_MEM(r, error);

	return 1;
error:
	return -1;
}
Example #16
0
/**
 * Append AnswerOriginKind=1 to partially constructed Interest, meaning
 * do not generate new content.
 */
static void
answer_passive(struct ccn_charbuf *templ)
{
    ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
    ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
    ccn_charbuf_append(templ, "1", 1);
    ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */
}
Example #17
0
static void
append_future_vcomp(struct ccn_charbuf *templ)
{
    /* One beyond a distant future version stamp */
    unsigned char b[7] = {CCN_MARKER_VERSION + 1, 0, 0, 0, 0, 0, 0};
    ccn_charbuf_append_tt(templ, CCN_DTAG_Component, CCN_DTAG);
    ccn_charbuf_append_tt(templ, sizeof(b), CCN_BLOB);
    ccn_charbuf_append(templ, b, sizeof(b));
    ccn_charbuf_append_closer(templ); /* </Component> */
}
Example #18
0
struct ccn_charbuf *
make_template(struct mydata *md)
{
    struct ccn_charbuf *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> */
    // XXX - use pubid if possible
    ccn_charbuf_append_tt(templ, CCN_DTAG_MaxSuffixComponents, CCN_DTAG);
    ccnb_append_number(templ, 1);
    ccn_charbuf_append_closer(templ); /* </MaxSuffixComponents> */
    if (md->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> */
    }
    ccn_charbuf_append_closer(templ); /* </Interest> */
    return(templ);
}
/**
* Creates a template for ccn interest fetch
*
* @param allow_stale
* @param scope
*/
struct ccn_charbuf* CCNGet::make_template(int allow_stale, int scope)
{
	struct ccn_charbuf *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> */
	ccn_charbuf_append_tt(templ, CCN_DTAG_MaxSuffixComponents, CCN_DTAG);
	ccnb_append_number(templ, 1);
	ccn_charbuf_append_closer(templ); /* </MaxSuffixComponents> */
	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 >= 0 && scope <= 2) {
		ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
	}
	ccn_charbuf_append_closer(templ); /* </Interest> */
	return(templ);
}
Example #20
0
/*
 * This appends a tagged, valid, fully-saturated Bloom filter, useful for
 * excluding everything between two 'fenceposts' in an Exclude construct.
 */
static void
append_bf_all(struct ccn_charbuf *c)
{
    unsigned char bf_all[9] = { 3, 1, 'A', 0, 0, 0, 0, 0, 0xFF };
    const struct ccn_bloom_wire *b = ccn_bloom_validate_wire(bf_all, sizeof(bf_all));
    if (b == NULL) abort();
    ccn_charbuf_append_tt(c, CCN_DTAG_Bloom, CCN_DTAG);
    ccn_charbuf_append_tt(c, sizeof(bf_all), CCN_BLOB);
    ccn_charbuf_append(c, bf_all, sizeof(bf_all));
    ccn_charbuf_append_closer(c);
}
Example #21
0
static void
append_bloom_element(struct ccn_charbuf *templ,
                     enum ccn_dtag dtag, struct ccn_bloom *b)
{
        int i;
        ccn_charbuf_append_tt(templ, dtag, CCN_DTAG);
        i = ccn_bloom_wiresize(b);
        ccn_charbuf_append_tt(templ, i, CCN_BLOB);
        ccn_bloom_store_wire(b, ccn_charbuf_reserve(templ, i), i);
        templ->length += i;
        ccn_charbuf_append_closer(templ);
}
Example #22
0
/*
 * Construct and send a new interest that uses the exclusion list.
 * Return -1 if not sent because of packet size, 0 for success.
 */
static int
express_my_interest(struct ccn *h,
                    struct ccn_closure *selfp,
                    struct ccn_charbuf *name)
{
    int ans;
    struct ccn_charbuf *templ = NULL;
    int i;
    struct upcalldata *data = get_my_data(selfp);

    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> */
    ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG);
    if ((data->flags & EXCLUDE_LOW) != 0)
        append_bf_all(templ);
    for (i = 0; i < data->n_excl; i++) {
        struct ccn_charbuf *comp = data->excl[i];
        if (comp->length < 4) abort();
        ccn_charbuf_append(templ, comp->buf + 1, comp->length - 2);
    }
    if ((data->flags & EXCLUDE_HIGH) != 0)
        append_bf_all(templ);
    ccn_charbuf_append_closer(templ); /* </Exclude> */
    answer_passive(templ);
    ccn_charbuf_append_closer(templ); /* </Interest> */
    if (templ->length + name->length > data->warn + 2) {
        fprintf(stderr, "*** Interest packet is %d bytes\n", (int)templ->length);
        data->warn = data->warn * 8 / 5;
    }
    if (templ->length + name->length > 1450 && data->n_excl > 3)
        ans = -1;
    else {
        ccn_express_interest(h, name, selfp, templ);
        ans = 0;
    }
    ccn_charbuf_destroy(&templ);
    return(ans);
}
Example #23
0
static void
express_bulkdata_interest(struct ccn *h, struct pending *p)
{
    int res;
    struct bulkdata *b = NULL;
    int prefix_comps = -1;
    int addl_comps = -1;
    struct ccn_charbuf *name = NULL;
    struct ccn_charbuf *templ = NULL;
    struct ccn_charbuf *seq = NULL;
    
    b = p->parent;
    if (b == NULL)
        return;
    name = ccn_charbuf_create();
    templ = ccn_charbuf_create();
    seq = ccn_charbuf_create();

    ccn_charbuf_append(name, b->name_prefix->buf, b->name_prefix->length);
    
    seq->length = 0;
    (*b->seqfunc)(p->x, b->seqfunc_param, seq);
    ccn_name_append(name, seq->buf, seq->length);
    prefix_comps = -1;
    addl_comps = 1;
    
    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> */

    // XXX - may want to set Min/MaxSuffixComponents
    
    ccn_charbuf_append_closer(templ); /* </Interest> */
    res = ccn_express_interest(h, name, &p->closure, templ);
    assert(res >= 0); // XXX - handle this better
    ccn_charbuf_destroy(&name);
    ccn_charbuf_destroy(&templ);
    ccn_charbuf_destroy(&seq);
}
Example #24
0
/************************************************
* Text
************************************************/
int NdnMediaProcess::fetchNdnText()
{
    int res = 0;
    QHash<QString,UserDataBuf *>::iterator it; 
	ruMutex->lock();
    for ( it = qhRemoteUser.begin(); it != qhRemoteUser.end(); ++it ) {
        if (!it.value()->texted) {
            struct ccn_charbuf *templ = ccn_charbuf_create();
            struct ccn_charbuf *path = 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);
            ccn_charbuf_append_tt(templ, CCN_DTAG_ChildSelector, CCN_DTAG);
            ccn_charbuf_append_tt(templ, 1, CCN_UDATA);
            ccn_charbuf_append(templ, "1", 1);	/* low bit 1: rightmost */
            ccn_charbuf_append_closer(templ); /*<ChildSelector>*/
            ccn_charbuf_append_closer(templ);
			ccn_name_from_uri(path, it.key().toLocal8Bit().constData());
			ccn_name_append_str(path, "text");
            if (res >= 0) {
                if (it.value()->data_buf.text_callback->p == NULL) {fprintf(stderr, "data_buf.text_callback is NULL!\n"); exit(1); }
				pthread_mutex_lock(&ccn_mutex);
                res = ccn_express_interest(ndnState.ccn, path, it.value()->data_buf.text_callback, templ);
				pthread_mutex_unlock(&ccn_mutex);
                it.value()->texted = 1;
				fprintf(stderr, "short interest sent\n");
            }
            if (res < 0) {
				fprintf(stderr, "sending the first interest failed\n");
				exit(1);
			}
            ccn_charbuf_destroy(&path);
            ccn_charbuf_destroy(&templ);
        }
    }
	ruMutex->unlock();
    return res;
}
Example #25
0
static int
ccn_encode_Signature(struct ccn_charbuf *buf,
                     const char *digest_algorithm,
                     const void *witness,
                     size_t witness_size,
                     const struct ccn_signature *signature,
                     size_t signature_size)
{
    int res = 0;

    if (signature == NULL)
        return(-1);

    res |= ccn_charbuf_append_tt(buf, CCN_DTAG_Signature, CCN_DTAG);

    if (digest_algorithm != NULL) {
        res |= ccn_charbuf_append_tt(buf, CCN_DTAG_DigestAlgorithm, CCN_DTAG);
        res |= ccn_charbuf_append_tt(buf, strlen(digest_algorithm), CCN_UDATA);
        res |= ccn_charbuf_append_string(buf, digest_algorithm);
        res |= ccn_charbuf_append_closer(buf);
    }

    if (witness != NULL) {
        res |= ccn_charbuf_append_tt(buf, CCN_DTAG_Witness, CCN_DTAG);
        res |= ccn_charbuf_append_tt(buf, witness_size, CCN_BLOB);
        res |= ccn_charbuf_append(buf, witness, witness_size);
        res |= ccn_charbuf_append_closer(buf);
    }

    res |= ccn_charbuf_append_tt(buf, CCN_DTAG_SignatureBits, CCN_DTAG);
    res |= ccn_charbuf_append_tt(buf, signature_size, CCN_BLOB);
    res |= ccn_charbuf_append(buf, signature, signature_size);
    res |= ccn_charbuf_append_closer(buf);
    
    res |= ccn_charbuf_append_closer(buf);

    return(res == 0 ? 0 : -1);
}
Example #26
0
/***********************************
 * Append a StatusResponse
 * 
 *  @param buf is the buffer to append to.
 *  @param errcode is a 3-digit error code.
 *            It should be documented in StatusResponse.txt.
 *  @param errtext is human-readable text (may be NULL).
 *  @returns 0 for success or -1 for error.
 */
int
ccn_encode_StatusResponse(struct ccn_charbuf *buf,
                          int errcode, const char *errtext)
{
    int res = 0;
    if (errcode < 100 || errcode > 999)
        return(-1);
    res |= ccn_charbuf_append_tt(buf, CCN_DTAG_StatusResponse, CCN_DTAG);
    res |= ccnb_tagged_putf(buf, CCN_DTAG_StatusCode, "%d", errcode);
    if (errtext != NULL && errtext[0] != 0)
        res |= ccnb_tagged_putf(buf, CCN_DTAG_StatusText, "%s", errtext);
    res |= ccn_charbuf_append_closer(buf);
    return(res);
}
Example #27
0
/**
 * Append a representation of a Link to a charbuf.
 * @param buf is the output buffer where encoded link is written.
 * @param name is the ccnb-encoded name from ccn_name_init and friends.
 * @param label is a UTF-8 string in a ccn_charbuf.
 * @param linkAuthenticator is the ccnb-encoded LinkAuthenticator.
 * @returns 0 for success or -1 for error.
 */
int
ccnb_append_Link(struct ccn_charbuf *buf,
                 const struct ccn_charbuf *name,
                 const char *label,
                 const struct ccn_charbuf *linkAuthenticator
                 )
{
    int res = 0;
    
    res |= ccn_charbuf_append_tt(buf, CCN_DTAG_Link, CCN_DTAG);
    res |= ccn_charbuf_append_charbuf(buf, name);
    if (label != NULL) {
        res |= ccn_charbuf_append_tt(buf, CCN_DTAG_Label, CCN_DTAG);
        res |= ccn_charbuf_append_tt(buf, strlen(label), CCN_UDATA);
        res |= ccn_charbuf_append_string(buf, label);
        res |= ccn_charbuf_append_closer(buf);
    }
    if (linkAuthenticator != NULL) {
        res |= ccn_charbuf_append_charbuf(buf, linkAuthenticator);
    }
    res |= ccn_charbuf_append_closer(buf);
    return(res == 0 ? 0 : -1);
}
Example #28
0
void CcnCC_sendContent(CcnCC self, struct ccn_charbuf* name, TimeSpan expires, void* data, size_t size) {
	struct ccn_signing_params sp = CCN_SIGNING_PARAMS_INIT;
	if (expires >= 0) {
		sp.template_ccnb = ccn_charbuf_create();
		ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_SignedInfo, CCN_DTAG);
		ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", expires / 1000);
		sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS;
		ccn_charbuf_append_closer(sp.template_ccnb);
	}
	struct ccn_charbuf* content = ccn_charbuf_create();
	if (0 == ccn_sign_content(self->ccnh, content, name, &sp, data, size)) {
		ccn_put(self->ccnh, content->buf, content->length);
	}
	ccn_charbuf_destroy(&sp.template_ccnb);
	ccn_charbuf_destroy(&content);
}
Example #29
0
/**
 * Append a tagged BLOB
 *
 * This is a ccnb-encoded element with containing the BLOB as content
 * @param c is the buffer to append to.
 * @param dtag is the element's dtab
 * @param data points to the binary data
 * @param size is the size of the data, in bytes
 * @returns 0 for success or -1 for error.
 */
int
ccnb_append_tagged_blob(struct ccn_charbuf *c,
                        enum ccn_dtag dtag,
                        const void *data,
                        size_t size)
{
    int res;

    res = ccn_charbuf_append_tt(c, dtag, CCN_DTAG);
    if (size != 0) {
        res |= ccn_charbuf_append_tt(c, size, CCN_BLOB);
        res |= ccn_charbuf_append(c, data, size);
    }
    res |= ccn_charbuf_append_closer(c);
    return(res == 0 ? 0 : -1);
}
// replace_name()
// Helper function to replace names in content objects
// Could build another version that works on already parsed content objects
// But as seen below it would be better to use a modified encoding call that
// didn't include the name at all.
//
int replace_name(struct ccn_charbuf* dest, unsigned char* src,  size_t src_size, struct ccn_charbuf* name) {
	struct ccn_parsed_ContentObject* pco = (struct ccn_parsed_ContentObject*) calloc(sizeof(struct ccn_parsed_ContentObject), 1);
	int res = 0;
	res = ccn_parse_ContentObject(src,src_size, pco, NULL);
    if (res < 0) {
    	free(pco);
    	return (res);
    }
	ccn_charbuf_append_tt(dest, CCN_DTAG_ContentObject, CCN_DTAG);
	ccn_charbuf_append(dest, &src[pco->offset[CCN_PCO_B_Signature]], pco->offset[CCN_PCO_E_Signature] - pco->offset[CCN_PCO_B_Signature]);
	ccn_charbuf_append_charbuf(dest, name); // Already tagged
	ccn_charbuf_append(dest, &src[pco->offset[CCN_PCO_B_SignedInfo]], pco->offset[CCN_PCO_E_SignedInfo] - pco->offset[CCN_PCO_B_SignedInfo]);
	ccnb_append_tagged_blob(dest, CCN_DTAG_Content, NULL, 0);
	ccn_charbuf_append_closer(dest);
	free(pco);
	return (0);
}