Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/nfn' into nfn
Browse files Browse the repository at this point in the history
  • Loading branch information
basilkohler committed Apr 22, 2014
2 parents f987009 + ace550d commit 6b4c5ac
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 280 deletions.
4 changes: 2 additions & 2 deletions ccn-lite-lnxkernel.c
Expand Up @@ -655,7 +655,7 @@ ccnl_lnxkernel_cleanup(void)
struct dentry *dir = dget_parent(p.dentry);

mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT);
rc = vfs_unlink(dir->d_inode, p.dentry);
rc = vfs_unlink(dir->d_inode, p.dentry, NULL);
mutex_unlock(&dir->d_inode->i_mutex);
dput(dir);
path_put(&p);
Expand All @@ -671,7 +671,7 @@ ccnl_lnxkernel_cleanup(void)
struct dentry *dir = dget_parent(px.dentry);

mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT);
rc = vfs_unlink(dir->d_inode, px.dentry);
rc = vfs_unlink(dir->d_inode, px.dentry, NULL);
mutex_unlock(&dir->d_inode->i_mutex);
dput(dir);
path_put(&px);
Expand Down
58 changes: 28 additions & 30 deletions ccn-lite-relay.c
Expand Up @@ -310,7 +310,7 @@ void ccnl_ageing(void *relay, void *aux)
// ----------------------------------------------------------------------

