authentication of ciphertexts (+ seed)
[oweals/gnunet.git] / src / fragmentation / test_fragmentation_enhanced.c
1 /*\r
2      This file is part of GNUnet.\r
3      (C) 2009 Christian Grothoff (and other contributing authors)\r
4 \r
5      GNUnet is free software; you can redistribute it and/or modify\r
6      it under the terms of the GNU General Public License as published\r
7      by the Free Software Foundation; either version 3, or (at your\r
8      option) any later version.\r
9 \r
10      GNUnet is distributed in the hope that it will be useful, but\r
11      WITHOUT ANY WARRANTY; without even the implied warranty of\r
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
13      General Public License for more details.\r
14 \r
15      You should have received a copy of the GNU General Public License\r
16      along with GNUnet; see the file COPYING.  If not, write to the\r
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
18      Boston, MA 02111-1307, USA.\r
19 */\r
20 \r
21 /**\r
22  * @file fragmentation/test_fragmentation_enhanced.c\r
23  * @brief testcase for the fragmentation.c\r
24  * @author Ji Lu\r
25  */\r
26 \r
27 #include "platform.h"\r
28 #include "gnunet_protocols.h"\r
29 #include "gnunet_fragmentation_lib.h"\r
30 \r
31 struct combine{\r
32         struct GNUNET_FRAGMENT_Context* ctx;\r
33         struct GNUNET_PeerIdentity* sender;\r
34 };\r
35 \r
36 void message_proc1(void *cls, const struct GNUNET_MessageHeader * msg){\r
37 \r
38         fprintf(stderr, "enter into message_proc1\n");\r
39 \r
40         struct GNUNET_MessageHeader * originalMsg = (struct GNUNET_MessageHeader *)cls;\r
41 \r
42         if(ntohs(originalMsg->size) != ntohs(msg->size)){\r
43                         fprintf(stderr, "the received message has the different size with the sent one!\n");\r
44                 }\r
45         if(ntohs(originalMsg->type) != ntohs(msg->type)){\r
46                         fprintf(stderr, "the received message has the different type with the sent one!\n");\r
47                 }\r
48         if(memcmp(msg, originalMsg, originalMsg->size)){\r
49                         fprintf(stderr, "the received message is not the sent one!\n");\r
50         }\r
51         else{\r
52                         fprintf(stdout, "You got the right message!\n");\r
53         }\r
54 \r
55 }\r
56 \r
57 void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){\r
58 \r
59         printf("enter into message_proc2\n");\r
60 \r
61         struct combine * com2 = (struct combine* )cls;\r
62         GNUNET_FRAGMENT_process(com2->ctx, com2->sender, msg);\r
63 \r
64 }\r
65 \r
66 int\r
67 main(int argc, char * argv[]){\r
68         
69         uint32_t mtu = 512;\r
70         struct GNUNET_FRAGMENT_Context * ctx;\r
71         struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)+2*mtu);\r
72         ctx = GNUNET_FRAGMENT_context_create(NULL, message_proc1, msg);\r
73         msg->size = htons(sizeof(struct GNUNET_MessageHeader)+4*mtu);\r
74         msg->type = htons(GNUNET_MESSAGE_TYPE_HELLO);\r
75         struct GNUNET_PeerIdentity *sender;\r
76         sender = (struct GNUNET_PeerIdentity *)GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));\r
77 \r
78         memset(sender, 9, sizeof(struct GNUNET_PeerIdentity));\r
79 \r
80         memset(&msg[1], 5, 2*mtu);\r
81 \r
82         struct combine *com;\r
83         com = (struct combine *)GNUNET_malloc(sizeof(struct combine));\r
84         com->ctx = ctx;\r
85         com->sender = sender;\r
86         GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, com);\r
87         GNUNET_free(msg);\r
88         return 0;\r
89 }\r