#include "platform.h"\r
+#include "gnunet_protocols.h"\r
#include "gnunet_fragmentation_lib.h"\r
\r
+struct combine{\r
+ struct GNUNET_FRAGMENT_Context* ctx;\r
+ struct GNUNET_PeerIdentity* sender;\r
+};\r
+\r
void message_proc1(void *cls, const struct GNUNET_MessageHeader * msg){\r
+ fprintf(stderr, "enter into message_proc1\n");\r
\r
struct GNUNET_MessageHeader * originalMsg = (struct GNUNET_MessageHeader *)cls;\r
- if(originalMsg->size != msg->size){\r
- fprintf(stderr, "the received message has the different size with the sent one!");\r
+\r
+ if(ntohs(originalMsg->size) != ntohs(msg->size)){\r
+ fprintf(stderr, "the received message has the different size with the sent one!\n");\r
}\r
- if(originalMsg->type != msg->type){\r
- fprintf(stderr, "the received message has the different type with the sent one!");\r
+ if(ntohs(originalMsg->type) != ntohs(msg->type)){\r
+ fprintf(stderr, "the received message has the different type with the sent one!\n");\r
}\r
- if(memcmp(&originalMsg[1], &msg[1], originalMsg->size - sizeof(struct GNUNET_MessageHeader))){\r
- fprintf(stderr, "the received message is not the sent one!");\r
+ if(memcmp(msg, originalMsg, originalMsg->size)){\r
+ fprintf(stderr, "the received message is not the sent one!\n");\r
+ }\r
+ else{\r
+ fprintf(stdout, "You got the right message!\n");\r
}\r
\r
}\r
\r
void message_proc2(void *cls, const struct GNUNET_MessageHeader * msg){\r
- struct GNUNET_FRAGMENT_Context * ctx = (struct GNUNET_FRAGMENT_Context * )cls;\r
- struct Fragment *frag;\r
- struct GNUNET_PeerIdentity sender;\r
- GNUNET_FRAGMENT_process(ctx, &sender, msg);\r
+ printf("enter into message_proc2\n");\r
+ struct combine * com2 = (struct combine* )cls;\r
+ GNUNET_FRAGMENT_process(com2->ctx, com2->sender, msg);\r
+\r
}\r
\r
int\r
main(int argc, char * argv[]){\r
-\r
+
+ uint32_t mtu = 512;\r
struct GNUNET_FRAGMENT_Context * ctx;\r
- struct GNUNET_MessageHeader *msg;\r
- ctx = GNUNET_FRAGMENT_context_create(stats, message_proc1, msg);\r
- msg->size = sizeof(struct GNUNET_MessageHeader)+2*mtu;\r
- msg->type = GNUNET_MESSAGE_TYPE_HELLO;\r
- memcpy(&msg[1], 5, 2*mtu);\r
- GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, ctx);\r
+ struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)+2*mtu);\r
+ ctx = GNUNET_FRAGMENT_context_create(NULL, message_proc1, msg);\r
+ msg->size = htons(sizeof(struct GNUNET_MessageHeader)+4*mtu);\r
+ msg->type = htons(GNUNET_MESSAGE_TYPE_HELLO);\r
+ struct GNUNET_PeerIdentity *sender;\r
+ sender = (struct GNUNET_PeerIdentity *)GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));\r
+\r
+ memset(sender, 9, sizeof(struct GNUNET_PeerIdentity));\r
+\r
+ memset(&msg[1], 5, 2*mtu);\r
\r
+ struct combine *com;\r
+ com = (struct combine *)GNUNET_malloc(sizeof(struct combine));\r
+ com->ctx = ctx;\r
+ com->sender = sender;\r
+ GNUNET_FRAGMENT_fragment(msg, mtu, message_proc2, com);\r
+ GNUNET_free(msg);\r
return 0;\r
}\r