void
ccnl_relay_config(struct ccnl_relay_s *relay, char *ethdev, int udpport,
ccnl_relay_config(struct ccnl_relay_s *ccnl, char *ethdev, int udpport,
int tcpport, char *uxpath, int max_cache_entries,
char *crypto_face_path)
{
Expand All @@ -319,66 +319,66 @@ ccnl_relay_config(struct ccnl_relay_s *relay, char *ethdev, int udpport,

DEBUGMSG(99, "ccnl_relay_config\n");

relay->max_cache_entries = max_cache_entries;
ccnl->max_cache_entries = max_cache_entries;
#ifdef USE_SCHEDULER
relay->defaultFaceScheduler = ccnl_relay_defaultFaceScheduler;
relay->defaultInterfaceScheduler = ccnl_relay_defaultInterfaceScheduler;
ccnl->defaultFaceScheduler = ccnl_relay_defaultFaceScheduler;
ccnl->defaultInterfaceScheduler = ccnl_relay_defaultInterfaceScheduler;
#endif

#ifdef USE_ETHERNET
// add (real) eth0 interface with index 0:
if (ethdev) {
i = &relay->ifs[relay->ifcount];
i = &ccnl->ifs[ccnl->ifcount];
i->sock = ccnl_open_ethdev(ethdev, &i->addr.eth, CCNL_ETH_TYPE);
i->mtu = 1500;
i->reflect = 1;
i->fwdalli = 1;
if (i->sock >= 0) {
relay->ifcount++;
ccnl->ifcount++;
DEBUGMSG(99, "new ETH interface (%s %s) configured\n",
ethdev, ccnl_addr2ascii(&i->addr));
if (relay->defaultInterfaceScheduler)
i->sched = relay->defaultInterfaceScheduler(relay,
if (ccnl->defaultInterfaceScheduler)
i->sched = ccnl->defaultInterfaceScheduler(ccnl,
ccnl_interface_CTS);
} else
fprintf(stderr, "sorry, could not open eth device\n");
}
#endif // USE_ETHERNET

if (udpport > 0) {
i = &relay->ifs[relay->ifcount];
i = &ccnl->ifs[ccnl->ifcount];
i->sock = ccnl_open_udpdev(udpport, &i->addr.ip4);
// i->frag = CCNL_DGRAM_FRAG_NONE;
i->mtu = CCN_DEFAULT_MTU;
i->fwdalli = 1;
if (i->sock >= 0) {
relay->ifcount++;
ccnl->ifcount++;
DEBUGMSG(99, "new UDP interface (ip4 %s) configured\n",
ccnl_addr2ascii(&i->addr));
if (relay->defaultInterfaceScheduler)
i->sched = relay->defaultInterfaceScheduler(relay,
if (ccnl->defaultInterfaceScheduler)
i->sched = ccnl->defaultInterfaceScheduler(ccnl,
ccnl_interface_CTS);
} else
fprintf(stderr, "sorry, could not open udp device\n");
}

#ifdef USE_HTTP_STATUS
if (tcpport) {
relay->http = ccnl_http_new(relay, tcpport);
ccnl->http = ccnl_http_new(ccnl, tcpport);
}
#endif // USE_HTTP_STATUS

#ifdef USE_UNIXSOCKET
if (uxpath) {
i = &relay->ifs[relay->ifcount];
i = &ccnl->ifs[ccnl->ifcount];
i->sock = ccnl_open_unixpath(uxpath, &i->addr.ux);
i->mtu = 4096;
if (i->sock >= 0) {
relay->ifcount++;
ccnl->ifcount++;
DEBUGMSG(99, "new UNIX interface (%s) configured\n",
ccnl_addr2ascii(&i->addr));
if (relay->defaultInterfaceScheduler)
i->sched = relay->defaultInterfaceScheduler(relay,
if (ccnl->defaultInterfaceScheduler)
i->sched = ccnl->defaultInterfaceScheduler(ccnl,
ccnl_interface_CTS);
} else
fprintf(stderr, "sorry, could not open unix datagram device\n");
Expand All @@ -387,41 +387,41 @@ ccnl_relay_config(struct ccnl_relay_s *relay, char *ethdev, int udpport,
if(crypto_face_path)
{
//sending interface + face
i = &relay->ifs[relay->ifcount];
i = &ccnl->ifs[ccnl->ifcount];
i->sock = ccnl_open_unixpath(crypto_face_path, &i->addr.ux);
i->mtu = 4096;
if (i->sock >= 0) {
relay->ifcount++;
ccnl->ifcount++;
DEBUGMSG(99, "new UNIX interface (%s) configured\n",
ccnl_addr2ascii(&i->addr));
if (relay->defaultInterfaceScheduler)
i->sched = relay->defaultInterfaceScheduler(relay,
if (ccnl->defaultInterfaceScheduler)
i->sched = ccnl->defaultInterfaceScheduler(ccnl,
ccnl_interface_CTS);
ccnl_crypto_create_ccnl_crypto_face(relay, crypto_face_path);
relay->crypto_path = crypto_face_path;
ccnl_crypto_create_ccnl_crypto_face(ccnl, crypto_face_path);
ccnl->crypto_path = crypto_face_path;
} else
fprintf(stderr, "sorry, could not open unix datagram device\n");

//receiving interface
memset(h,0,sizeof(h));
sprintf(h,"%s-2",crypto_face_path);
i = &relay->ifs[relay->ifcount];
i = &ccnl->ifs[ccnl->ifcount];
i->sock = ccnl_open_unixpath(h, &i->addr.ux);
i->mtu = 4096;
if (i->sock >= 0) {
relay->ifcount++;
ccnl->ifcount++;
DEBUGMSG(99, "new UNIX interface (%s) configured\n",
ccnl_addr2ascii(&i->addr));
if (relay->defaultInterfaceScheduler)
i->sched = relay->defaultInterfaceScheduler(relay,
if (ccnl->defaultInterfaceScheduler)
i->sched = ccnl->defaultInterfaceScheduler(ccnl,
ccnl_interface_CTS);
//create_ccnl_crypto_face(relay, crypto_face_path);
} else
fprintf(stderr, "sorry, could not open unix datagram device\n");
}
#endif //USE_SIGNATURES
#endif // USE_UNIXSOCKET
ccnl_set_timer(1000000, ccnl_ageing, relay, 0);
ccnl_set_timer(1000000, ccnl_ageing, ccnl, 0);
}

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -657,8 +657,6 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
}

main_thread = new_thread(0);

DEBUGMSG(1, "This is ccn-lite-relay, starting at %s", ctime(&theRelay.startup_time) + 4);
DEBUGMSG(1, " ccnl-core: %s\n", CCNL_VERSION);
Expand Down
72 changes: 38 additions & 34 deletions ccnl-core.c
Expand Up @@ -32,7 +32,7 @@ int ccnl_crypto(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *orig,
struct ccnl_prefix_s *prefix, struct ccnl_face_s *from);

void
ccnl_nfn_send_signal(int threadid);
ccnl_nfn_continue_computation(struct ccnl_relay_s *ccnl, int configid);

static struct ccnl_interest_s*
ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i);
Expand Down Expand Up @@ -638,7 +638,7 @@ ccnl_interest_propagate(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i)
{
struct ccnl_forward_s *fwd;
DEBUGMSG(99, "ccnl_interest_propagate\n");

ccnl_print_stats(ccnl, STAT_SND_I); // log_send_i

// CONFORM: "A node MUST implement some strategy rule, even if it is only to
Expand All @@ -662,8 +662,12 @@ struct ccnl_interest_s*
ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i)
{
struct ccnl_interest_s *i2;
DEBUGMSG(40, "ccnl_interest_remove %p\n", (void *) i);

DEBUGMSG(40, "ccnl_interest_remove %p ", (void *) i);
int it;
for(it = 0; it < i->prefix->compcnt; ++it){
fprintf(stderr, "/%s", i->prefix->comp[it]);
}
fprintf(stderr, "\n");
while (i->pending) {
struct ccnl_pendint_s *tmp = i->pending->next; \
ccnl_free(i->pending);
Expand All @@ -673,6 +677,7 @@ ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i)
DBL_LINKED_LIST_REMOVE(ccnl->pit, i);
//free_prefix(i->prefix); //TODO: //FIXME: IMPORTANT: memory leak
free_3ptr_list(i->ppkd, i->pkt, i);

return i2;
}

Expand Down Expand Up @@ -878,7 +883,7 @@ ccnl_core_cleanup(struct ccnl_relay_s *ccnl)
// the core logic of CCN:

int
ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
ccnl_core_RX_i_or_c(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from,
unsigned char **data, int *datalen)
{
int rc= -1, scope=3, aok=3, minsfx=0, maxsfx=CCNL_MAX_NAME_COMP, contlen;
Expand All @@ -894,32 +899,32 @@ ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
if (!buf) {
DEBUGMSG(6, " parsing error or no prefix\n"); goto Done;
}
if (nonce && ccnl_nonce_find_or_append(relay, nonce)) {
if (nonce && ccnl_nonce_find_or_append(ccnl, nonce)) {
DEBUGMSG(6, " dropped because of duplicate nonce\n"); //goto Skip; //FIXME //TODO enable goto Skip
}
if (buf->data[0] == 0x01 && buf->data[1] == 0xd2) { // interest
DEBUGMSG(6, " interest=<%s>\n", ccnl_prefix_to_path(p));
ccnl_print_stats(relay, STAT_RCV_I); //log count recv_interest
ccnl_print_stats(ccnl, STAT_RCV_I); //log count recv_interest
if (p->compcnt > 0 && p->comp[0][0] == (unsigned char) 0xc1) goto Skip;
if (p->compcnt == 4 && !memcmp(p->comp[0], "ccnx", 4)) {
rc = ccnl_mgmt(relay, buf, p, from); goto Done;
rc = ccnl_mgmt(ccnl, buf, p, from); goto Done;
}
// CONFORM: Step 1:
if ( aok & 0x01 ) { // honor "answer-from-existing-content-store" flag
for (c = relay->contents; c; c = c->next) {
for (c = ccnl->contents; c; c = c->next) {
if (!ccnl_i_prefixof_c(p, ppkd, minsfx, maxsfx, c)) continue;
// FIXME: should check stale bit in aok here
DEBUGMSG(7, " matching content for interest, content %p\n", (void *) c);
ccnl_print_stats(relay, STAT_SND_C); //log sent_c
ccnl_print_stats(ccnl, STAT_SND_C); //log sent_c
if (from->ifndx >= 0)
ccnl_face_enqueue(relay, from, buf_dup(c->pkt));
ccnl_face_enqueue(ccnl, from, buf_dup(c->pkt));
else
ccnl_app_RX(relay, c);
ccnl_app_RX(ccnl, c);
goto Skip;
}
}
// CONFORM: Step 2: check whether interest is already known
for (i = relay->pit; i; i = i->next) {
for (i = ccnl->pit; i; i = i->next) {
if (!ccnl_prefix_cmp(i->prefix, NULL, p, CMP_EXACT) &&
i->minsuffix == minsfx && i->maxsuffix == maxsfx &&
((!ppkd && !i->ppkd) || buf_equal(ppkd, i->ppkd)) )
Expand All @@ -931,50 +936,50 @@ ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
if(!memcmp(p->comp[p->compcnt-1], "NFN", 3)){
struct ccnl_buf_s *buf2 = buf;
struct ccnl_prefix_s *p2 = p;
i = ccnl_interest_new(relay, from, &buf, &p, minsfx, maxsfx, &ppkd);
i = ccnl_interest_new(ccnl, from, &buf, &p, minsfx, maxsfx, &ppkd);
i->propagate = 0; //TODO: mechanism to set propagate in a meaningful way
ccnl_interest_append_pending(i, from);
if(!i->propagate)ccnl_nfn(relay, buf2, p2, from, 0);
if(!i->propagate)ccnl_nfn(ccnl, buf2, p2, from, NULL);
goto Done;
}
#endif /*CCNL_NFN*/
i = ccnl_interest_new(relay, from, &buf, &p, minsfx, maxsfx, &ppkd);
i = ccnl_interest_new(ccnl, from, &buf, &p, minsfx, maxsfx, &ppkd);
if (i) { // CONFORM: Step 3 (and 4)
DEBUGMSG(7, " created new interest entry %p\n", (void *) i);
if (scope > 2)
ccnl_interest_propagate(relay, i);
ccnl_interest_propagate(ccnl, i);
}
} else if (scope > 2 && (from->flags & CCNL_FACE_FLAGS_FWDALLI)) {
DEBUGMSG(7, " old interest, nevertheless propagated %p\n", (void *) i);
ccnl_interest_propagate(relay, i);
ccnl_interest_propagate(ccnl, i);
}
if (i) { // store the I request, for the incoming face (Step 3)
DEBUGMSG(7, " appending interest entry %p\n", (void *) i);
ccnl_interest_append_pending(i, from);
}
} else { // content
DEBUGMSG(6, " content=<%s>\n", ccnl_prefix_to_path(p));
ccnl_print_stats(relay, STAT_RCV_C); //log count recv_content
ccnl_print_stats(ccnl, STAT_RCV_C); //log count recv_content

#ifdef USE_SIGNATURES
if (p->compcnt == 2 && !memcmp(p->comp[0], "ccnx", 4)
&& !memcmp(p->comp[1], "crypto", 6) &&
from == relay->crypto_face) {
rc = ccnl_crypto(relay, buf, p, from); goto Done;
from == ccnl->crypto_face) {
rc = ccnl_crypto(ccnl, buf, p, from); goto Done;
}
#endif /*USE_SIGNATURES*/

// CONFORM: Step 1:
for (c = relay->contents; c; c = c->next)
for (c = ccnl->contents; c; c = c->next)
if (buf_equal(c->pkt, buf)) goto Skip; // content is dup
c = ccnl_content_new(relay, &buf, &p, &ppkd, content, contlen);
c = ccnl_content_new(ccnl, &buf, &p, &ppkd, content, contlen);
if (c) { // CONFORM: Step 2 (and 3)


#ifdef CCNL_NFN
fprintf(stderr, "PIT Entries: \n");
struct ccnl_interest_s *i_it;
for(i_it = relay->pit; i_it; i_it = i_it->next){
for(i_it = ccnl->pit; i_it; i_it = i_it->next){
int it;
fprintf(stderr, " - ");
for(it = 0; it < i_it->prefix->compcnt; ++it){
Expand All @@ -990,19 +995,18 @@ ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
if(!memcmp(c->name->comp[c->name->compcnt-1], "NFN", 3)){
struct ccnl_interest_s *i_it = NULL;
int found = 0;
for(i_it = relay->pit; i_it; i_it = i_it->next){
for(i_it = ccnl->pit; i_it; i_it = i_it->next){
int md = i_it->prefix->compcnt - c->name->compcnt == 1 ? compute_ccnx_digest(c->pkt) : NULL;
//Check if prefix match and it is a nfn request
int cmp = ccnl_prefix_cmp(c->name, md, i_it->prefix, CMP_MATCH);
DEBUGMSG(99, "CMP: %d, faceid: %d \n", cmp, i_it->from->faceid);
if( ccnl_prefix_cmp(c->name, md, i_it->prefix, CMP_MATCH)
&& i_it->from->faceid < 0){
ccnl_content_add2cache(relay, c);
int threadid = -i_it->from->faceid;
i_it = ccnl_interest_remove(relay, i_it);
DEBUGMSG(49, "Send signal for threadid: %d\n", threadid);
ccnl_nfn_send_signal(threadid);
DEBUGMSG(49, "Done\n");
ccnl_content_add2cache(ccnl, c);
int configid = -i_it->from->faceid;
i_it = ccnl_interest_remove(ccnl, i_it);
DEBUGMSG(49, "Continue configuration for configid: %d\n", configid);
ccnl_nfn_continue_computation(ccnl, configid);
++found;
goto Done;
}
Expand All @@ -1011,15 +1015,15 @@ ccnl_core_RX_i_or_c(struct ccnl_relay_s *relay, struct ccnl_face_s *from,
DEBUGMSG(99, "no running computation found \n");
}
#endif
if (!ccnl_content_serve_pending(relay, c)) { // unsolicited content
if (!ccnl_content_serve_pending(ccnl, c)) { // unsolicited content
// CONFORM: "A node MUST NOT forward unsolicited data [...]"
DEBUGMSG(7, " removed because no matching interest\n");
free_content(c);
goto Skip;
}
if (relay->max_cache_entries != 0) { // it's set to -1 or a limit
if (ccnl->max_cache_entries != 0) { // it's set to -1 or a limit
DEBUGMSG(7, " adding content to cache\n");
ccnl_content_add2cache(relay, c);
ccnl_content_add2cache(ccnl, c);
} else {
DEBUGMSG(7, " content not added to cache\n");
free_content(c);
Expand Down

0 comments on commit 6b4c5ac

Please sign in to comment.