to be continued
[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+960, originalMsg+960, 68)){\r
22                         fprintf(stderr, "the received message is not the sent one!\n");\r
23         }\r
24 \r
25 }\r
26 \r
27 void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){\r
28         printf("enter into message_proc2\n");\r
29         struct combine * com2 = (struct combine* )cls;\r
30         GNUNET_FRAGMENT_process(com2->ctx, com2->sender, msg);\r
31 }\r
32 \r
33 int\r
34 main(int argc, char * argv[]){\r
35         
36         uint16_t mtu = 512;\r
37         struct GNUNET_FRAGMENT_Context * ctx;\r
38         struct GNUNET_MessageHeader *msg = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)+2*mtu);\r
39         ctx = GNUNET_FRAGMENT_context_create(NULL, message_proc1, msg);\r
40         msg->size = htons(sizeof(struct GNUNET_MessageHeader)+2*mtu);\r
41         msg->type = htons(GNUNET_MESSAGE_TYPE_HELLO);\r
42         struct GNUNET_PeerIdentity *sender;\r
43         sender = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));\r
44 \r
45         memset(sender, 9, sizeof(struct GNUNET_PeerIdentity));\r
46 \r
47         memset(&msg[1], 5, 2*mtu);\r
48         struct combine *com;\r
49         com = GNUNET_malloc(sizeof(struct combine));\r
50         com->ctx = ctx;\r
51         com->sender = sender;\r
52         GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, com);\r
53         GNUNET_free(msg);\r
54         return 0;\r
55 }\r