aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation/test_frag_ji.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fragmentation/test_frag_ji.c')
-rw-r--r--src/fragmentation/test_frag_ji.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/fragmentation/test_frag_ji.c b/src/fragmentation/test_frag_ji.c
index 8cba654ad..059994f2b 100644
--- a/src/fragmentation/test_frag_ji.c
+++ b/src/fragmentation/test_frag_ji.c
@@ -1,38 +1,55 @@
1#include "platform.h" 1#include "platform.h"
2#include "gnunet_protocols.h"
2#include "gnunet_fragmentation_lib.h" 3#include "gnunet_fragmentation_lib.h"
3 4
5struct combine{
6 struct GNUNET_FRAGMENT_Context* ctx;
7 struct GNUNET_PeerIdentity* sender;
8};
9
4void message_proc1(void *cls, const struct GNUNET_MessageHeader * msg){ 10void message_proc1(void *cls, const struct GNUNET_MessageHeader * msg){
11 fprintf(stderr, "enter into message_proc1\n");
5 12
6 struct GNUNET_MessageHeader * originalMsg = (struct GNUNET_MessageHeader *)cls; 13 struct GNUNET_MessageHeader * originalMsg = (struct GNUNET_MessageHeader *)cls;
7 if(originalMsg->size != msg->size){ 14
8 fprintf(stderr, "the received message has the different size with the sent one!"); 15 if(ntohs(originalMsg->size) != ntohs(msg->size)){
16 fprintf(stderr, "the received message has the different size with the sent one!\n");
9 } 17 }
10 if(originalMsg->type != msg->type){ 18 if(ntohs(originalMsg->type) != ntohs(msg->type)){
11 fprintf(stderr, "the received message has the different type with the sent one!"); 19 fprintf(stderr, "the received message has the different type with the sent one!\n");
12 } 20 }
13 if(memcmp(&originalMsg[1], &msg[1], originalMsg->size - sizeof(struct GNUNET_MessageHeader))){ 21 if(memcmp(msg+960, originalMsg+960, 68)){
14 fprintf(stderr, "the received message is not the sent one!"); 22 fprintf(stderr, "the received message is not the sent one!\n");
15 } 23 }
16 24
17} 25}
18 26
19void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){ 27void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){
20 struct GNUNET_FRAGMENT_Context * ctx = (struct GNUNET_FRAGMENT_Context * )cls; 28 printf("enter into message_proc2\n");
21 struct Fragment *frag; 29 struct combine * com2 = (struct combine* )cls;
22 struct GNUNET_PeerIdentity sender; 30 GNUNET_FRAGMENT_process(com2->ctx, com2->sender, msg);
23 GNUNET_FRAGMENT_process(ctx, &sender, msg);
24} 31}
25 32
26int 33int
27main(int argc, char * argv[]){ 34main(int argc, char * argv[]){
28 35
36 uint16_t mtu = 512;
29 struct GNUNET_FRAGMENT_Context * ctx; 37 struct GNUNET_FRAGMENT_Context * ctx;
30 struct GNUNET_MessageHeader *msg; 38 struct GNUNET_MessageHeader *msg = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)+2*mtu);
31 ctx = GNUNET_FRAGMENT_context_create(stats, message_proc1, msg); 39 ctx = GNUNET_FRAGMENT_context_create(NULL, message_proc1, msg);
32 msg->size = sizeof(struct GNUNET_MessageHeader)+2*mtu; 40 msg->size = htons(sizeof(struct GNUNET_MessageHeader)+2*mtu);
33 msg->type = GNUNET_MESSAGE_TYPE_HELLO; 41 msg->type = htons(GNUNET_MESSAGE_TYPE_HELLO);
34 memcpy(&msg[1], 5, 2*mtu); 42 struct GNUNET_PeerIdentity *sender;
35 GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, ctx); 43 sender = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
44
45 memset(sender, 9, sizeof(struct GNUNET_PeerIdentity));
36 46
47 memset(&msg[1], 5, 2*mtu);
48 struct combine *com;
49 com = GNUNET_malloc(sizeof(struct combine));
50 com->ctx = ctx;
51 com->sender = sender;
52 GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, com);
53 GNUNET_free(msg);
37 return 0; 54 return 0;
38} 55}