void update_routing_table(char * dest_router,int next_hop_face, int route_cost) { if ( nlsr->debugging ) { printf("update_routing_table called \n"); printf("Dest Router: %s Next Hop face: %d Route Cost: %d \n",dest_router,next_hop_face,route_cost); } int res,res1; struct routing_table_entry *rte; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->routing_table, e); res = hashtb_seek(e, dest_router, strlen(dest_router), 0); if( res == HT_OLD_ENTRY ) { rte=e->data; struct hashtb_enumerator eef; struct hashtb_enumerator *ef = &eef; hashtb_start(rte->face_list, ef); res1 = hashtb_seek(ef, &next_hop_face, sizeof(next_hop_face), 0); if( res1 == HT_NEW_ENTRY) { struct face_list_entry *fle; fle=ef->data; fle->next_hop_face=next_hop_face; fle->route_cost=route_cost; } else if ( res1 == HT_OLD_ENTRY ) { struct face_list_entry *fle; fle=ef->data; fle->route_cost=route_cost; } hashtb_end(ef); } else if ( res == HT_NEW_ENTRY ) { hashtb_delete(e); } hashtb_end(e); }
int main(int argc, char ** argv){ char* nid="123"; int chunk=1; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ struct hashtb* conetht = hashtb_create(sizeof(struct conet_entry), NULL); hashtb_start(conetht, e); struct conet_entry* ce; int res=hashtb_seek(e, nid, strlen(nid), 0); if (res < 0) perror("errore nel seek dell'ht"); ce = e->data; if (res == HT_NEW_ENTRY) { ce->prev=NULL; ce->next=NULL; ce->chunk_number=chunk; ce->m_req_wnd=1; ce->m_segment_size=1046; ce->nid=nid; } hashtb_end(e); }
/** * This makes a cookie for content, and, if it has an accession number already, * enters it into the content_by_accession_tab. Does not index by name. */ PUBLIC ccnr_cookie r_store_enroll_content(struct ccnr_handle *h, struct content_entry *content) { ccnr_cookie cookie; unsigned mask; mask = h->cookie_limit - 1; cookie = ++(h->cookie); if (cookie == 0) cookie = ++(h->cookie); /* Cookie numbers may wrap */ // XXX - check for persistence here, if we add that r_store_forget_content(h, &(h->content_by_cookie[cookie & mask])); content->cookie = cookie; h->content_by_cookie[cookie & mask] = content; if (content->accession != CCNR_NULL_ACCESSION) { struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ ccnr_accession accession = content->accession; struct content_by_accession_entry *entry = NULL; hashtb_start(h->content_by_accession_tab, e); hashtb_seek(e, &accession, sizeof(accession), 0); entry = e->data; if (entry != NULL) entry->content = content; hashtb_end(e); content->flags |= CCN_CONTENT_ENTRY_STABLE; } return(cookie); }
void read_stats(struct hashtb* stats, const char * filename) { char buf[MAXLINELEN]; char name[MAXLINELEN]; unsigned long num_req = 0; unsigned long sat_req = 0; struct hashtb_enumerator ee; struct hashtb_enumerator * hte = ⅇ struct stats_entry* entry = NULL; int res = 0; memset(hte, 0, sizeof(struct hashtb_enumerator)); FILE* input = fopen(filename, "r"); if (input == NULL) { return; } while (fgets(buf, MAXLINELEN, input) != NULL) { memset(name, 0, MAXLINELEN); sscanf(buf, "%s %lu %lu", name, &num_req, &sat_req); hashtb_start(stats, hte); res = hashtb_seek(hte, name, MAXLINELEN, 0); entry = hte->data; if (res == HT_NEW_ENTRY) { entry->name = hte->key; entry->num_req = 0; entry->sat_req = 0; } entry->num_req += num_req; entry->sat_req += sat_req; hashtb_end(hte); } fclose(input); }
void add_next_hop_router(char *dest_router) { if ( strcmp(dest_router,nlsr->router_name)== 0) { return ; } struct routing_table_entry *rte;//=(struct routing_table_entry *)malloc(sizeof(struct routing_table_entry)); struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(nlsr->routing_table, e); res = hashtb_seek(e, dest_router, strlen(dest_router), 0); if( res == HT_NEW_ENTRY ) { rte=e->data; rte->dest_router=(char *)malloc(strlen(dest_router)+1); memset(rte->dest_router,0,strlen(dest_router)+1); memcpy(rte->dest_router,dest_router,strlen(dest_router)); //rte->next_hop_face=NO_NEXT_HOP; struct hashtb_param param_fle = {0}; rte->face_list=hashtb_create(sizeof(struct face_list_entry), ¶m_fle); add_npt_entry(dest_router, dest_router, 0, NULL, NULL); } hashtb_end(e); }
int get_number_of_next_hop(char *dest_router) { struct routing_table_entry *rte; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res,ret; hashtb_start(nlsr->routing_table, e); res = hashtb_seek(e, dest_router, strlen(dest_router), 0); if( res == HT_OLD_ENTRY ) { rte=e->data; ret=hashtb_n(rte->face_list); //nhl=rte->face_list; } else if(res == HT_NEW_ENTRY) { hashtb_delete(e); ret=NO_NEXT_HOP; } hashtb_end(e); return ret; }
int does_name_exist_in_npl(struct name_prefix *np) { int ret=0; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(nlsr->npl, e); res = hashtb_seek(e, np->name, np->length, 0); if(res == HT_NEW_ENTRY) { hashtb_delete(e); ret=0; } else { ret=1; } hashtb_end(e); return ret; }
char * get_router_from_rev_map(long int mapping_number) { struct map_entry *me; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(nlsr->rev_map, e); res = hashtb_seek(e, &mapping_number, sizeof(mapping_number), 0); if(res == HT_OLD_ENTRY) { me=e->data; hashtb_end(e); return me->router; } else if(res == HT_NEW_ENTRY) { hashtb_delete(e); hashtb_end(e); } return NULL; }
void add_rev_map_entry(long int mapping_number, char *router) { struct map_entry *me;//=(struct map_entry*)malloc(sizeof(struct map_entry )); struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(nlsr->rev_map, e); res = hashtb_seek(e, &mapping_number, sizeof(mapping_number), 0); if(res == HT_NEW_ENTRY) { me=e->data; me->router=(char *)malloc(strlen(router)+1); memset(me->router,0,strlen(router)+1); memcpy(me->router,router,strlen(router)); me->mapping=mapping_number; } hashtb_end(e); }
long int get_lsa_id_from_npl(struct name_prefix *np) { int ret=0; struct name_prefix_list_entry *npe; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(nlsr->npl, e); res = hashtb_seek(e, np->name, np->length, 0); if(res == HT_NEW_ENTRY) { hashtb_delete(e); ret=0; } else { npe=e->data; ret=npe->name_lsa_id; } hashtb_end(e); return ret; }
void LMD_demux(LMD self) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; LMDRec rec; SockAddr addr = SockAddr_ctor(); struct ccn_charbuf* hashkey; void* buf = malloc(self->mtu); size_t len; hashtb_start(self->demux, hte); while ((len = NBS_read(self->nbs, buf, self->mtu, addr)) > 0) { hashkey = SockAddr_hashkey(addr); htres = hashtb_seek(hte, hashkey->buf, hashkey->length, 0); rec = NULL; if (htres == HT_OLD_ENTRY) { rec = *((LMDRec*)hte->data); } else { rec = self->fallback; if (htres == HT_NEW_ENTRY) hashtb_delete(hte); } if (rec != NULL) { LMDRec_deliver(rec, buf, len, addr); buf = malloc(self->mtu); } } free(buf); hashtb_end(hte); SockAddr_dtor(addr); }
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(); }
void SentPkts_remove(SentPkts self, SeqNum sequence) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; SentPktRec rec; hashtb_start(self->index, hte); htres = hashtb_seek(hte, &sequence, sizeof(SeqNum), 0); if (htres == HT_OLD_ENTRY) { rec = *((SentPktRec*)hte->data); SentPkts_rDetach(self, rec); SentPkts_sDetach(self, rec); SentPktRec_dtor(rec, false); } hashtb_delete(hte); hashtb_end(hte); }
bool LMD_registered(LMD self, SockAddr srcaddr) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; bool found = false; struct ccn_charbuf* hashkey = SockAddr_hashkey(srcaddr); hashtb_start(self->demux, hte); htres = hashtb_seek(hte, hashkey->buf, hashkey->length, 0); if (htres == HT_OLD_ENTRY) { found = true; } else { hashtb_delete(hte); } hashtb_end(hte); return found; }
int get_next_hop(char *dest_router,int *faces, int *route_costs) { struct routing_table_entry *rte; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res,ret; hashtb_start(nlsr->routing_table, e); res = hashtb_seek(e, dest_router, strlen(dest_router), 0); if( res == HT_OLD_ENTRY ) { rte=e->data; ret=hashtb_n(rte->face_list); //nhl=rte->face_list; int j,face_list_element; struct face_list_entry *fle; struct hashtb_enumerator eef; struct hashtb_enumerator *ef = &eef; hashtb_start(rte->face_list, ef); face_list_element=hashtb_n(rte->face_list); for(j=0;j<face_list_element;j++) { fle=ef->data; //printf(" Face: %d Route_Cost: %d \n",fle->next_hop_face,fle->route_cost); faces[j]=fle->next_hop_face; route_costs[j]=fle->route_cost; hashtb_next(ef); } hashtb_end(ef); } else if(res == HT_NEW_ENTRY) { hashtb_delete(e); ret=NO_NEXT_HOP; } hashtb_end(e); return ret; }
void LMD_reg(LMD self, SockAddr srcaddr) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; LMDRec rec = NULL; struct ccn_charbuf* hashkey = SockAddr_hashkey(srcaddr); hashtb_start(self->demux, hte); htres = hashtb_seek(hte, hashkey->buf, hashkey->length, 0); if (htres == HT_NEW_ENTRY) { rec = LMDRec_ctor(srcaddr); *((LMDRec*)hte->data) = rec; } hashtb_end(hte); if (SockAddr_equals(LMD_fallbackAddr_inst(), srcaddr)) { self->fallback = rec; } }
static void remove_ccn_ping_entry(struct ccn_ping_client *client, const unsigned char *interest_msg, const struct ccn_parsed_interest *pi) { struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(client->ccn_ping_table, e); res = hashtb_seek(e, interest_msg + pi->offset[CCN_PI_B_Component0], pi->offset[CCN_PI_E_LastPrefixComponent] - pi->offset[CCN_PI_B_Component0], 0); assert(res == HT_OLD_ENTRY); hashtb_delete(e); hashtb_end(e); }
void SentPkts_insert(SentPkts self, DataPkt pkt) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; SeqNum sequence; SentPktRec rec; sequence = DataPkt_getSequence(pkt); hashtb_start(self->index, hte); htres = hashtb_seek(hte, &sequence, sizeof(SeqNum), 0); if (htres == HT_NEW_ENTRY) { rec = SentPktRec_ctor(pkt, self->retryCount); *((SentPktRec*)hte->data) = rec; SentPkts_sInsert(self, rec); SentPkts_rInsert(self, rec); } hashtb_end(hte); if (self->count > self->capacity) { SentPkts_remove(self, DataPkt_getSequence(self->shead->pkt)); } }
void LMD_unreg(LMD self, SockAddr srcaddr) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; LMDRec rec = NULL; struct ccn_charbuf* hashkey = SockAddr_hashkey(srcaddr); hashtb_start(self->demux, hte); htres = hashtb_seek(hte, hashkey->buf, hashkey->length, 0); if (htres == HT_OLD_ENTRY) { rec = *((LMDRec*)hte->data); } hashtb_delete(hte); hashtb_end(hte); if (rec != NULL) { if (self->fallback == rec) self->fallback = NULL; LMDRec_dtor(rec); } }
PUBLIC int r_store_set_accession_from_offset(struct ccnr_handle *h, struct content_entry *content, struct fdholder *fdholder, off_t offset) { struct ccn_btree_node *leaf = NULL; uint_least64_t cobid; int ndx; int res = -1; if (offset != (off_t)-1 && content->accession == CCNR_NULL_ACCESSION) { struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ struct content_by_accession_entry *entry = NULL; content->flags |= CCN_CONTENT_ENTRY_STABLE; content->accession = ((ccnr_accession)offset) | r_store_mark_repoFile1; hashtb_start(h->content_by_accession_tab, e); hashtb_seek(e, &content->accession, sizeof(content->accession), 0); entry = e->data; if (entry != NULL) { entry->content = content; if (content->cob != NULL) h->cob_count++; } hashtb_end(e); if (content->flatname != NULL) { res = ccn_btree_lookup(h->btree, content->flatname->buf, content->flatname->length, &leaf); if (res >= 0 && CCN_BT_SRCH_FOUND(res)) { ndx = CCN_BT_SRCH_INDEX(res); cobid = ccnr_accession_encode(h, content->accession); ccn_btree_prepare_for_update(h->btree, leaf); res = ccn_btree_content_set_cobid(leaf, ndx, cobid); } else res = -1; } if (res >= 0 && content->accession >= h->notify_after) r_sync_notify_content(h, 0, content); } return(res); }
static void add_ccn_ping_entry(struct ccn_ping_client *client, struct ccn_charbuf *name, long int number) { struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ struct ccn_ping_entry *entry; int res; hashtb_start(client->ccn_ping_table, e); res = hashtb_seek(e, name->buf + 1, name->length - 2, 0); assert(res == HT_NEW_ENTRY); entry = e->data; entry->number = number; gettimeofday(&entry->send_time, NULL); hashtb_end(e); }
/** * Remove internal representation of a content object */ PUBLIC void r_store_forget_content(struct ccnr_handle *h, struct content_entry **pentry) { unsigned i; struct content_entry *entry = *pentry; if (entry == NULL) return; *pentry = NULL; if ((entry->flags & CCN_CONTENT_ENTRY_STALE) != 0) h->n_stale--; if (CCNSHOULDLOG(h, LM_4, CCNL_FINER)) ccnr_debug_content(h, __LINE__, "remove", NULL, entry); /* Remove the cookie reference */ i = entry->cookie & (h->cookie_limit - 1); if (h->content_by_cookie[i] == entry) h->content_by_cookie[i] = NULL; entry->cookie = 0; /* Remove the accession reference */ if (entry->accession != CCNR_NULL_ACCESSION) { struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(h->content_by_accession_tab, e); if (hashtb_seek(e, &entry->accession, sizeof(entry->accession), 0) == HT_NEW_ENTRY) { ccnr_msg(h, "orphaned content %llu", (unsigned long long)(entry->accession)); hashtb_delete(e); hashtb_end(e); return; } hashtb_delete(e); hashtb_end(e); entry->accession = CCNR_NULL_ACCESSION; } /* Clean up allocated subfields */ ccn_charbuf_destroy(&entry->flatname); if (entry->cob != NULL) { h->cob_count--; ccn_charbuf_destroy(&entry->cob); } free(entry); }
static struct ndn_ping_entry *get_ndn_ping_entry(struct ndn_ping_client *client, const unsigned char *interest_msg, const struct ndn_parsed_interest *pi) { struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ struct ndn_ping_entry *entry; int res; hashtb_start(client->ndn_ping_table, e); res = hashtb_seek(e, interest_msg + pi->offset[NDN_PI_B_Component0], pi->offset[NDN_PI_E_LastPrefixComponent] - pi->offset[NDN_PI_B_Component0], 0); assert(res == HT_OLD_ENTRY); entry = e->data; hashtb_end(e); return entry; }
NdnlpPkt LMD_read(LMD self, SockAddr srcaddr) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; int htres; LMDRec rec = NULL; struct ccn_charbuf* hashkey = SockAddr_hashkey(srcaddr); hashtb_start(self->demux, hte); htres = hashtb_seek(hte, hashkey->buf, hashkey->length, 0); if (htres == HT_OLD_ENTRY) { rec = *((LMDRec*)hte->data); } else if (htres == HT_NEW_ENTRY) { hashtb_delete(hte); } hashtb_end(hte); if (rec == NULL) return NULL; NdnlpPkt pkt = LMDRec_read(rec, srcaddr); if (pkt == NULL) { LMD_demux(self); pkt = LMDRec_read(rec, srcaddr); } return pkt; }
void update_nlsa_id_for_name_in_npl(struct name_prefix *np, long int nlsa_id) { struct name_prefix_list_entry *npe; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(nlsr->npl, e); res = hashtb_seek(e, np->name, np->length, 0); if(res == HT_OLD_ENTRY) { npe=e->data; npe->name_lsa_id=nlsa_id; } else { hashtb_delete(e); } hashtb_end(e); }
DataPkt SentPkts_getRetransmit(SentPkts self, DateTime sendBefore) { SentPktRec rec = self->rhead; if (rec == NULL || rec->sendTime >= sendBefore) return NULL; SentPkts_rDetach(self, rec); DataPkt pkt = rec->pkt; if (--rec->retryCount <= 0) { struct hashtb_enumerator htee; struct hashtb_enumerator* hte = &htee; SeqNum sequence = DataPkt_getSequence(pkt); hashtb_start(self->index, hte); hashtb_seek(hte, &sequence, sizeof(SeqNum), 0); hashtb_delete(hte); hashtb_end(hte); SentPkts_sDetach(self, rec); SentPktRec_dtor(rec, true); } else { rec->sendTime = DateTime_now(); SentPkts_rInsert(self, rec); pkt = NdnlpPkt_clone(pkt); } return pkt; }
int does_face_exist_for_router(char *dest_router, int face_id) { if (nlsr->debugging) { printf("does_face_exist_for_router called\n"); printf("Dest Router: %s and Face id: %d \n",dest_router, face_id); } int ret=0; int res; struct routing_table_entry *rte; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ hashtb_start(nlsr->routing_table, e); res = hashtb_seek(e, dest_router, strlen(dest_router), 0); if( res == HT_OLD_ENTRY ) { rte=e->data; unsigned *v; v = hashtb_lookup(rte->face_list, &face_id, sizeof(face_id)); if (v != NULL) ret = 1; } else { hashtb_delete(e); } hashtb_end(e); return ret; }
int get_default_keys(struct ccn* h, struct ccn_signing_params* p, struct ccn_keystore** keystore, struct ccn_pkey** public_key, unsigned char** public_key_digest, size_t* public_key_digest_length, struct ccn_pkey** private_key) { // These structures are supposed to be internal to the libs but // there doesn't appear to be an API to deal with the keystores - // We could use ccn_keystore_init but seem to have to know just // as many implementation details. See ccnsendchunks.c struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res = 0; hashtb_start(h->keystores, e); if (hashtb_seek(e, p->pubid, sizeof(p->pubid), 0) != HT_OLD_ENTRY) { fprintf(stderr,"No default keystore?\n"); res = -1; } else { struct ccn_keystore **pk = e->data; (*keystore) = *pk; (*public_key) = (struct ccn_pkey*) ccn_keystore_public_key(*keystore); (*private_key) = (struct ccn_pkey*) ccn_keystore_private_key(*keystore); (*public_key_digest) = (unsigned char*) ccn_keystore_public_key_digest(*keystore); (*public_key_digest_length) = ccn_keystore_public_key_digest_length(*keystore); } hashtb_end(e); return(res); }
int get_mapping_no(char *router) { struct map_entry *me; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; int ret; int n = hashtb_n(nlsr->map); if ( n < 1) { return NO_MAPPING_NUM; } hashtb_start(nlsr->map, e); res = hashtb_seek(e, router, strlen(router), 0); if( res == HT_OLD_ENTRY ) { me=e->data; ret=me->mapping; } else if(res == HT_NEW_ENTRY) { hashtb_delete(e); ret=NO_MAPPING_NUM; } hashtb_end(e); return ret; }
void add_name_to_npl(struct name_prefix *np) { struct name_prefix_list_entry *npe; struct hashtb_enumerator ee; struct hashtb_enumerator *e = ⅇ int res; hashtb_start(nlsr->npl, e); res = hashtb_seek(e, np->name, np->length, 0); if(res == HT_NEW_ENTRY) { npe=e->data; npe->np=(struct name_prefix *)calloc(1,sizeof(struct name_prefix )); npe->np->length=np->length; npe->np->name=(char *)calloc(np->length,sizeof(char)); memcpy(npe->np->name,np->name,np->length); npe->name_lsa_id=0; } hashtb_end(e); }