-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
85 lines (72 loc) · 2.28 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (C) 2019 Tianyuan Yu
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*
* See AUTHORS.md for complete list of NDN IOT PKG authors and contributors.
*/
#include <stdio.h>
#include "../../adaptation/ndn-lite.h"
#include "../../adaptation/gnrc-netface/netface.h"
#include "ndn-lite/encode/name.h"
#include "ndn-lite/encode/data.h"
#include "ndn-lite/encode/interest.h"
#include "ndn-lite/security/ndn-lite-rng.h"
#include <kernel_types.h>
#include <thread.h>
#include "xtimer.h"
#include "shell.h"
static ndn_interest_t interest;
static uint8_t buffer[250];
bool running = false;
void
on_data(const uint8_t* rawdata, uint32_t data_size, void* userdata)
{
ndn_data_t data;
printf("On data\n");
if(ndn_data_tlv_decode_digest_verify(&data, rawdata, data_size)){
printf("Decoding failed.\n");
}
for (int i = 0; i < 100; i++)
printf("It says: %d\n", *(data.content_value + i));
running = false;
}
void
on_timeout(void* userdata)
{
printf("On timeout\n");
running = false;
}
int main(void)
{
printf("/**** Application Is Running: PID = %" PRIkernel_pid " ****/\n",
thread_getpid());
ndn_lite_startup();
ndn_netface_t* netface = ndn_netface_get_list();
ndn_face_intf_t* face_ptr = &netface[0].intf;
ndn_forwarder_add_route_by_str(face_ptr, "/ndn", strlen("/ndn"));
ndn_name_from_string(&interest.name, "/ndn/test", strlen("/ndn/test"));
ndn_name_print(&interest.name);
ndn_interest_set_MustBeFresh(&interest, true);
ndn_interest_set_CanBePrefix(&interest, true);
ndn_rng(&interest.nonce, sizeof(interest.nonce));
interest.lifetime = 5000;
printf("expressing interest\n");
ndn_encoder_t encoder;
encoder_init(&encoder, buffer, sizeof(buffer));
int ret = ndn_interest_tlv_encode(&encoder, &interest);
if (ret == 0) {
printf("interest encoding success\n");
}
ndn_forwarder_express_interest(encoder.output_value, encoder.offset, on_data, on_timeout, NULL);
running = true;
while(running) {
ndn_forwarder_process();
xtimer_sleep(1);
}
printf("current time (after quitting) is %ld ms\n", ndn_time_now_ms());
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
}