struct ccn_proxy * ccn_proxy_init(const char *filter_uri, const char *prefix_uri) { struct ccn_proxy *proxy = calloc(1, sizeof(struct ccn_proxy)); struct ccn_buf_decoder decoder; struct ccn_buf_decoder *d = &decoder; int res; DEBUG_PRINT("IN %d %s\n", __LINE__, __func__); /* Convert URI to name this proxy is responsible for */ proxy->prefix = ccn_charbuf_create(); res = ccn_name_from_uri(proxy->prefix, prefix_uri); if (res < 0) { DEBUG_PRINT("ABORT %d %s bad ccn URI: %s\n", __LINE__, __func__, prefix_uri); abort(); } d = ccn_buf_decoder_start(d, proxy->prefix->buf, proxy->prefix->length); proxy->prefix_comps = ccn_indexbuf_create(); proxy->prefix_ncomps = ccn_parse_Name(d, proxy->prefix_comps); proxy->filter = ccn_charbuf_create(); res = ccn_name_from_uri(proxy->filter, filter_uri); if (res < 0) { DEBUG_PRINT("ABORT %d %s bad ccn URI: %s\n", __LINE__, __func__, filter_uri); abort(); } /* Initialization should be done by ccn_proxy_connect() */ proxy->handle_name = ccn_charbuf_create(); ccn_charbuf_append_string(proxy->handle_name, "in/outb"); DEBUG_PRINT("OUT %d %s\n", __LINE__, __func__); return(proxy); }
void GroupManager::enumerate() { ccn_charbuf *interest_path = NULL; ccn_charbuf *templ = NULL; interest_path = ccn_charbuf_create(); if (interest_path == NULL ) { return; } ccn_name_from_uri(interest_path, BROADCAST_PREFIX); ccn_name_append_str(interest_path, confName.toLocal8Bit().constData()); ccn_name_append_str(interest_path, "speaker-list"); // update exclusive filter according to recently known remote users QHash<QString, RemoteUser *>::const_iterator it = (pGroupManager->qhRemoteUsers).constBegin(); QList<QString> toExclude; while (it != (pGroupManager->qhRemoteUsers).constEnd()) { RemoteUser *ru = it.value(); if (ru && !ru->needRefresh()) { toExclude.append(ru->getName()); } ++it; } // TODO: do not exclude local user (when staleness comes to play) // always exclude localuser by now toExclude.append(userName); expressEnumInterest(interest_path, toExclude); }
static void ccn_publish_client_mountpoint() { dropbear_log(LOG_WARNING,"Enter ccn_publish_client_mountpoint"); int result; struct ccn_charbuf *mountpoint; char client_id_str[6]; char *client_name_str = NULL; mountpoint = ccn_charbuf_create(); if( mountpoint == NULL ) dropbear_exit("Failed to allocate client mountpoint charbuf"); client_name_str = strdup((const char*)cli_opts.ccnxdomain); strcat(client_name_str,"/ssh/"); sprintf(client_id_str,"%6d",rand()); strcat(client_name_str,client_id_str); cli_opts.ccnxdomain = client_name_str; result = ccn_name_from_uri(mountpoint,cli_opts.ccnxdomain); if( result < 0 ) dropbear_exit("Can't resolve client domain"); dropbear_log(LOG_WARNING,"Listening at"); print_ccnb_charbuf(mountpoint); result = ccn_set_interest_filter(cli_opts.ssh_ccn,mountpoint,&newServerAction); }
int main() { struct ccn *ccn = NULL; struct ccn_charbuf *name = NULL; int res; struct ccn_closure *incoming = NULL; ccn = ccn_create(); if (ccn_connect(ccn, NULL) == -1) { perror("Could not connect to ccnd"); exit(1); } incoming = calloc(1, sizeof(*incoming)); incoming->p = &incoming_content; name = ccn_charbuf_create(); res = ccn_name_from_uri(name, "ccnx:/FOX/test"); //ccn_express_persistent_interest(ccn, name, incoming, NULL, 1); ccn_express_interest(ccn, name, incoming, NULL); printf("Interests send\n", res); res = ccn_run(ccn, 10000); return 0; }
int ccns_slice_name(struct ccn_charbuf *nm, struct ccns_slice *s) { struct ccn_charbuf *c; struct ccn_digest *digest = NULL; struct ccn_charbuf *hash = NULL; int res = 0; c = ccn_charbuf_create(); if (c == NULL) return (-1); res = append_slice(c, s); if (res < 0) goto Cleanup; digest = ccn_digest_create(CCN_DIGEST_SHA256); hash = ccn_charbuf_create_n(ccn_digest_size(digest)); if (hash == NULL) goto Cleanup; ccn_digest_init(digest); res |= ccn_digest_update(digest, c->buf, c->length); res |= ccn_digest_final(digest, hash->buf, hash->limit); if (res < 0) goto Cleanup; hash->length = hash->limit; if (ccn_name_from_uri(nm, "ccnx:/%C1.M.S.localhost/%C1.S.cs") < 0) res = -1; res |= ccn_name_append(nm, hash->buf, hash->length); Cleanup: ccn_charbuf_destroy(&c); ccn_digest_destroy(&digest); ccn_charbuf_destroy(&hash); return (res); }
/** * should probably return a new cob, rather than reusing one. * should publish link as: * CCNRID_POLICY_URI("ccnx:/%C1.M.S.localhost/%C1.M.SRV/repository/POLICY)/%C1.M.K--pubid--/--version--/%00 * should have key locator which is the key name of the repository */ PUBLIC struct ccn_charbuf * ccnr_init_policy_link_cob(struct ccnr_handle *ccnr, struct ccn *h, struct ccn_charbuf *targetname) { struct ccn_signing_params sp = CCN_SIGNING_PARAMS_INIT; struct ccn_charbuf *name = ccn_charbuf_create(); struct ccn_charbuf *pubid = ccn_charbuf_create(); struct ccn_charbuf *pubkey = ccn_charbuf_create(); struct ccn_charbuf *keyid = ccn_charbuf_create(); struct ccn_charbuf *content = ccn_charbuf_create(); struct ccn_charbuf *cob = ccn_charbuf_create(); struct ccn_charbuf *answer = NULL; int res; res = ccn_get_public_key(h, NULL, pubid, pubkey); if (res < 0) goto Bail; if (ccn_name_from_uri(name, CCNRID_POLICY_URI) < 0) goto Bail; res |= ccn_charbuf_append_value(keyid, CCN_MARKER_CONTROL, 1); res |= ccn_charbuf_append_string(keyid, ".M.K"); res |= ccn_charbuf_append_value(keyid, 0, 1); res |= ccn_charbuf_append_charbuf(keyid, pubid); res |= ccn_name_append(name, keyid->buf, keyid->length); res |= ccn_create_version(h, name, CCN_V_NOW, 0, 0); if (ccn_name_from_uri(name, "%00") < 0) goto Bail; sp.sp_flags |= CCN_SP_FINAL_BLOCK; sp.type = CCN_CONTENT_LINK; res |= ccnb_append_Link(content, targetname, "Repository Policy", NULL); if (res != 0) goto Bail; res |= ccn_sign_content(h, cob, name, &sp, content->buf, content->length); if (res != 0) goto Bail; answer = cob; cob = NULL; Bail: ccn_charbuf_destroy(&name); ccn_charbuf_destroy(&pubid); ccn_charbuf_destroy(&pubkey); ccn_charbuf_destroy(&keyid); ccn_charbuf_destroy(&content); ccn_charbuf_destroy(&cob); return (answer); }
static struct ccn_charbuf * ccnr_init_service_ccnb(struct ccnr_handle *ccnr, struct ccn *h, const char *baseuri, int freshness) { struct ccn_signing_params sp = CCN_SIGNING_PARAMS_INIT; struct ccn_charbuf *name = ccn_charbuf_create(); struct ccn_charbuf *pubid = ccn_charbuf_create(); struct ccn_charbuf *pubkey = ccn_charbuf_create(); struct ccn_charbuf *keyid = ccn_charbuf_create(); struct ccn_charbuf *cob = ccn_charbuf_create(); int res; res = ccn_get_public_key(h, NULL, pubid, pubkey); if (res < 0) abort(); ccn_name_from_uri(name, baseuri); ccn_charbuf_append_value(keyid, CCN_MARKER_CONTROL, 1); ccn_charbuf_append_string(keyid, ".M.K"); ccn_charbuf_append_value(keyid, 0, 1); ccn_charbuf_append_charbuf(keyid, pubid); ccn_name_append(name, keyid->buf, keyid->length); ccn_create_version(h, name, 0, ccnr->starttime, ccnr->starttime_usec * 1000); sp.template_ccnb = ccn_charbuf_create(); ccnb_element_begin(sp.template_ccnb, CCN_DTAG_SignedInfo); ccnb_element_begin(sp.template_ccnb, CCN_DTAG_KeyLocator); ccnb_element_begin(sp.template_ccnb, CCN_DTAG_KeyName); ccn_charbuf_append_charbuf(sp.template_ccnb, name); ccnb_element_end(sp.template_ccnb); // ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_PublisherPublicKeyDigest, // CCN_DTAG); // ccn_charbuf_append_charbuf(sp.template_ccnb, pubid); // ccnb_element_end(sp.template_ccnb); ccnb_element_end(sp.template_ccnb); ccnb_element_end(sp.template_ccnb); sp.sp_flags |= CCN_SP_TEMPL_KEY_LOCATOR; ccn_name_from_uri(name, "%00"); sp.sp_flags |= CCN_SP_FINAL_BLOCK; sp.type = CCN_CONTENT_KEY; sp.freshness = freshness; res = ccn_sign_content(h, cob, name, &sp, pubkey->buf, pubkey->length); if (res != 0) abort(); ccn_charbuf_destroy(&name); ccn_charbuf_destroy(&pubid); ccn_charbuf_destroy(&pubkey); ccn_charbuf_destroy(&keyid); ccn_charbuf_destroy(&sp.template_ccnb); return(cob); }
/* * newServerHandler * * Expecting a string containing the URI for the client */ static enum ccn_upcall_res newServerHandler(struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info) { dropbear_log(LOG_WARNING,"Enter newServerHandler"); dropbear_log(LOG_WARNING,"Got interest matching %d components, kind = %d\n", info->matched_comps, kind); int result; const unsigned char *ccnb = NULL; size_t ccnb_size; void *data = NULL; size_t data_size = 0; switch (kind) { case CCN_UPCALL_CONTENT: break; case CCN_UPCALL_INTEREST_TIMED_OUT: return CCN_UPCALL_RESULT_REEXPRESS; case CCN_UPCALL_CONTENT_UNVERIFIED: // TODO: fix verification break; default: return CCN_UPCALL_RESULT_ERR; } dropbear_log(LOG_WARNING,"Interest to"); print_ccnb_name(info); ccnb = info->content_ccnb; ccnb_size = info->pco->offset[CCN_PCO_E]; result = ccn_content_get_value(ccnb, ccnb_size, info->pco, (const unsigned char **)&data, &data_size); if( result < 0 ) dropbear_exit("Could not parse reply message"); dropbear_log(LOG_WARNING,"newServerHandler: parsing contents"); if( strncmp((char *)data,"ccnx:/",6) == 0 ) { cli_opts.remote_name_str = (char *)data; dropbear_log(LOG_WARNING,"newServerHandler: matches: %s (%d)",data,data_size); ses.remote_name = ccn_charbuf_create(); result = ccn_name_from_uri(ses.remote_name,cli_opts.remote_name_str); if( result < 0 ) dropbear_exit("Did not find expected uri in server response"); // Start a new session dropbear_log(LOG_WARNING,"Connected to server at"); print_ccnb_charbuf(ses.remote_name); cli_session(cli_opts.ccnxdomain,cli_opts.remote_name_str); return CCN_UPCALL_RESULT_OK; } else { dropbear_log(LOG_WARNING,"newServerHandler: doesn't match"); return CCN_UPCALL_RESULT_ERR; } }
static int add_delete_ccn_face(struct ccn *h, const char *uri, const char *address, const unsigned int p, int operation) { struct ccn_charbuf *prefix; char port[6]; struct ccn_charbuf *local_scope_template = ccn_charbuf_create(); struct ccn_charbuf *no_name = ccn_charbuf_create(); unsigned char ccndid_storage[32] = {0}; unsigned char *ccndid = ccndid_storage; size_t ccndid_size = 0; struct ccn_face_instance *fi; struct ccn_face_instance *nfi; int res; prefix = ccn_charbuf_create(); res = ccn_name_from_uri(prefix, uri); ON_ERROR_CLEANUP(res); memset(port, 0, 6); sprintf(port, "%d", p); init_data(local_scope_template, no_name); ccndid_size = get_ccndid(h, local_scope_template, ccndid); if (ccndid_size != sizeof(ccndid_storage)) { fprintf(stderr, "Incorrect size for ccnd id in response\n"); ON_ERROR_CLEANUP(-1); } /* construct a face instance for new face request */ fi = construct_face(ccndid, ccndid_size, address, port); ON_NULL_CLEANUP(fi); /* send new face request to actually create a new face */ nfi = create_face(h, local_scope_template, no_name, fi); ON_NULL_CLEANUP(nfi); res = register_unregister_prefix(h, local_scope_template, no_name, prefix, nfi, operation); ON_ERROR_CLEANUP(res); ccn_charbuf_destroy(&local_scope_template); ccn_charbuf_destroy(&no_name); ccn_face_instance_destroy(&fi); ccn_face_instance_destroy(&nfi); ccn_charbuf_destroy(&prefix); return 0; cleanup: ccn_charbuf_destroy(&prefix); ccn_charbuf_destroy(&local_scope_template); ccn_charbuf_destroy(&no_name); ccn_face_instance_destroy(&fi); ccn_face_instance_destroy(&nfi); return -1; }
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)); }
struct ccn_forwarding_entry * parse_ccn_forwarding_entry(struct ccndc_data *self, const char *cmd_uri, const char *cmd_flags, int freshness) { int res = 0; struct ccn_forwarding_entry *entry; entry= calloc(1, sizeof(*entry)); if (entry == NULL) { ccndc_warn(__LINE__, "Fatal error: memory allocation failed"); goto ExitOnError; } entry->name_prefix = ccn_charbuf_create(); if (entry->name_prefix == NULL) { ccndc_warn(__LINE__, "Fatal error: memory allocation failed"); goto ExitOnError; } // copy static info entry->ccnd_id = (const unsigned char *)self->ccnd_id; entry->ccnd_id_size = self->ccnd_id_size; /* we will be creating the face to either add/delete a prefix on it */ if (cmd_uri == NULL) { ccndc_warn(__LINE__, "command erro, missing CCNx URI\n"); goto ExitOnError; } res = ccn_name_from_uri(entry->name_prefix, cmd_uri); if (res < 0) { ccndc_warn(__LINE__, "command error, bad CCNx URI '%s'\n", cmd_uri); goto ExitOnError; } entry->flags = -1; if (cmd_flags != NULL && cmd_flags[0] != 0) { char *endptr; entry->flags = strtol(cmd_flags, &endptr, 10); if ((endptr != &cmd_flags[strlen(cmd_flags)]) || (entry->flags & ~CCN_FORW_PUBMASK) != 0) { ccndc_warn(__LINE__, "command error, invalid flags %s\n", cmd_flags); goto ExitOnError; } } entry->lifetime = freshness; return (entry); ExitOnError: ccn_forwarding_entry_destroy(&entry); return (NULL); }
char * get_orig_router_from_lsa_name(struct ccn_charbuf * content_name) { int start=0; size_t comp_size; const unsigned char *second_last_comp; char *second_comp_type; char *sep="."; char *rem; 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); start=components->n-2; ccn_charbuf_destroy(&name); ccn_indexbuf_destroy(&components); struct ccn_indexbuf *comps=ccn_indexbuf_create(); ccn_name_split (content_name, comps); ccn_name_comp_get( content_name->buf, comps, comps->n-1-2, &second_last_comp, &comp_size); second_comp_type=strtok_r((char *)second_last_comp, sep, &rem); if ( strcmp( second_comp_type, "lsId" ) == 0 ){ ccn_name_chop(content_name,comps,-3); } else{ ccn_name_chop(content_name,comps,-2); } struct ccn_charbuf *temp=ccn_charbuf_create(); ccn_name_init(temp); ccn_name_append_components( temp, content_name->buf, comps->buf[start+1], comps->buf[comps->n - 1]); struct ccn_charbuf *temp1=ccn_charbuf_create(); ccn_uri_append(temp1, temp->buf, temp->length, 0); char *orig_router=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1, sizeof(char)); memcpy(orig_router,ccn_charbuf_as_string(temp1), strlen(ccn_charbuf_as_string(temp1))); orig_router[strlen(orig_router)]='\0'; ccn_charbuf_destroy(&temp); ccn_charbuf_destroy(&temp1); ccn_indexbuf_destroy(&comps); return orig_router; }
int GroupManager::ccn_open() { ccn_charbuf *interest_filter_path; interest_filter_path = ccn_charbuf_create(); if (interest_filter_path == NULL ) { DPRINT("Failed to allocate or initialize interest filter path"); return -1; } ccn_name_from_uri(interest_filter_path, (const char *) BROADCAST_PREFIX); ccn_name_append_str(interest_filter_path, confName.toLocal8Bit().constData()); ccn_name_append_str(interest_filter_path, "speaker-list"); ccn_set_interest_filter(ccn, interest_filter_path, req_closure); ccn_charbuf_destroy(&interest_filter_path); ccn_charbuf *leave_filter = ccn_charbuf_create(); ccn_name_from_uri(leave_filter, (const char *) BROADCAST_PREFIX); ccn_name_append_str(leave_filter, confName.toLocal8Bit().constData()); ccn_name_append_str(leave_filter, "leave"); ccn_set_interest_filter(ccn, leave_filter, leave_closure); ccn_charbuf_destroy(&leave_filter); return 0; }
void ccn_ssh_connect(char *remote_name_str) { dropbear_log(LOG_WARNING,"Enter ccn_ssh_connect"); int result; struct ccn_charbuf *remote_name; /* struct ccn_pkey *server_pkey; void *encrypted_local_name; size_t encrypted_local_name_length; */ struct ccn_charbuf *connect_template; remote_name = ccn_charbuf_create(); result = ccn_name_from_uri(remote_name,remote_name_str); if( result < 0 ) dropbear_exit("Could not parse server uri"); ccn_name_append_str(remote_name,"ssh"); ccn_name_append_str(remote_name,"client"); /* server_pkey = ssh_ccn_retrieve_public_key( cli_opts.ssh_ccn, cli_opts.remote_name_str, cli_opts.ccn_cached_keystore); if( server_pkey == NULL ) dropbear_exit("Could not get server public key"); result = ccn_pubkey_encrypt(server_pkey, cli_opts.ccnxdomain, strlen(cli_opts.ccnxdomain), &encrypted_local_name, &encrypted_local_name_length); ccn_name_append(remote_name,encrypted_local_name); */ ccn_name_append(remote_name,cli_opts.ccnxdomain,strlen(cli_opts.ccnxdomain)); dropbear_log(LOG_WARNING,"Connecting to remote:"); print_ccnb_charbuf(remote_name); connect_template = make_connect_template(); result = ccn_express_interest(cli_opts.ssh_ccn, remote_name, &newServerAction, connect_template); if( result < 0 ) dropbear_exit("Failed to express interest to server"); }
/* * Create a face on the multicast address and port, bind the DHCP prefix to the face */ int join_dhcp_group(struct ccn *h) { int res; struct ccn_charbuf *prefix = ccn_charbuf_create(); ccn_name_from_uri(prefix, CCN_DHCP_URI); res = add_new_face(h, prefix, CCN_DHCP_ADDR, CCN_DHCP_PORT); ccn_charbuf_destroy(&prefix); return res; }
/** * Initiates a stream to download data * * @param id identifier of the ccn stream * @param pname name of the object to download * @param pipeline number of parallel requisitions for chunks */ bool CCNGet::initStream(string id, string pname, int pipeline) { name = ccn_charbuf_create(); name->length = 0; ccn_name_from_uri(name, pname.c_str()); templ = make_template(0,-1); ccn = ccn_create(); if (ccn_connect(ccn,NULL) == -1) return false; fetch = ccn_fetch_new(ccn); stream = ccn_fetch_open(fetch, name, id.c_str(), templ, pipeline, CCN_V_HIGHEST, ASSUMEFIXED); if (stream == NULL) return false; else return true; }
void CcnCC_registerControlPrefix(CcnCC self) { if (self->regControlPrefix) return; struct ccn_charbuf* prefix = ccn_charbuf_create(); ccn_name_from_uri(prefix, "ccnx:/ccnx/ndnld"); ccn_name_append(prefix, self->ccndid, CCNDID_length); ccn_name_append_str(prefix, "control"); struct ccn_closure* action = (struct ccn_closure*)calloc(1, sizeof(struct ccn_closure)); action->data = self; action->p = &CcnCC_controlInterest; ccn_set_interest_filter(self->ccnh, prefix, action); ccn_charbuf_destroy(&prefix); }
void CcnLAC_fetchFaceid(CcnLAC self, CCNDID ccndid) { struct ccn_charbuf* prefix = ccn_charbuf_create(); ccn_name_from_uri(prefix, "ccnx:/ccnx/ndnld"); ccn_name_append(prefix, ccndid, CCNDID_length); ccn_name_append_str(prefix, "discover-faceid"); struct ccn_forwarding_entry* fe = CcnH_buildForwardingEntry(CcnPrefixOp_selfreg, ccndid, 0, prefix); fe->flags = CCN_FORW_LAST | CCN_FORW_LOCAL; fe->lifetime = 1; CcnH_regForwardingEntry(self->ccnh, ccndid, fe, self, &CcnLAC_fetchFaceidCb); ccn_charbuf_destroy(&prefix); free(fe); }
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; }
extern struct SyncBaseStruct * SyncNewBase(struct ccnr_handle *ccnr, struct ccn *ccn, struct ccn_schedule *sched) { sync_time now = SyncCurrentTime(); struct SyncBaseStruct *base = NEW_STRUCT(1, SyncBaseStruct); base->ccnr = ccnr; base->ccn = ccn; base->sched = sched; struct SyncPrivate *priv = NEW_STRUCT(1, SyncPrivate); base->priv = priv; priv->topoAccum = SyncAllocNameAccum(4); priv->prefixAccum = SyncAllocNameAccum(4); priv->sliceCmdPrefix = ccn_charbuf_create(); priv->localHostPrefix = ccn_charbuf_create(); priv->comps = ccn_indexbuf_create(); priv->stableTarget = CCNR_NULL_HWM; priv->stableStored = CCNR_NULL_HWM; priv->lastStable = now; priv->lastCacheClean = now; ccn_name_from_uri(priv->localHostPrefix, "/%C1.M.S.localhost"); ccn_name_from_uri(priv->sliceCmdPrefix, "/%C1.M.S.localhost/%C1.S.cs"); return base; }
int main(int argc, char *argv[]) { int res; struct ccn *ccn = NULL; struct ccn_charbuf *name = NULL; struct ccn_closure *incoming; if (argc != 2) usage(argv[0]); name = ccn_charbuf_create(); res = ccn_name_from_uri(name, argv[1]); if (res < 0) { fprintf(stderr, "invalid ccn URI: %s\n", argv[1]); usage(argv[0]); } ccn = ccn_create(); res = ccn_connect(ccn, NULL); if (res < 0) { fprintf(stderr, "can't connect to ccn: %d\n", res); ccn_perror(ccn, "ccn_connect"); exit(1); } incoming = calloc(1, sizeof(*incoming)); incoming->p = incoming_handler; g_working = true; gettimeofday(&g_start, NULL); res = ccn_express_interest(ccn, name, incoming, NULL); while (g_working && res >= 0) res = ccn_run(ccn, 100); free(incoming); if (res < 0) { ccn_perror(ccn, "ccn_run"); exit(1); } ccn_charbuf_destroy(&name); ccn_destroy(&ccn); return 0; }
/* send optional leave notification before actually leaves */ void GroupManager::sendLeaveInterest() { ccn_charbuf *interest_path = ccn_charbuf_create(); if (interest_path == NULL ) { return; } ccn_name_from_uri(interest_path, (const char*)BROADCAST_PREFIX); ccn_name_append_str(interest_path, confName.toLocal8Bit().constData()); ccn_name_append_str(interest_path, "leave"); ccn_name_append_str(interest_path, userName.toLocal8Bit().constData()); static ccn_charbuf *templ = NULL; mutex_trylock(); ccn_express_interest(ccn, interest_path, leave_closure, NULL); mutex_unlock(); ccn_charbuf_destroy(&interest_path); templ = NULL; }
/** * Initiates a stream to download metadata (relations) * * @param id identifier of the ccn stream * @param pname name of the object containing the metadata * @param pmetaname name of the meta object to download * @param pipeline number of parallel requisitions for chunks */ bool CCNGet::initMetaStream(string id, string pname, string pmetaname, int pipeline) { name = ccn_charbuf_create(); name->length = 0; ccn_name_from_uri(name, pname.c_str()); templ = make_template(0,-1); ccn = ccn_create(); if (ccn_connect(ccn,NULL) == -1) return false; if (ccn_resolve_version(ccn, name, CCN_V_HIGHEST, 1000) < 1) return false; ccn_name_append(name, meta, sizeof(meta)); ccn_name_append_str(name, pmetaname.c_str()); fetch = ccn_fetch_new(ccn); stream = ccn_fetch_open(fetch, name, id.c_str(), templ, pipeline, CCN_V_HIGHEST, ASSUMEFIXED); if (stream == NULL) return false; else return true; }
/** * Set up a connection with the ccnd router * * During this setup we establish a basic connection with the router service * over an IP connection. * This is also a good time to setup the ccn name for the content we will * produce; that is the prefix name and the timestamp [Tnow], since the * segment portion of the name is added just as the packet is being sent. * * Lastly we also load our security keys and create our signing parameters. * * \param me context sink element for which the socket is for */ static void setup_ccn (Gstccnxsink * me) { struct ccn *ccn; GST_DEBUG ("CCNxSink: setup name..."); if ((me->name = ccn_charbuf_create ()) == NULL) { GST_ELEMENT_ERROR (me, RESOURCE, READ, (NULL), ("name alloc failed")); return; } if (ccn_name_from_uri (me->name, me->uri) < 0) { GST_ELEMENT_ERROR (me, RESOURCE, READ, (NULL), ("name from uri failed")); return; } GST_DEBUG ("CCNxSink: creating ccn object"); if ((ccn = ccn_create ()) == NULL) { GST_ELEMENT_ERROR (me, RESOURCE, READ, (NULL), ("ccn_create failed")); return; } me->ccn = ccn; GST_DEBUG ("CCNxSink: connecting"); if (-1 == ccn_connect (me->ccn, ccndHost ())) { GST_ELEMENT_ERROR (me, RESOURCE, READ, (NULL), ("ccn_connect failed to %s", ccndHost ())); return; } GST_DEBUG ("CCNxSink: setting name version"); if (0 > ccn_create_version (ccn, me->name, CCN_V_REPLACE | CCN_V_NOW | CCN_V_HIGH, 0, 0)) { GST_ELEMENT_ERROR (me, RESOURCE, READ, (NULL), ("ccn_create_version() failed")); return; } GST_DEBUG ("CCNxSink: setting up keystore"); /* me->keystore = fetchStore(); if( me->keystore ) me->keylocator = makeLocator( ccn_keystore_public_key(me->keystore) ); */ loadKey (me->ccn, &me->sp); GST_DEBUG ("CCNxSink: done; have keys!"); }
struct ccn_charbuf* CcnH_signForwardingEntry(struct ccn* ccnh, CCNDID ccndid, struct ccn_forwarding_entry* fe) { struct ccn_charbuf* request = ccn_charbuf_create(); ccnb_append_forwarding_entry(request, fe); struct ccn_charbuf* emptyname = ccn_charbuf_create(); ccn_name_init(emptyname); struct ccn_charbuf* signed_request = ccn_charbuf_create(); ccn_sign_content(ccnh, signed_request, emptyname, NULL, request->buf, request->length); struct ccn_charbuf* reqname = ccn_charbuf_create(); ccn_name_from_uri(reqname, "ccnx:/ccnx"); ccn_name_append(reqname, ccndid, CCNDID_length); ccn_name_append_str(reqname, fe->action); ccn_name_append(reqname, signed_request->buf, signed_request->length); ccn_charbuf_destroy(&request); ccn_charbuf_destroy(&emptyname); ccn_charbuf_destroy(&signed_request); return reqname; }
/** * Request the current segment number from the ccnx data producer * * This is a request for meta data for the media stream the user has named with their URI. * We assume that they want to join the media broadcast from what is currently being published * and \em not want to start from the beginning...although there is good reason for that too. * * Getting this data is done by expressing interests in the meta data. The producer of the * media stream will catch this through one of its ccnx filters and produce this meta data * back through the network to us. * * \param h ccnx context handle * \param name the content name for which we desire the meta data * \param timeout how long to wait around * \return the segment number to ask for first, 0 on timeout */ static uintmax_t * get_segment (struct ccn *h, struct ccn_charbuf *name, int timeout) { struct ccn_charbuf *hn; uintmax_t *result = NULL; int res = 0; GST_INFO ("get_segment step 1"); hn = ccn_charbuf_create (); // ccn_name_append_components(hn, name->buf, 0, name->length ); ccn_charbuf_append_charbuf (hn, name); ccn_name_from_uri (hn, "_meta_/.segment"); // ccn_name_append_str(hn, "_meta_"); // ccn_name_append_str(hn, ".segment"); GST_INFO ("get_segment step 2"); // res = ccn_resolve_version(h, hn, CCN_V_HIGHEST, timeout); GST_INFO ("get_segment step 3, res: %d", res); if (res == 0) { struct ccn_charbuf *ho = ccn_charbuf_create (); struct ccn_parsed_ContentObject pcobuf = { 0 }; const unsigned char *hc; size_t hcs; // hDump(DUMP_ADDR(hn->buf), DUMP_SIZE(hn->length)); GST_INFO ("get_segment step 10"); res = ccn_get (h, hn, NULL, timeout, ho, &pcobuf, NULL, 0); GST_INFO ("get_segment step 11, res: %d", res); if (res >= 0) { hc = ho->buf; hcs = ho->length; // hDump( DUMP_ADDR(hc), DUMP_SIZE(hcs)); ccn_content_get_value (hc, hcs, &pcobuf, &hc, &hcs); // hDump( DUMP_ADDR(hc), DUMP_SIZE(hcs)); result = calloc (1, sizeof (uintmax_t)); memcpy (result, hc, sizeof (uintmax_t)); } ccn_charbuf_destroy (&ho); } GST_INFO ("get_segment step 9"); ccn_charbuf_destroy (&hn); return (result); }
void CcnCC_fetchCcndid(CcnCC self) { int res; struct ccn_charbuf* name = ccn_charbuf_create(); struct ccn_charbuf* resultbuf = ccn_charbuf_create(); struct ccn_parsed_ContentObject pcobuf = {0}; const uint8_t* ccndid_result; static size_t ccndid_result_size; ccn_name_from_uri(name, "ccnx:/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY"); res = ccn_get(self->ccnh, name, CcnH_localScopeTempl(), 4500, resultbuf, &pcobuf, NULL, 0); if (res >= 0) { res = ccn_ref_tagged_BLOB(CCN_DTAG_PublisherPublicKeyDigest, resultbuf->buf, pcobuf.offset[CCN_PCO_B_PublisherPublicKeyDigest], pcobuf.offset[CCN_PCO_E_PublisherPublicKeyDigest], &ccndid_result, &ccndid_result_size); } if (res >= 0 && ccndid_result_size == CCNDID_length) { memcpy((void*)self->ccndid, ccndid_result, CCNDID_length); } else { self->error = true; } ccn_charbuf_destroy(&name); ccn_charbuf_destroy(&resultbuf); }
void NdnMediaProcess::tick() { // send new interest for every speaker ruMutex->lock(); QHash<QString, UserDataBuf *>::const_iterator it = qhRemoteUser.constBegin(); while (it != qhRemoteUser.constEnd()) { QString userName = it.key(); UserDataBuf *udb = it.value(); if (udb != NULL && udb->seq >= 0) { udb->seq++; struct ccn_charbuf *pathbuf = ccn_charbuf_create(); ccn_name_from_uri(pathbuf, userName.toLocal8Bit().constData()); ccn_name_append_str(pathbuf, "audio"); struct ccn_charbuf *temp = ccn_charbuf_create(); ccn_charbuf_putf(temp, "%ld", udb->seq); ccn_name_append(pathbuf, temp->buf, temp->length); /* 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); int res = ccn_express_interest(ndnState.ccn, pathbuf, udb->data_buf.pipe_callback, NULL); pthread_mutex_unlock(&ccn_mutex); if (res < 0) { fprintf(stderr, "Sending interest failed at normal processor\n"); exit(1); } ccn_charbuf_destroy(&pathbuf); ccn_charbuf_destroy(&temp); } it++; } ruMutex->unlock(); }
/************************************************ * 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; }
/** * * Get ccnd id * */ static int get_ccndid(struct ccn *h, struct ccn_charbuf *local_scope_template, unsigned char *ccndid) { struct ccn_charbuf *name = NULL; struct ccn_charbuf *resultbuf = NULL; struct ccn_parsed_ContentObject pcobuf = {0}; char ccndid_uri[] = "ccnx:/%C1.M.S.localhost/%C1.M.SRV/ccnd/KEY"; const unsigned char *ccndid_result; static size_t ccndid_result_size; int res; name = ccn_charbuf_create(); resultbuf = ccn_charbuf_create(); res = ccn_name_from_uri(name, ccndid_uri); ON_ERROR_EXIT(res, "Unable to parse service locator URI for ccnd key\n"); /* get Data */ res = ccn_get(h, name, local_scope_template, 4500, resultbuf, &pcobuf, NULL, 0); ON_ERROR_EXIT(res, "Unable to get key from ccnd\n"); /* extract from Data */ res = ccn_ref_tagged_BLOB(CCN_DTAG_PublisherPublicKeyDigest, resultbuf->buf, pcobuf.offset[CCN_PCO_B_PublisherPublicKeyDigest], pcobuf.offset[CCN_PCO_E_PublisherPublicKeyDigest], &ccndid_result, &ccndid_result_size); ON_ERROR_EXIT(res, "Unable to parse ccnd response for ccnd id\n"); memcpy((void *)ccndid, ccndid_result, ccndid_result_size); ccn_charbuf_destroy(&name); ccn_charbuf_destroy(&resultbuf); return (ccndid_result_size); }