*/
void *receive_buffer;
+ /**
+ * The listen socket from which this socket is derived. Should be NULL if it
+ * is not a derived socket
+ */
+ struct GNUNET_STREAM_ListenSocket *lsocket;
+
/**
* Task identifier for the read io timeout task
*/
*/
unsigned int retries;
- /**
- * Is this socket derived from listen socket?
- */
- unsigned int derived;
-
/**
* The peer identity of the peer at the other end of the stream
*/
set_state_established (void *cls,
struct GNUNET_STREAM_Socket *socket)
{
+ struct GNUNET_PeerIdentity initiator_pid;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%x: Attaining ESTABLISHED state\n",
socket->our_id);
socket->write_offset = 0;
socket->read_offset = 0;
socket->state = STATE_ESTABLISHED;
- if (socket->open_cb)
+ /* FIXME: What if listen_cb is NULL */
+ if (NULL != socket->lsocket)
+ {
+ GNUNET_PEER_resolve (socket->other_peer, &initiator_pid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%x: Calling listen callback\n",
+ socket->our_id);
+ if (GNUNET_SYSERR ==
+ socket->lsocket->listen_cb (socket->lsocket->listen_cb_cls,
+ socket,
+ &initiator_pid))
+ {
+ socket->state = STATE_CLOSED;
+ /* FIXME: We should close in a decent way */
+ GNUNET_MESH_tunnel_destroy (socket->tunnel); /* Destroy the tunnel */
+ GNUNET_free (socket);
+ }
+ }
+ else if (socket->open_cb)
socket->open_cb (socket->open_cls, socket);
}
GNUNET_SCHEDULER_NO_TASK;
}
+ /* FIXME: Bits in the ack_bitmap are only to be set; Once set they cannot
+ be unset */
socket->write_handle->ack_bitmap = GNUNET_ntohll (ack->bitmap);
socket->receiver_window_available =
ntohl (ack->receive_window_remaining);
socket->tunnel = tunnel;
socket->session_id = 0; /* FIXME */
socket->state = STATE_INIT;
- socket->derived = GNUNET_YES;
+ socket->lsocket = lsocket;
socket->our_id = lsocket->our_id;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
socket->other_peer);
/* FIXME: Copy MESH handle from lsocket to socket */
- /* FIXME: What if listen_cb is NULL */
- if (GNUNET_SYSERR == lsocket->listen_cb (lsocket->listen_cb_cls,
- socket,
- initiator))
- {
- socket->state = STATE_CLOSED;
- /* FIXME: Send CLOSE message and then free */
- GNUNET_free (socket);
- GNUNET_MESH_tunnel_destroy (tunnel); /* Destroy the tunnel */
- }
+
return socket;
}
}
/* Close mesh connection */
- if (NULL != socket->mesh && GNUNET_YES != socket->derived)
+ if (NULL != socket->mesh && NULL == socket->lsocket)
{
GNUNET_MESH_disconnect (socket->mesh);
socket->mesh = NULL;
GNUNET_assert (size <= strlen (data));
peer->bytes_wrote += size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Writing completed\n");
-
if (peer->bytes_wrote < strlen(data)) /* Have more data to send */
{
peer->io_write_handle =
}
else
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Writing completed\n");
+
if (&peer1 == peer) /* Peer1 has finished writing; should read now */
{
peer->io_read_handle =
*/
static int
stream_listen_cb (void *cls,
- struct GNUNET_STREAM_Socket *socket,
- const struct GNUNET_PeerIdentity *initiator)
+ struct GNUNET_STREAM_Socket *socket,
+ const struct GNUNET_PeerIdentity *initiator)
{
GNUNET_assert (NULL != socket);
GNUNET_assert (NULL != initiator);
GNUNET_i2s(initiator));
peer2.socket = socket;
+ /* FIXME: reading should be done right now instead of a scheduled call */
read_task = GNUNET_SCHEDULER_add_now (&stream_read, (void *) socket);
return GNUNET_OK;
}