Skip to content

Commit

Permalink
moved the enum for CCNL_SUITE_* to ccnl.h; moved ccnl_pkt2suite() to …
Browse files Browse the repository at this point in the history
…ccnl-util.c
  • Loading branch information
tschudin committed Jun 19, 2014
1 parent 9fc9570 commit 6b821fc
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 46 deletions.
1 change: 1 addition & 0 deletions ccn-lite-lnxkernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ ccnl_close_socket(struct socket *s)
#include "ccnl-platform.c"
#include "ccnl-ext.h"

#include "ccnl-util.c"
#include "ccnl-core.c"

#ifdef USE_FRAG
Expand Down
1 change: 1 addition & 0 deletions ccn-lite-minimalrelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ ccnl_path_to_prefix(const char *path)

// ----------------------------------------------------------------------

#include "ccnl-util.c"
#include "ccnl-core.c"

// ----------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions ccn-lite-relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
// #define USE_FRAG
// #define USE_ETHERNET
#define USE_HTTP_STATUS
// #define USE_MGMT
#define USE_MGMT
#define USE_SCHEDULER
// #define USE_SUITE_CCNB
#define USE_SUITE_CCNB
// #define USE_SUITE_CCNTLV
// #define USE_SUITE_LOCALRPC
#define USE_SUITE_NDNTLV
Expand All @@ -57,6 +57,7 @@
#define ccnl_app_RX(x,y) do{}while(0)
#define ccnl_print_stats(x,y) do{}while(0)

#include "ccnl-util.c"
#include "ccnl-core.c"

#include "ccnl-ext-http.c"
Expand Down Expand Up @@ -704,7 +705,7 @@ main(int argc, char **argv)
" [-g MIN_INTER_PACKET_INTERVAL]"
" [-i MIN_INTER_CCNMSG_INTERVAL]"
" [-s SUITE (0=ccnb, 2=ndntlv)"
" [-t tcpport]"
" [-t tcpport (for HTML status page)]"
" [-u udpport]"
" [-v DEBUG_LEVEL]"

Expand Down
2 changes: 1 addition & 1 deletion ccn-lite-simu.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ int ccnl_app_RX(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c);
void ccnl_print_stats(struct ccnl_relay_s *relay, int code);
enum {STAT_RCV_I, STAT_RCV_C, STAT_SND_I, STAT_SND_C, STAT_QLEN, STAT_EOP1};

#include "ccnl-core.c"
#include "ccnl-util.c"
#include "ccnl-core.c"

#include "ccnl-ext-mgmt.c"
#include "ccnl-ext-sched.c"
Expand Down
24 changes: 0 additions & 24 deletions ccnl-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,30 +756,6 @@ ccnl_core_cleanup(struct ccnl_relay_s *ccnl)
# include "fwd-ndntlv.c"
#endif

int
ccnl_pkt2suite(unsigned char *data, int len)
{
#ifdef USE_SUITE_CCNB
if (*data == 0x01 || *data == 0x04)
return CCNL_SUITE_CCNB;
#endif

#ifdef USE_SUITE_CCNTLV
if (data[0] == 0 && len > 1) {
if (data[1] == CCNX_TLV_TL_Interest ||
data[1] == CCNX_TLV_TL_Object)
return CCNL_SUITE_CCNTLV;
}
#endif

#ifdef USE_SUITE_NDNTLV
if (*data == 0x05 || *data == 0x06)
return CCNL_SUITE_NDNTLV;
#endif

return -1;
}

void
ccnl_core_RX(struct ccnl_relay_s *relay, int ifndx, unsigned char *data,
int datalen, struct sockaddr *sa, int addrlen)
Expand Down
7 changes: 0 additions & 7 deletions ccnl-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@
#define CCNL_CONTENT_FLAGS_STATIC 0x01
#define CCNL_CONTENT_FLAGS_STALE 0x02

enum {
CCNL_SUITE_CCNB,
CCNL_SUITE_CCNTLV,
CCNL_SUITE_NDNTLV,
CCNL_SUITE_LOCALRPC
};

// ----------------------------------------------------------------------

