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