2 This file is part of GNUnet.
\r
3 (C) 2009 Christian Grothoff (and other contributing authors)
\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
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
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
22 * @file fragmentation/test_fragmentation_enhanced.c
\r
23 * @brief testcase for the fragmentation.c
\r
27 #include "platform.h"
\r
28 #include "gnunet_protocols.h"
\r
29 #include "gnunet_fragmentation_lib.h"
\r
32 struct GNUNET_FRAGMENT_Context* ctx;
\r
33 struct GNUNET_PeerIdentity* sender;
\r
36 void message_proc1(void *cls, const struct GNUNET_MessageHeader * msg){
\r
38 fprintf(stderr, "enter into message_proc1\n");
\r
40 struct GNUNET_MessageHeader * originalMsg = (struct GNUNET_MessageHeader *)cls;
\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
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
48 if(memcmp(msg, originalMsg, originalMsg->size)){
\r
49 fprintf(stderr, "the received message is not the sent one!\n");
\r
52 fprintf(stdout, "You got the right message!\n");
\r
57 void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){
\r
59 printf("enter into message_proc2\n");
\r
61 struct combine * com2 = (struct combine* )cls;
\r
62 GNUNET_FRAGMENT_process(com2->ctx, com2->sender, msg);
\r
67 main(int argc, char * argv[]){
\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
78 memset(sender, 9, sizeof(struct GNUNET_PeerIdentity));
\r
80 memset(&msg[1], 5, 2*mtu);
\r
82 struct combine *com;
\r
83 com = (struct combine *)GNUNET_malloc(sizeof(struct combine));
\r
85 com->sender = sender;
\r
86 GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, com);
\r