aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-08 13:52:48 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-08 13:52:48 +0000
commiteb9946906b648956195b9de60bfbde047956810f (patch)
tree7743b755d8512d0df6335ac72d72f7598115b1d4 /src
parent25392eeb76fe54b71bdf5b855eeaafb29560e899 (diff)
downloadgnunet-eb9946906b648956195b9de60bfbde047956810f.tar.gz
gnunet-eb9946906b648956195b9de60bfbde047956810f.zip
-stylistic fixes
Diffstat (limited to 'src')
-rw-r--r--src/stream/stream_api.c186
-rw-r--r--src/stream/stream_protocol.h2
2 files changed, 100 insertions, 88 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c
index c16d1f54f..faceac297 100644
--- a/src/stream/stream_api.c
+++ b/src/stream/stream_api.c
@@ -32,6 +32,7 @@
32 32
33#define MAX_PACKET_SIZE 64000 33#define MAX_PACKET_SIZE 64000
34 34
35
35/** 36/**
36 * states in the Protocol 37 * states in the Protocol
37 */ 38 */
@@ -122,6 +123,11 @@ struct MessageQueue
122 * The next message in queue. Should be NULL in the last message 123 * The next message in queue. Should be NULL in the last message
123 */ 124 */
124 struct MessageQueue *next; 125 struct MessageQueue *next;
126
127 /**
128 * The next message in queue. Should be NULL in the last message
129 */
130 struct MessageQueue *prev;
125}; 131};
126 132
127 133
@@ -130,25 +136,26 @@ struct MessageQueue
130 */ 136 */
131struct GNUNET_STREAM_Socket 137struct GNUNET_STREAM_Socket
132{ 138{
139
133 /** 140 /**
134 * The mesh handle 141 * The peer identity of the peer at the other end of the stream
135 */ 142 */
136 struct GNUNET_MESH_Handle *mesh; 143 struct GNUNET_PeerIdentity other_peer;
137 144
138 /** 145 /**
139 * The mesh tunnel handle 146 * Retransmission timeout
140 */ 147 */
141 struct GNUNET_MESH_Tunnel *tunnel; 148 struct GNUNET_TIME_Relative retransmit_timeout;
142 149
143 /** 150 /**
144 * The session id associated with this stream connection 151 * The mesh handle
145 */ 152 */
146 uint32_t session_id; 153 struct GNUNET_MESH_Handle *mesh;
147 154
148 /** 155 /**
149 * The peer identity of the peer at the other end of the stream 156 * The mesh tunnel handle
150 */ 157 */
151 struct GNUNET_PeerIdentity other_peer; 158 struct GNUNET_MESH_Tunnel *tunnel;
152 159
153 /** 160 /**
154 * Stream open closure 161 * Stream open closure
@@ -161,49 +168,49 @@ struct GNUNET_STREAM_Socket
161 GNUNET_STREAM_OpenCallback open_cb; 168 GNUNET_STREAM_OpenCallback open_cb;
162 169
163 /** 170 /**
164 * Retransmission timeout 171 * The current transmit handle (if a pending transmit request exists)
165 */ 172 */
166 struct GNUNET_TIME_Relative retransmit_timeout; 173 struct GNUNET_MESH_TransmitHandle *transmit_handle;
167 174
168 /** 175 /**
169 * The state of the protocol associated with this socket 176 * The current message associated with the transmit handle
170 */ 177 */
171 enum State state; 178 struct MessageQueue *queue_head;
172 179
173 /** 180 /**
174 * The status of the socket 181 * The queue tail, should always point to the last message in queue
175 */ 182 */
176 enum GNUNET_STREAM_Status status; 183 struct MessageQueue *queue_tail;
177 184
178 /** 185 /**
179 * The current transmit handle (if a pending transmit request exists) 186 * The write IO_handle associated with this socket
180 */ 187 */
181 struct GNUNET_MESH_TransmitHandle *transmit_handle; 188 struct GNUNET_STREAM_IOHandle *write_handle;
182 189
183 /** 190 /**
184 * The current message associated with the transmit handle 191 * The read IO_handle associated with this socket
185 */ 192 */
186 struct MessageQueue *queue; 193 struct GNUNET_STREAM_IOHandle *read_handle;
187 194
188 /** 195 /**
189 * The queue tail, should always point to the last message in queue 196 * The state of the protocol associated with this socket
190 */ 197 */
191 struct MessageQueue *queue_tail; 198 enum State state;
192 199
193 /** 200 /**
194 * The number of previous timeouts 201 * The status of the socket
195 */ 202 */
196 unsigned int retries; 203 enum GNUNET_STREAM_Status status;
197 204
198 /** 205 /**
199 * The write IO_handle associated with this socket 206 * The number of previous timeouts; FIXME: currently not used
200 */ 207 */
201 struct GNUNET_STREAM_IOHandle *write_handle; 208 unsigned int retries;
202 209
203 /** 210 /**
204 * The read IO_handle associated with this socket 211 * The session id associated with this stream connection
205 */ 212 */
206 struct GNUNET_STREAM_IOHandle *read_handle; 213 uint32_t session_id;
207 214
208 /** 215 /**
209 * Write sequence number. Start at random upon reaching ESTABLISHED state 216 * Write sequence number. Start at random upon reaching ESTABLISHED state
@@ -229,11 +236,6 @@ struct GNUNET_STREAM_ListenSocket
229 struct GNUNET_MESH_Handle *mesh; 236 struct GNUNET_MESH_Handle *mesh;
230 237
231 /** 238 /**
232 * The service port
233 */
234 GNUNET_MESH_ApplicationType port;
235
236 /**
237 * The callback function which is called after successful opening socket 239 * The callback function which is called after successful opening socket
238 */ 240 */
239 GNUNET_STREAM_ListenCallback listen_cb; 241 GNUNET_STREAM_ListenCallback listen_cb;
@@ -242,6 +244,11 @@ struct GNUNET_STREAM_ListenSocket
242 * The call back closure 244 * The call back closure
243 */ 245 */
244 void *listen_cb_cls; 246 void *listen_cb_cls;
247
248 /**
249 * The service port
250 */
251 GNUNET_MESH_ApplicationType port;
245}; 252};
246 253
247 254
@@ -284,8 +291,10 @@ send_message_notify (void *cls, size_t size, void *buf)
284 struct MessageQueue *head; 291 struct MessageQueue *head;
285 size_t ret; 292 size_t ret;
286 293
287 head = socket->queue;
288 socket->transmit_handle = NULL; /* Remove the transmit handle */ 294 socket->transmit_handle = NULL; /* Remove the transmit handle */
295 head = socket->queue_head;
296 if (NULL == head)
297 return 0; /* just to be safe */
289 if (0 == size) /* request timed out */ 298 if (0 == size) /* request timed out */
290 { 299 {
291 socket->retries++; 300 socket->retries++;
@@ -312,11 +321,12 @@ send_message_notify (void *cls, size_t size, void *buf)
312 { 321 {
313 head->finish_cb (socket, head->finish_cb_cls); 322 head->finish_cb (socket, head->finish_cb_cls);
314 } 323 }
315 324 GNUNET_CONTAINER_DLL_remove (socket->queue_head,
316 socket->queue = head->next; /* Will be NULL if the queue is empty */ 325 socket->queue_tail,
326 head);
317 GNUNET_free (head->message); 327 GNUNET_free (head->message);
318 GNUNET_free (head); 328 GNUNET_free (head);
319 head = socket->queue; 329 head = socket->queue_head;
320 if (NULL != head) /* more pending messages to send */ 330 if (NULL != head) /* more pending messages to send */
321 { 331 {
322 socket->retries = 0; 332 socket->retries = 0;
@@ -355,28 +365,22 @@ queue_message (struct GNUNET_STREAM_Socket *socket,
355 queue_entity->message = message; 365 queue_entity->message = message;
356 queue_entity->finish_cb = finish_cb; 366 queue_entity->finish_cb = finish_cb;
357 queue_entity->finish_cb_cls = finish_cb_cls; 367 queue_entity->finish_cb_cls = finish_cb_cls;
358 queue_entity->next = NULL; 368 GNUNET_CONTAINER_DLL_insert_tail (socket->queue_head,
359 369 socket->queue_tail,
360 if (NULL == socket->queue) 370 queue_entity);
361 { 371 if (NULL == socket->transmit_handle)
362 socket->queue = queue_entity; 372 {
363 socket->queue_tail = queue_entity; 373 socket->retries = 0;
364 socket->retries = 0; 374 socket->transmit_handle =
365 socket->transmit_handle = 375 GNUNET_MESH_notify_transmit_ready (socket->tunnel,
366 GNUNET_MESH_notify_transmit_ready (socket->tunnel, 376 0, /* Corking */
367 0, /* Corking */ 377 1, /* Priority */
368 1, /* Priority */ 378 socket->retransmit_timeout,
369 socket->retransmit_timeout, 379 &socket->other_peer,
370 &socket->other_peer, 380 ntohs (message->header.size),
371 ntohs (message->header.size), 381 &send_message_notify,
372 &send_message_notify, 382 socket);
373 socket); 383 }
374 }
375 else /* There is a pending message in queue */
376 {
377 socket->queue_tail->next = queue_entity; /* Add to tail */
378 socket->queue_tail = queue_entity;
379 }
380} 384}
381 385
382 386
@@ -385,17 +389,18 @@ queue_message (struct GNUNET_STREAM_Socket *socket,
385 * 389 *
386 * @param bitmap the bitmap to modify 390 * @param bitmap the bitmap to modify
387 * @param bit the bit number to modify 391 * @param bit the bit number to modify
388 * @param GNUNET_YES to on, GNUNET_NO to off 392 * @param value GNUNET_YES to on, GNUNET_NO to off
389 */ 393 */
390static void 394static void
391AckBitmap_modify_bit (GNUNET_STREAM_AckBitmap *bitmap, 395AckBitmap_modify_bit (GNUNET_STREAM_AckBitmap *bitmap,
392 uint8_t bit, 396 unsigned int bit,
393 uint8_t value) 397 int value)
394{ 398{
395 uint64_t val; 399 GNUNET_assert (bit < 64);
396 400 if (GNUNET_YES == value)
397 val = value; 401 *bitmap |= (1LL << bit);
398 *bitmap = *bitmap | (val << bit); 402 else
403 *bitmap &= ~(1LL << bit);
399} 404}
400 405
401 406
@@ -407,9 +412,10 @@ AckBitmap_modify_bit (GNUNET_STREAM_AckBitmap *bitmap,
407 */ 412 */
408static uint8_t 413static uint8_t
409AckBitmap_is_bit_set (const GNUNET_STREAM_AckBitmap *bitmap, 414AckBitmap_is_bit_set (const GNUNET_STREAM_AckBitmap *bitmap,
410 uint8_t bit) 415 unsigned int bit)
411{ 416{
412 return (*bitmap & (0x0000000000000001 << bit)) >> bit; 417 GNUNET_assert (bit < 64);
418 return 0 != (*bitmap & (1LL << bit));
413} 419}
414 420
415 421
@@ -456,7 +462,7 @@ client_handle_data (void *cls,
456/** 462/**
457 * Callback to set state to ESTABLISHED 463 * Callback to set state to ESTABLISHED
458 * 464 *
459 * @param cls the closure from queue_message 465 * @param cls the closure from queue_message FIXME: document
460 * @param socket the socket to requiring state change 466 * @param socket the socket to requiring state change
461 */ 467 */
462static void 468static void
@@ -510,12 +516,13 @@ client_handle_hello_ack (void *cls,
510 516
511 ack_msg = (const struct GNUNET_STREAM_HelloAckMessage *) message; 517 ack_msg = (const struct GNUNET_STREAM_HelloAckMessage *) message;
512 GNUNET_assert (socket->tunnel == tunnel); 518 GNUNET_assert (socket->tunnel == tunnel);
513 if (STATE_HELLO_WAIT == socket->state) 519 switch (socket->state)
514 { 520 {
521 case STATE_HELLO_WAIT:
515 socket->read_sequence_number = ntohl (ack_msg->sequence_number); 522 socket->read_sequence_number = ntohl (ack_msg->sequence_number);
516 /* Get the random sequence number */ 523 /* Get the random sequence number */
517 socket->write_sequence_number = 524 socket->write_sequence_number =
518 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 0xffffffff); 525 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
519 reply = 526 reply =
520 GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage)); 527 GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage));
521 reply->header.header.size = 528 reply->header.header.size =
@@ -524,18 +531,22 @@ client_handle_hello_ack (void *cls,
524 htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK); 531 htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK);
525 reply->sequence_number = htonl (socket->write_sequence_number); 532 reply->sequence_number = htonl (socket->write_sequence_number);
526 queue_message (socket, 533 queue_message (socket,
527 (struct GNUNET_STREAM_MessageHeader *) reply, 534 &reply->header,
528 &set_state_established, 535 &set_state_established,
529 NULL); 536 NULL);
530 } 537 return GNUNET_OK;
531 else 538 case STATE_ESTABLISHED:
532 { 539 case STATE_RECEIVE_CLOSE_WAIT:
533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 540 // call statistics (# ACKs ignored++)
534 "Server sent HELLO_ACK when in state %d\n", socket->state); 541 return GNUNET_OK;
535 /* FIXME: Send RESET? */ 542 case STATE_INIT:
536 } 543 default:
544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
545 "Server sent HELLO_ACK when in state %d\n", socket->state);
546 socket->state = STATE_CLOSED; // introduce STATE_ERROR?
547 return GNUNET_SYSERR;
548 }
537 549
538 return GNUNET_OK;
539} 550}
540 551
541 552
@@ -778,7 +789,7 @@ server_handle_hello (void *cls,
778 { 789 {
779 /* Get the random sequence number */ 790 /* Get the random sequence number */
780 socket->write_sequence_number = 791 socket->write_sequence_number =
781 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 0xffffffff); 792 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
782 reply = 793 reply =
783 GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage)); 794 GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage));
784 reply->header.header.size = 795 reply->header.header.size =
@@ -787,7 +798,7 @@ server_handle_hello (void *cls,
787 htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK); 798 htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK);
788 reply->sequence_number = htonl (socket->write_sequence_number); 799 reply->sequence_number = htonl (socket->write_sequence_number);
789 queue_message (socket, 800 queue_message (socket,
790 (struct GNUNET_STREAM_MessageHeader *)reply, 801 &reply->header,
791 &set_state_hello_wait, 802 &set_state_hello_wait,
792 NULL); 803 NULL);
793 } 804 }
@@ -1179,8 +1190,8 @@ mesh_peer_connect_callback (void *cls,
1179 sizeof (struct GNUNET_PeerIdentity))) 1190 sizeof (struct GNUNET_PeerIdentity)))
1180 { 1191 {
1181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1182 "A peer (%s) which is not our target has\ 1193 "A peer (%s) which is not our target has connected to our tunnel",
1183 connected to our tunnel", GNUNET_i2s (peer)); 1194 GNUNET_i2s (peer));
1184 return; 1195 return;
1185 } 1196 }
1186 1197
@@ -1319,9 +1330,10 @@ GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket)
1319 } 1330 }
1320 1331
1321 /* Clear existing message queue */ 1332 /* Clear existing message queue */
1322 while (NULL != socket->queue) { 1333 while (NULL != (head = socket->queue_head)) {
1323 head = socket->queue; 1334 GNUNET_CONTAINER_DLL_remove (socket->queue_head,
1324 socket->queue = head->next; 1335 socket->queue_tail,
1336 head);
1325 GNUNET_free (head->message); 1337 GNUNET_free (head->message);
1326 GNUNET_free (head); 1338 GNUNET_free (head);
1327 } 1339 }
diff --git a/src/stream/stream_protocol.h b/src/stream/stream_protocol.h
index cc08dbe8e..426cd345b 100644
--- a/src/stream/stream_protocol.h
+++ b/src/stream/stream_protocol.h
@@ -52,7 +52,7 @@ struct GNUNET_STREAM_MessageHeader
52 struct GNUNET_MessageHeader header; 52 struct GNUNET_MessageHeader header;
53 53
54 /** 54 /**
55 * A number which identifies a session between the two peers. 55 * A number which identifies a session between the two peers. FIXME: not needed
56 */ 56 */
57 uint32_t session_id GNUNET_PACKED; 57 uint32_t session_id GNUNET_PACKED;
58 58