aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation/fragmentation.c
diff options
context:
space:
mode:
authorJi Lu <jilu@140774ce-b5e7-0310-ab8b-a85725594a96>2010-04-01 14:56:59 +0000
committerJi Lu <jilu@140774ce-b5e7-0310-ab8b-a85725594a96>2010-04-01 14:56:59 +0000
commit6dac073d8bdd079f31b147ee35757d86fcac0246 (patch)
tree625be9e16ea3a2bf9dee369235ea6ebe792ebc92 /src/fragmentation/fragmentation.c
parenta6f8b3403ad79d6e7823637e48a5118ca5731f72 (diff)
downloadgnunet-6dac073d8bdd079f31b147ee35757d86fcac0246.tar.gz
gnunet-6dac073d8bdd079f31b147ee35757d86fcac0246.zip
to be continued
Diffstat (limited to 'src/fragmentation/fragmentation.c')
-rw-r--r--src/fragmentation/fragmentation.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c
index c67059f34..74d5a6b4c 100644
--- a/src/fragmentation/fragmentation.c
+++ b/src/fragmentation/fragmentation.c
@@ -47,21 +47,22 @@ struct Fragment
47 /** 47 /**
48 * Fragment offset. 48 * Fragment offset.
49 */ 49 */
50 uint32_t off GNUNET_PACKED; 50 uint16_t off GNUNET_PACKED;
51 51
52 /** 52 /**
53 * "unique" id for the fragment 53 * "unique" id for the fragment
54 */ 54 */
55 uint64_t id GNUNET_PACKED; 55 uint32_t id GNUNET_PACKED;
56
57 uint16_t mtu;
58 uint16_t totalNum;
59 uint16_t totalSize;
56 60
57 size_t mtu;
58 uint32_t totalNum;
59 uint64_t totalSize;
60}; 61};
61 62
62struct GNUNET_FRAGEMENT_Ctxbuffer{ 63struct GNUNET_FRAGEMENT_Ctxbuffer{
63 struct GNUNET_FRAGEMENT_Ctxbuffer *next; 64 struct GNUNET_FRAGEMENT_Ctxbuffer *next;
64 uint64_t id; 65 uint32_t id;
65 uint16_t size; 66 uint16_t size;
66 char * buff; 67 char * buff;
67 int counter; 68 int counter;
@@ -99,6 +100,7 @@ GNUNET_FRAGMENT_fragment (const struct GNUNET_MessageHeader *msg,
99{ 100{
100 uint32_t id = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256); 101 uint32_t id = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256);
101 size_t size = sizeof(struct Fragment); 102 size_t size = sizeof(struct Fragment);
103
102 if(ntohs(msg->size) > mtu-size){ 104 if(ntohs(msg->size) > mtu-size){
103 uint16_t lastSize; 105 uint16_t lastSize;
104 uint16_t num; 106 uint16_t num;
@@ -115,14 +117,14 @@ GNUNET_FRAGMENT_fragment (const struct GNUNET_MessageHeader *msg,
115 struct Fragment *frag; 117 struct Fragment *frag;
116 if(actualNum != num){ 118 if(actualNum != num){
117 if(i!=actualNum-1){ 119 if(i!=actualNum-1){
118 frag = GNUNET_malloc(mtu); 120 frag = (struct Fragment *)GNUNET_malloc(mtu);
119 } 121 }
120 else{ 122 else{
121 frag = GNUNET_malloc(lastSize+size); 123 frag = (struct Fragment *)GNUNET_malloc(lastSize+size);
122 } 124 }
123 } 125 }
124 else{ 126 else{
125 frag = GNUNET_malloc(mtu); 127 frag = (struct Fragment *)GNUNET_malloc(mtu);
126 } 128 }
127 frag->header.type = htons(GNUNET_MESSAGE_TYPE_FRAGMENT); 129 frag->header.type = htons(GNUNET_MESSAGE_TYPE_FRAGMENT);
128 frag->id = htonl(id); 130 frag->id = htonl(id);
@@ -130,19 +132,20 @@ GNUNET_FRAGMENT_fragment (const struct GNUNET_MessageHeader *msg,
130 frag->mtu = htons(mtu); 132 frag->mtu = htons(mtu);
131 frag->totalNum = htons(actualNum); 133 frag->totalNum = htons(actualNum);
132 frag->totalSize = msg->size; 134 frag->totalSize = msg->size;
135 char *m = (char *)msg;
133 if(actualNum != num){ 136 if(actualNum != num){
134 if(i!=actualNum-1){ 137 if(i!=actualNum-1){
135 frag->header.size = htons(mtu); 138 frag->header.size = frag->mtu;
136 memcpy(&frag[1], msg + ntohs(frag->off), mtu - size); 139 memcpy(&frag[1], m + (mtu-size)*i, mtu - size);
137 } 140 }
138 else{ 141 else{
139 frag->header.size = htons(lastSize+size); 142 frag->header.size = htons(lastSize+size);
140 memcpy(&frag[1], msg + ntohs(frag->off), lastSize); 143 memcpy(&frag[1], m + (mtu-size)*i, lastSize);
141 } 144 }
142 } 145 }
143 else{ 146 else{
144 frag->header.size = htons(mtu); 147 frag->header.size = frag->mtu;
145 memcpy(&frag[1], msg + ntohs(frag->off), mtu - size); 148 memcpy(&frag[1], m + (mtu-size)*i, mtu - size);
146 } 149 }
147 proc(proc_cls, &frag->header); 150 proc(proc_cls, &frag->header);
148 GNUNET_free(frag); 151 GNUNET_free(frag);
@@ -234,7 +237,7 @@ GNUNET_FRAGMENT_process (struct GNUNET_FRAGMENT_Context *ctx,
234 } 237 }
235 238
236 if(!exist){ 239 if(!exist){
237 buffer = GNUNET_malloc(sizeof(struct GNUNET_FRAGEMENT_Ctxbuffer)); 240 buffer = (struct GNUNET_FRAGEMENT_Ctxbuffer*)GNUNET_malloc(sizeof(struct GNUNET_FRAGEMENT_Ctxbuffer));
238 buffer->num = (int*)GNUNET_malloc(ntohs(frag->totalNum)*sizeof(int)); 241 buffer->num = (int*)GNUNET_malloc(ntohs(frag->totalNum)*sizeof(int));
239 int j; 242 int j;
240 for(j = 0; j<ntohs(frag->totalNum); j++){ 243 for(j = 0; j<ntohs(frag->totalNum); j++){
@@ -243,9 +246,9 @@ GNUNET_FRAGMENT_process (struct GNUNET_FRAGMENT_Context *ctx,
243 buffer->peerID = sender; 246 buffer->peerID = sender;
244 buffer->id = ntohl(frag->id); 247 buffer->id = ntohl(frag->id);
245 buffer->receivedTime = GNUNET_TIME_absolute_get (); 248 buffer->receivedTime = GNUNET_TIME_absolute_get ();
246 uint64_t si = ntohs(frag->totalSize); 249 uint16_t si = ntohs(frag->totalSize);
247 buffer->size = si; 250 buffer->size = si;
248 buffer->buff = (char *)GNUNET_malloc(si); 251 buffer->buff = (char*)GNUNET_malloc(si);
249 buffer->next = ctx->buffer; 252 buffer->next = ctx->buffer;
250 ctx->buffer = buffer; 253 ctx->buffer = buffer;
251 } 254 }