mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #389 from mehlis/ccn-lite-follow-up-2
Ccn lite follow up
This commit is contained in:
commit
e01d43e129
@ -58,8 +58,6 @@
|
||||
/** message buffer */
|
||||
msg_t msg_buffer_relay[RELAY_MSG_BUFFER_SIZE];
|
||||
|
||||
uint8_t packet_out[PAYLOAD_SIZE];
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
struct ccnl_relay_s theRelay;
|
||||
@ -71,17 +69,20 @@ ccnl_run_events(void)
|
||||
long usec;
|
||||
|
||||
rtc_time(&now);
|
||||
DEBUGMSG(1, "ccnl_run_events now: %ld:%ld\n", now.tv_sec, now.tv_usec);
|
||||
|
||||
while (eventqueue) {
|
||||
struct ccnl_timer_s *t = eventqueue;
|
||||
usec = timevaldelta(&(t->timeout), &now);
|
||||
|
||||
if (usec >= 0) {
|
||||
DEBUGMSG(1, "ccnl_run_events nothing to do: %ld:%ld\n", now.tv_sec, now.tv_usec);
|
||||
now.tv_sec = usec / 1000000;
|
||||
now.tv_usec = usec % 1000000;
|
||||
return &now;
|
||||
}
|
||||
|
||||
DEBUGMSG(1, "ccnl_run_events run event handler: %ld:%ld\n", now.tv_sec, now.tv_usec);
|
||||
if (t->fct) {
|
||||
(t->fct)(t->node, t->intarg);
|
||||
}
|
||||
@ -124,8 +125,7 @@ void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc,
|
||||
{
|
||||
(void) ccnl; /* unused */
|
||||
|
||||
memcpy(&packet_out, &buf->data, buf->datalen);
|
||||
ifc->sendfunc(packet_out, (uint16_t) buf->datalen, (uint16_t) dest->id);
|
||||
ifc->sendfunc(buf->data, (uint16_t) buf->datalen, (uint16_t) dest->id);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@ -195,6 +195,8 @@ void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries)
|
||||
else {
|
||||
DEBUGMSG(1, "sorry, could not open riot trans device\n");
|
||||
}
|
||||
|
||||
ccnl_set_timer(1000000, ccnl_ageing, relay, 0);
|
||||
}
|
||||
|
||||
#if RIOT_CCNL_POPULATE
|
||||
@ -245,7 +247,7 @@ void ccnl_populate_cache(struct ccnl_relay_s *ccnl, unsigned char *buf, int data
|
||||
}
|
||||
}
|
||||
|
||||
void handle_populate_cache()
|
||||
void handle_populate_cache(void)
|
||||
{
|
||||
DEBUGMSG(1, "ccnl_populate_cache with: text_txt_ccnb\n");
|
||||
ccnl_populate_cache(&theRelay, (unsigned char *) text_txt_ccnb_0, (int) text_txt_ccnb_0_len);
|
||||
@ -308,9 +310,9 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
|
||||
riot_ccnl_msg_t *m;
|
||||
|
||||
while (!ccnl->halt_flag) {
|
||||
// struct timeval *timeout = ccnl_run_events();
|
||||
DEBUGMSG(1, "waiting for incomming msg\n");
|
||||
msg_receive(&in);
|
||||
struct timeval *timeout = ccnl_run_events();
|
||||
|
||||
switch (in.type) {
|
||||
case PKT_PENDING:
|
||||
@ -371,15 +373,14 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
|
||||
* @param pointer to count transceiver pids
|
||||
*
|
||||
*/
|
||||
void ccnl_riot_relay_start(void)
|
||||
void ccnl_riot_relay_start(int max_cache_entries)
|
||||
{
|
||||
int max_cache_entries = 20;
|
||||
|
||||
struct timeval now;
|
||||
theRelay.startup_time = rtc_time(&now);
|
||||
|
||||
DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", now.tv_sec, now.tv_usec);
|
||||
DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__);
|
||||
DEBUGMSG(1, " max_cache_entries: %d\n", max_cache_entries);
|
||||
DEBUGMSG(1, " compile options: %s\n", compile_string());
|
||||
|
||||
ccnl_relay_config(&theRelay, max_cache_entries);
|
||||
|
@ -915,22 +915,34 @@ ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c)
|
||||
DEBUGMSG(99, "ccnl_content_add2cache (%d/%d)\n", ccnl->contentcnt,
|
||||
ccnl->max_cache_entries);
|
||||
|
||||
if (ccnl->max_cache_entries > 0
|
||||
&& ccnl->contentcnt >= ccnl->max_cache_entries) { // remove oldest content
|
||||
struct ccnl_content_s *c2;
|
||||
if (ccnl->max_cache_entries <= 0) {
|
||||
DEBUGMSG(1, " content store disabled...\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (ccnl->max_cache_entries <= ccnl->contentcnt) {
|
||||
DEBUGMSG(1, " remove oldest content...\n");
|
||||
struct ccnl_content_s *c2, *oldest = NULL;
|
||||
int age = 0;
|
||||
|
||||
for (c2 = ccnl->contents; c2; c2 = c2->next)
|
||||
for (c2 = ccnl->contents; c2; c2 = c2->next) {
|
||||
if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC)
|
||||
&& ((age == 0) || c2->last_used < age)) {
|
||||
age = c2->last_used;
|
||||
oldest = c2;
|
||||
}
|
||||
}
|
||||
|
||||
if (c2) {
|
||||
ccnl_content_remove(ccnl, c2);
|
||||
if (oldest) {
|
||||
DEBUGMSG(1, " replaced: '%s'\n",ccnl_prefix_to_path(oldest->name));
|
||||
ccnl_content_remove(ccnl, oldest);
|
||||
} else {
|
||||
DEBUGMSG(1, " no dynamic content to remove...\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUGMSG(1, " add new content to store: '%s'\n", ccnl_prefix_to_path(c->name));
|
||||
DBL_LINKED_LIST_ADD(ccnl->contents, c);
|
||||
ccnl->contentcnt++;
|
||||
return c;
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
@ -60,13 +61,21 @@ int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to)
|
||||
DEBUGMSG(1, "this is a RIOT MSG based connection\n");
|
||||
DEBUGMSG(1, "size=%" PRIu16 " to=%" PRIu16 "\n", size, to);
|
||||
|
||||
static riot_ccnl_msg_t rmsg;
|
||||
rmsg.payload = buf;
|
||||
rmsg.size = size;
|
||||
uint8_t *buf2 = malloc(sizeof(riot_ccnl_msg_t) + size);
|
||||
if (!buf2) {
|
||||
DEBUGMSG(1, " malloc failed...dorpping msg!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
riot_ccnl_msg_t *rmsg = (riot_ccnl_msg_t *) buf2;
|
||||
rmsg->payload = buf2 + sizeof(riot_ccnl_msg_t);
|
||||
rmsg->size = size;
|
||||
|
||||
memcpy(rmsg->payload, buf, size);
|
||||
|
||||
msg_t m;
|
||||
m.type = CCNL_RIOT_MSG;
|
||||
m.content.ptr = (char *) &rmsg;
|
||||
m.content.ptr = (char *) rmsg;
|
||||
DEBUGMSG(1, "sending msg to pid=%u\n", to);
|
||||
msg_send(&m, to, 1);
|
||||
|
||||
|
@ -55,14 +55,29 @@ typedef enum ccnl_riot_event {
|
||||
CCNL_RIOT_RESERVED
|
||||
} ccnl_riot_event_t;
|
||||
|
||||
#define CCNL_RIOT_CHUNK_SIZE 90
|
||||
#define CCNL_HEADER_SIZE (40)
|
||||
|
||||
#ifdef MODULE_NATIVENET
|
||||
/*
|
||||
* static content for testing ccn get has this chunk size
|
||||
* this test (populate + interest /riot/text) current works
|
||||
* only on transceiver which can handle ~130 bytes
|
||||
*/
|
||||
# define CCNL_RIOT_CHUNK_SIZE (90)
|
||||
#else
|
||||
# define CCNL_RIOT_CHUNK_SIZE (PAYLOAD_SIZE - CCNL_HEADER_SIZE)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief starts the ccnl relay
|
||||
*
|
||||
* @note to stop the relay send msg "RIOT_HALT" to this thread
|
||||
*
|
||||
* @param max_cache_entries number of slots in the CS
|
||||
*/
|
||||
void ccnl_riot_relay_start(void);
|
||||
void ccnl_riot_relay_start(int max_cache_entries);
|
||||
|
||||
/**
|
||||
* @brief starts an appication server, which can repy to ccn interests
|
||||
|
@ -70,11 +70,10 @@ int ccnl_riot_client_get(unsigned int relay_pid, char *name, char *reply_buf)
|
||||
|
||||
msg_receive(&rep);
|
||||
riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr;
|
||||
memcpy(&compat_small_buf, rmsg_reply->payload, rmsg_reply->size);
|
||||
unsigned char *data = compat_small_buf;
|
||||
int datalen = (int) rmsg_reply->size;
|
||||
DEBUGMSG(1, "%d bytes left; msg from=%u '%s'\n", datalen, rep.sender_pid, compat_small_buf);
|
||||
|
||||
unsigned char *data = rmsg_reply->payload;
|
||||
int datalen = (int) rmsg_reply->size;
|
||||
DEBUGMSG(1, "%d bytes left; msg from=%u '%s'\n", datalen, rep.sender_pid, data);
|
||||
|
||||
int scope = 3, aok = 3, minsfx = 0, maxsfx = CCNL_MAX_NAME_COMP,
|
||||
contlen = 0;
|
||||
@ -96,6 +95,7 @@ int ccnl_riot_client_get(unsigned int relay_pid, char *name, char *reply_buf)
|
||||
|
||||
free_prefix(p);
|
||||
free_3ptr_list(buf, nonce, ppkd);
|
||||
ccnl_free(rmsg_reply);
|
||||
|
||||
if (contlen < CCNL_RIOT_CHUNK_SIZE || CCNL_RIOT_CHUNK_SIZE < contlen) {
|
||||
/* last chunk */
|
||||
|
Loading…
Reference in New Issue
Block a user