1 #include "platform.h"
\r
2 #include "gnunet_protocols.h"
\r
3 #include "gnunet_fragmentation_lib.h"
\r
6 struct GNUNET_FRAGMENT_Context* ctx;
\r
7 struct GNUNET_PeerIdentity* sender;
\r
10 void message_proc1(void *cls, const struct GNUNET_MessageHeader * msg){
\r
11 fprintf(stderr, "enter into message_proc1\n");
\r
13 struct GNUNET_MessageHeader * originalMsg = (struct GNUNET_MessageHeader *)cls;
\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
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
21 if(memcmp(msg, originalMsg, originalMsg->size)){
\r
22 fprintf(stderr, "the received message is not the sent one!\n");
\r
25 fprintf(stdout, "You got the right message!\n");
\r
30 void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){
\r
31 printf("enter into message_proc2\n");
\r
32 struct combine * com2 = (struct combine* )cls;
\r
33 GNUNET_FRAGMENT_process(com2->ctx, com2->sender, msg);
\r
38 main(int argc, char * argv[]){
\r
41 struct GNUNET_FRAGMENT_Context * ctx;
\r
42 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)+2*mtu);
\r
43 ctx = GNUNET_FRAGMENT_context_create(NULL, message_proc1, msg);
\r
44 msg->size = htons(sizeof(struct GNUNET_MessageHeader)+4*mtu);
\r
45 msg->type = htons(GNUNET_MESSAGE_TYPE_HELLO);
\r
46 struct GNUNET_PeerIdentity *sender;
\r
47 sender = (struct GNUNET_PeerIdentity *)GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
\r
49 memset(sender, 9, sizeof(struct GNUNET_PeerIdentity));
\r
51 memset(&msg[1], 5, 2*mtu);
\r
53 struct combine *com;
\r
54 com = (struct combine *)GNUNET_malloc(sizeof(struct combine));
\r
56 com->sender = sender;
\r
57 GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, com);
\r