(no commit message)
[oweals/gnunet.git] / src / fragmentation / test_frag_ji.c
1 #include "platform.h"\r
2 #include "gnunet_protocols.h"\r
3 #include "gnunet_fragmentation_lib.h"\r
4 \r
5 struct combine{\r
6         struct GNUNET_FRAGMENT_Context* ctx;\r
7         struct GNUNET_PeerIdentity* sender;\r
8 };\r
9 \r
10 void message_proc1(void *cls, const struct GNUNET_MessageHeader * msg){\r
11         fprintf(stderr, "enter into message_proc1\n");\r
12 \r
13         struct GNUNET_MessageHeader * originalMsg = (struct GNUNET_MessageHeader *)cls;\r
14 \r
15         if(ntohs(originalMsg->size) != ntohs(msg->size)){\r
16                         fprintf(stderr, "the received message has the different size with the sent one!\n");\r
17                 }\r
18         if(ntohs(originalMsg->type) != ntohs(msg->type)){\r
19                         fprintf(stderr, "the received message has the different type with the sent one!\n");\r
20                 }\r
21         if(memcmp(msg, originalMsg, originalMsg->size)){\r
22                         fprintf(stderr, "the received message is not the sent one!\n");\r
23         }\r
24         else{\r
25                 fprintf(stdout, "You got the right message!\n");\r
26         }\r
27 \r
28 }\r
29 \r
30 void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){\r
31         printf("enter into message_proc2\n");\r
32         struct combine * com2 = (struct combine* )cls;\r
33         GNUNET_FRAGMENT_process(com2->ctx, com2->sender, msg);\r
34 \r
35 }\r
36 \r
37 int\r
38 main(int argc, char * argv[]){\r
39         
40         uint32_t mtu = 512;\r
41         struct GNUNET_FRAGMENT_Context * ctx;\r
42         struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)+2*mtu);\r
43         ctx = GNUNET_FRAGMENT_context_create(NULL, message_proc1, msg);\r
44         msg->size = htons(sizeof(struct GNUNET_MessageHeader)+4*mtu);\r
45         msg->type = htons(GNUNET_MESSAGE_TYPE_HELLO);\r
46         struct GNUNET_PeerIdentity *sender;\r
47         sender = (struct GNUNET_PeerIdentity *)GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));\r
48 \r
49         memset(sender, 9, sizeof(struct GNUNET_PeerIdentity));\r
50 \r
51         memset(&msg[1], 5, 2*mtu);\r
52 \r
53         struct combine *com;\r
54         com = (struct combine *)GNUNET_malloc(sizeof(struct combine));\r
55         com->ctx = ctx;\r
56         com->sender = sender;\r
57         GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, com);\r
58         GNUNET_free(msg);\r
59         return 0;\r
60 }\r