aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-03-21 07:06:26 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-03-21 07:06:26 +0000
commit66f52c411df00d115efced5efb9ba78632fd45c2 (patch)
treefbc953ed46a9b03191eb360e33db75e97745eec1 /src
parent942ca274bd54d35eb4ffd76d30b53db8bbd8bf15 (diff)
downloadgnunet-66f52c411df00d115efced5efb9ba78632fd45c2.tar.gz
gnunet-66f52c411df00d115efced5efb9ba78632fd45c2.zip
fixed listen callback to happen after reaching ESTABLISHED state
Diffstat (limited to 'src')
-rw-r--r--src/stream/stream_api.c50
-rw-r--r--src/stream/test_stream_local.c11
2 files changed, 38 insertions, 23 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c
index 55b0ab958..1547f0228 100644
--- a/src/stream/stream_api.c
+++ b/src/stream/stream_api.c
@@ -231,6 +231,12 @@ struct GNUNET_STREAM_Socket
231 void *receive_buffer; 231 void *receive_buffer;
232 232
233 /** 233 /**
234 * The listen socket from which this socket is derived. Should be NULL if it
235 * is not a derived socket
236 */
237 struct GNUNET_STREAM_ListenSocket *lsocket;
238
239 /**
234 * Task identifier for the read io timeout task 240 * Task identifier for the read io timeout task
235 */ 241 */
236 GNUNET_SCHEDULER_TaskIdentifier read_io_timeout_task; 242 GNUNET_SCHEDULER_TaskIdentifier read_io_timeout_task;
@@ -266,11 +272,6 @@ struct GNUNET_STREAM_Socket
266 unsigned int retries; 272 unsigned int retries;
267 273
268 /** 274 /**
269 * Is this socket derived from listen socket?
270 */
271 unsigned int derived;
272
273 /**
274 * The peer identity of the peer at the other end of the stream 275 * The peer identity of the peer at the other end of the stream
275 */ 276 */
276 GNUNET_PEER_Id other_peer; 277 GNUNET_PEER_Id other_peer;
@@ -1118,13 +1119,33 @@ static void
1118set_state_established (void *cls, 1119set_state_established (void *cls,
1119 struct GNUNET_STREAM_Socket *socket) 1120 struct GNUNET_STREAM_Socket *socket)
1120{ 1121{
1122 struct GNUNET_PeerIdentity initiator_pid;
1123
1121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1122 "%x: Attaining ESTABLISHED state\n", 1125 "%x: Attaining ESTABLISHED state\n",
1123 socket->our_id); 1126 socket->our_id);
1124 socket->write_offset = 0; 1127 socket->write_offset = 0;
1125 socket->read_offset = 0; 1128 socket->read_offset = 0;
1126 socket->state = STATE_ESTABLISHED; 1129 socket->state = STATE_ESTABLISHED;
1127 if (socket->open_cb) 1130 /* FIXME: What if listen_cb is NULL */
1131 if (NULL != socket->lsocket)
1132 {
1133 GNUNET_PEER_resolve (socket->other_peer, &initiator_pid);
1134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1135 "%x: Calling listen callback\n",
1136 socket->our_id);
1137 if (GNUNET_SYSERR ==
1138 socket->lsocket->listen_cb (socket->lsocket->listen_cb_cls,
1139 socket,
1140 &initiator_pid))
1141 {
1142 socket->state = STATE_CLOSED;
1143 /* FIXME: We should close in a decent way */
1144 GNUNET_MESH_tunnel_destroy (socket->tunnel); /* Destroy the tunnel */
1145 GNUNET_free (socket);
1146 }
1147 }
1148 else if (socket->open_cb)
1128 socket->open_cb (socket->open_cls, socket); 1149 socket->open_cb (socket->open_cls, socket);
1129} 1150}
1130 1151
@@ -1869,6 +1890,8 @@ handle_ack (struct GNUNET_STREAM_Socket *socket,
1869 GNUNET_SCHEDULER_NO_TASK; 1890 GNUNET_SCHEDULER_NO_TASK;
1870 } 1891 }
1871 1892
1893 /* FIXME: Bits in the ack_bitmap are only to be set; Once set they cannot
1894 be unset */
1872 socket->write_handle->ack_bitmap = GNUNET_ntohll (ack->bitmap); 1895 socket->write_handle->ack_bitmap = GNUNET_ntohll (ack->bitmap);
1873 socket->receiver_window_available = 1896 socket->receiver_window_available =
1874 ntohl (ack->receive_window_remaining); 1897 ntohl (ack->receive_window_remaining);
@@ -2122,7 +2145,7 @@ new_tunnel_notify (void *cls,
2122 socket->tunnel = tunnel; 2145 socket->tunnel = tunnel;
2123 socket->session_id = 0; /* FIXME */ 2146 socket->session_id = 0; /* FIXME */
2124 socket->state = STATE_INIT; 2147 socket->state = STATE_INIT;
2125 socket->derived = GNUNET_YES; 2148 socket->lsocket = lsocket;
2126 socket->our_id = lsocket->our_id; 2149 socket->our_id = lsocket->our_id;
2127 2150
2128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2131,16 +2154,7 @@ new_tunnel_notify (void *cls,
2131 socket->other_peer); 2154 socket->other_peer);
2132 2155
2133 /* FIXME: Copy MESH handle from lsocket to socket */ 2156 /* FIXME: Copy MESH handle from lsocket to socket */
2134 /* FIXME: What if listen_cb is NULL */ 2157
2135 if (GNUNET_SYSERR == lsocket->listen_cb (lsocket->listen_cb_cls,
2136 socket,
2137 initiator))
2138 {
2139 socket->state = STATE_CLOSED;
2140 /* FIXME: Send CLOSE message and then free */
2141 GNUNET_free (socket);
2142 GNUNET_MESH_tunnel_destroy (tunnel); /* Destroy the tunnel */
2143 }
2144 return socket; 2158 return socket;
2145} 2159}
2146 2160
@@ -2328,7 +2342,7 @@ GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket)
2328 } 2342 }
2329 2343
2330 /* Close mesh connection */ 2344 /* Close mesh connection */
2331 if (NULL != socket->mesh && GNUNET_YES != socket->derived) 2345 if (NULL != socket->mesh && NULL == socket->lsocket)
2332 { 2346 {
2333 GNUNET_MESH_disconnect (socket->mesh); 2347 GNUNET_MESH_disconnect (socket->mesh);
2334 socket->mesh = NULL; 2348 socket->mesh = NULL;
diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c
index 125fc6df8..9a6c13da6 100644
--- a/src/stream/test_stream_local.c
+++ b/src/stream/test_stream_local.c
@@ -204,9 +204,6 @@ write_completion (void *cls,
204 GNUNET_assert (size <= strlen (data)); 204 GNUNET_assert (size <= strlen (data));
205 peer->bytes_wrote += size; 205 peer->bytes_wrote += size;
206 206
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "Writing completed\n");
209
210 if (peer->bytes_wrote < strlen(data)) /* Have more data to send */ 207 if (peer->bytes_wrote < strlen(data)) /* Have more data to send */
211 { 208 {
212 peer->io_write_handle = 209 peer->io_write_handle =
@@ -221,6 +218,9 @@ write_completion (void *cls,
221 } 218 }
222 else 219 else
223 { 220 {
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Writing completed\n");
223
224 if (&peer1 == peer) /* Peer1 has finished writing; should read now */ 224 if (&peer1 == peer) /* Peer1 has finished writing; should read now */
225 { 225 {
226 peer->io_read_handle = 226 peer->io_read_handle =
@@ -359,8 +359,8 @@ stream_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
359 */ 359 */
360static int 360static int
361stream_listen_cb (void *cls, 361stream_listen_cb (void *cls,
362 struct GNUNET_STREAM_Socket *socket, 362 struct GNUNET_STREAM_Socket *socket,
363 const struct GNUNET_PeerIdentity *initiator) 363 const struct GNUNET_PeerIdentity *initiator)
364{ 364{
365 GNUNET_assert (NULL != socket); 365 GNUNET_assert (NULL != socket);
366 GNUNET_assert (NULL != initiator); 366 GNUNET_assert (NULL != initiator);
@@ -372,6 +372,7 @@ stream_listen_cb (void *cls,
372 GNUNET_i2s(initiator)); 372 GNUNET_i2s(initiator));
373 373
374 peer2.socket = socket; 374 peer2.socket = socket;
375 /* FIXME: reading should be done right now instead of a scheduled call */
375 read_task = GNUNET_SCHEDULER_add_now (&stream_read, (void *) socket); 376 read_task = GNUNET_SCHEDULER_add_now (&stream_read, (void *) socket);
376 return GNUNET_OK; 377 return GNUNET_OK;
377} 378}