SendFinishCallback finish_cb,
void *finish_cb_cls)
{
- struct MessageQueue *msg_info;
-
- 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;
+ struct MessageQueue *queue_entity;
+ 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,
}
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;
}
}
&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;
}
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;
}
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;
}
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);
}
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 */
NULL, /* Tunnel context */
&mesh_peer_connect_callback,
&mesh_peer_disconnect_callback,
- (void *) socket);
+ socket);
// FIXME: if (NULL == socket->tunnel) ...
return socket;
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)
{
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;
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;
}
void
GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket)
{
- /* Do house keeping */
-
/* Close MESH connection */
GNUNET_MESH_disconnect (lsocket->mesh);