[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19696 - gnunet/src/stream
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19696 - gnunet/src/stream |
Date: |
Sun, 5 Feb 2012 12:55:46 +0100 |
Author: harsha
Date: 2012-02-05 12:55:46 +0100 (Sun, 05 Feb 2012)
New Revision: 19696
Modified:
gnunet/src/stream/stream_api.c
Log:
-protocol upto ESTABLISHED state
Modified: gnunet/src/stream/stream_api.c
===================================================================
--- gnunet/src/stream/stream_api.c 2012-02-05 10:44:42 UTC (rev 19695)
+++ gnunet/src/stream/stream_api.c 2012-02-05 11:55:46 UTC (rev 19696)
@@ -308,19 +308,18 @@
SendFinishCallback finish_cb,
void *finish_cb_cls)
{
- struct MessageQueue *msg_info;
+ struct MessageQueue *queue_entity;
- msg_info = GNUNET_malloc (sizeof (struct MessageQueue));
- msg_info->message = message;
- msg_info->finish_cb = finish_cb;
- msg_info->finish_cb_cls = finish_cb_cls;
- msg_info->next = NULL;
+ queue_entity = GNUNET_malloc (sizeof (struct MessageQueue));
+ queue_entity->message = message;
+ queue_entity->finish_cb = finish_cb;
+ queue_entity->finish_cb_cls = finish_cb_cls;
+ queue_entity->next = NULL;
-
if (NULL == socket->queue)
{
- socket->queue = msg_info;
- socket->queue_tail = msg_info;
+ socket->queue = queue_entity;
+ socket->queue_tail = queue_entity;
socket->retries = 0;
socket->transmit_handle =
GNUNET_MESH_notify_transmit_ready (socket->tunnel,
@@ -334,8 +333,8 @@
}
else /* There is a pending message in queue */
{
- socket->queue_tail->next = msg_info; /* Add to tail */
- socket->queue_tail = msg_info;
+ socket->queue_tail->next = queue_entity; /* Add to tail */
+ socket->queue_tail = queue_entity;
}
}
@@ -448,6 +447,12 @@
&set_state_established,
NULL);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Server sent HELLO_ACK when in state %d\n", socket->state);
+ /* FIXME: Send RESET? */
+ }
return GNUNET_OK;
}
@@ -685,7 +690,29 @@
const struct GNUNET_ATS_Information*atsi)
{
struct GNUNET_STREAM_Socket *socket = *tunnel_ctx;
+ struct GNUNET_STREAM_MessageHeader *reply;
+ GNUNET_assert (socket->tunnel == tunnel);
+ if (STATE_INIT == socket->state)
+ {
+ reply =
+ GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader));
+ reply->header.size =
+ htons (sizeof (struct GNUNET_STREAM_MessageHeader));
+ reply->header.type =
+ htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK);
+ queue_message (socket,
+ reply,
+ &set_state_hello_wait,
+ NULL);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client sent HELLO when in state %d\n", socket->state);
+ /* FIXME: Send RESET? */
+
+ }
return GNUNET_OK;
}
@@ -711,7 +738,20 @@
const struct GNUNET_ATS_Information*atsi)
{
struct GNUNET_STREAM_Socket *socket = *tunnel_ctx;
+ struct GNUNET_STREAM_MessageHeader *reply;
+ GNUNET_assert (socket->tunnel == tunnel);
+ if (STATE_HELLO_WAIT == socket->state)
+ {
+ socket->state = STATE_ESTABLISHED;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client sent HELLO_ACK when in state %d\n", socket->state);
+ /* FIXME: Send RESET? */
+
+ }
return GNUNET_OK;
}
@@ -1073,12 +1113,12 @@
NULL);
/* Call open callback */
- if (NULL == socket->open_cls)
+ if (NULL == socket->open_cb)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"STREAM_open callback is NULL\n");
}
- if (NULL != socket->open_cb)
+ else
{
socket->open_cb (socket->open_cls, socket);
}
@@ -1150,8 +1190,7 @@
case GNUNET_STREAM_OPTION_END:
break;
}
-
- } while (0 != option);
+ } while (GNUNET_STREAM_OPTION_END != option);
va_end (vargs); /* End of variable args parsing */
socket->mesh = GNUNET_MESH_connect (cfg, /* the configuration handle */
@@ -1168,7 +1207,7 @@
NULL, /* Tunnel context */
&mesh_peer_connect_callback,
&mesh_peer_disconnect_callback,
- (void *) socket);
+ socket);
// FIXME: if (NULL == socket->tunnel) ...
return socket;
@@ -1183,17 +1222,28 @@
void
GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket)
{
+ struct MessageQueue *head;
+
/* Clear Transmit handles */
if (NULL != socket->transmit_handle)
{
GNUNET_MESH_notify_transmit_ready_cancel (socket->transmit_handle);
}
- /* FIXME: Clear message queue */
+
+ /* Clear existing message queue */
+ while (NULL != socket->queue) {
+ head = socket->queue;
+ socket->queue = head->next;
+ GNUNET_free (head->message);
+ GNUNET_free (head);
+ }
+
/* Close associated tunnel */
if (NULL != socket->tunnel)
{
GNUNET_MESH_tunnel_destroy (socket->tunnel);
}
+
/* Close mesh connection */
if (NULL != socket->mesh)
{
@@ -1258,7 +1308,6 @@
const struct GNUNET_MESH_Tunnel *tunnel,
void *tunnel_ctx)
{
- struct GNUNET_STREAM_ListenSocket *lsocket = cls;
struct GNUNET_STREAM_Socket *socket = tunnel_ctx;
struct MessageQueue *head;
@@ -1273,14 +1322,7 @@
GNUNET_MESH_notify_transmit_ready_cancel (socket->transmit_handle);
socket->transmit_handle = NULL;
}
-
- /* Clear existing message queue */
- while (NULL != socket->queue) {
- head = socket->queue;
- socket->queue = head->next;
- GNUNET_free (head->message);
- GNUNET_free (head);
- }
+ socket->tunnel = NULL;
}
@@ -1329,8 +1371,6 @@
void
GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket)
{
- /* Do house keeping */
-
/* Close MESH connection */
GNUNET_MESH_disconnect (lsocket->mesh);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19696 - gnunet/src/stream,
gnunet <=