typedef union {
Expand Down
1 change: 0 additions & 1 deletion ccnl-ext-crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "pkt-ccnb.h"
//#include "pkt-ccnb.c"
#include "ccnl-includes.h"
#include "ccnl.h"
#include "ccnl-ext-mgmt.c"

char buf[64000];
Expand Down
2 changes: 1 addition & 1 deletion ccnl-ext-mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include "pkt-ccnb.h"
#include "pkt-ccnb-enc.c"
#include "ccnl.h"
// #include "ccnl.h"
#include "ccnl-core.h"
#include "ccnl-ext-debug.c"

Expand Down
34 changes: 34 additions & 0 deletions ccnl-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,37 @@ unescape_component(unsigned char *comp) // inplace, returns len after shrinking

// ----------------------------------------------------------------------

int
ccnl_pkt2suite(unsigned char *data, int len)
{
if (len <= 0)
return -1;

#ifdef USE_SUITE_CCNB
if (*data == 0x01 || *data == 0x04)
return CCNL_SUITE_CCNB;
#endif

#ifdef USE_SUITE_CCNTLV
if (data[0] == 0 && len > 1) {
if (data[1] == CCNX_TLV_TL_Interest ||
data[1] == CCNX_TLV_TL_Object)
return CCNL_SUITE_CCNTLV;
}
#endif

#ifdef USE_SUITE_NDNTLV
if (*data == 0x05 || *data == 0x06)
return CCNL_SUITE_NDNTLV;
#endif

#ifdef USE_SUITE_LOCALRPC
if (*data == 0x80)
return CCNL_SUITE_LOCALRPC;
#endif

return -1;
}

// ----------------------------------------------------------------------

6 changes: 6 additions & 0 deletions ccnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
#define CCNL_DEFAULT_MAX_CACHE_ENTRIES 0 // means: no content caching
#define CCNL_MAX_NONCES 256 // for detected dups

enum {
CCNL_SUITE_CCNB,
CCNL_SUITE_CCNTLV,
CCNL_SUITE_NDNTLV,
CCNL_SUITE_LOCALRPC
};

// ----------------------------------------------------------------------
// our own CCN-lite extensions for the ccnb encoding:
Expand Down
36 changes: 27 additions & 9 deletions util/ccn-lite-peek.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,30 @@
#define USE_SUITE_NDNTLV

#include "../ccnl.h"
#include "../ccnl-util.c"

#include "ccnl-common.c"

#ifdef USE_SUITE_CCNB
# include "../pkt-ccnb.h"
#endif

#ifdef USE_SUITE_NDNTLV
# include "../pkt-ndntlv.h"
#endif

#include "../ccnl-util.c"

#ifdef USE_SUITE_CCNB
# include "../pkt-ccnb-dec.c"
# include "../pkt-ccnb-enc.c"
#endif

#ifdef USE_SUITE_NDNTLV
# include "../pkt-ndntlv.h"
# include "../pkt-ndntlv-dec.c"
# include "../pkt-ndntlv-enc.c"
#endif


// ----------------------------------------------------------------------

char *unix_path;
Expand Down Expand Up @@ -239,20 +247,30 @@ request_content(int sock, int (*sendproc)(int,char*,unsigned char*,int),
if (block_on_read(sock, wait) <= 0)
break;
len2 = recv(sock, buf, sizeof(buf), 0);
fprintf(stderr, "received %d bytes\n", len2);
cp = buf;
len = len2;
switch(ccnl_pkt2suite(buf, len)) {
#ifdef USE_SUITE_CCNB
if (len2 < 0 || ccnl_ccnb_dehead(&cp, &len, &dummy, &typ))
case CCNL_SUITE_CCNB:
if (len2 < 0 || ccnl_ccnb_dehead(&cp, &len, &dummy, &typ))
return;
if (typ != CCN_TT_DTAG || dummy != CCN_DTAG_CONTENTOBJ)
continue;
break;
if (typ != CCN_TT_DTAG || dummy != CCN_DTAG_CONTENTOBJ)
continue;
#endif
#ifdef USE_SUITE_CCNB
if (len2 < 0 || ccnl_ndntlv_dehead(&cp, &len, &typ, &dummy))

#ifdef USE_SUITE_NDNTLV
case CCNL_SUITE_NDNTLV:
if (len2 < 0 || ccnl_ndntlv_dehead(&cp, &len, &typ, &dummy))
return;
if (typ != NDN_TLV_Data)
continue;
break;
if (typ != NDN_TLV_Data)
continue;
#endif
default:
return;
}
write(1, buf, len2);
myexit(0);
}
Expand Down

0 comments on commit 6b821fc

Please sign in to comment.