aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/stream/stream_api.c96
1 files changed, 68 insertions, 28 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c
index d1b4dc299..bd89320ec 100644
--- a/src/stream/stream_api.c
+++ b/src/stream/stream_api.c
@@ -308,19 +308,18 @@ queue_message (struct GNUNET_STREAM_Socket *socket,
308 SendFinishCallback finish_cb, 308 SendFinishCallback finish_cb,
309 void *finish_cb_cls) 309 void *finish_cb_cls)
310{ 310{
311 struct MessageQueue *msg_info; 311 struct MessageQueue *queue_entity;
312
313 msg_info = GNUNET_malloc (sizeof (struct MessageQueue));
314 msg_info->message = message;
315 msg_info->finish_cb = finish_cb;
316 msg_info->finish_cb_cls = finish_cb_cls;
317 msg_info->next = NULL;
318 312
313 queue_entity = GNUNET_malloc (sizeof (struct MessageQueue));
314 queue_entity->message = message;
315 queue_entity->finish_cb = finish_cb;
316 queue_entity->finish_cb_cls = finish_cb_cls;
317 queue_entity->next = NULL;
319 318
320 if (NULL == socket->queue) 319 if (NULL == socket->queue)
321 { 320 {
322 socket->queue = msg_info; 321 socket->queue = queue_entity;
323 socket->queue_tail = msg_info; 322 socket->queue_tail = queue_entity;
324 socket->retries = 0; 323 socket->retries = 0;
325 socket->transmit_handle = 324 socket->transmit_handle =
326 GNUNET_MESH_notify_transmit_ready (socket->tunnel, 325 GNUNET_MESH_notify_transmit_ready (socket->tunnel,
@@ -334,8 +333,8 @@ queue_message (struct GNUNET_STREAM_Socket *socket,
334 } 333 }
335 else /* There is a pending message in queue */ 334 else /* There is a pending message in queue */
336 { 335 {
337 socket->queue_tail->next = msg_info; /* Add to tail */ 336 socket->queue_tail->next = queue_entity; /* Add to tail */
338 socket->queue_tail = msg_info; 337 socket->queue_tail = queue_entity;
339 } 338 }
340} 339}
341 340
@@ -448,6 +447,12 @@ client_handle_hello_ack (void *cls,
448 &set_state_established, 447 &set_state_established,
449 NULL); 448 NULL);
450 } 449 }
450 else
451 {
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "Server sent HELLO_ACK when in state %d\n", socket->state);
454 /* FIXME: Send RESET? */
455 }
451 456
452 return GNUNET_OK; 457 return GNUNET_OK;
453} 458}
@@ -685,7 +690,29 @@ server_handle_hello (void *cls,
685 const struct GNUNET_ATS_Information*atsi) 690 const struct GNUNET_ATS_Information*atsi)
686{ 691{
687 struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; 692 struct GNUNET_STREAM_Socket *socket = *tunnel_ctx;
693 struct GNUNET_STREAM_MessageHeader *reply;
688 694
695 GNUNET_assert (socket->tunnel == tunnel);
696 if (STATE_INIT == socket->state)
697 {
698 reply =
699 GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader));
700 reply->header.size =
701 htons (sizeof (struct GNUNET_STREAM_MessageHeader));
702 reply->header.type =
703 htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK);
704 queue_message (socket,
705 reply,
706 &set_state_hello_wait,
707 NULL);
708 }
709 else
710 {
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
712 "Client sent HELLO when in state %d\n", socket->state);
713 /* FIXME: Send RESET? */
714
715 }
689 return GNUNET_OK; 716 return GNUNET_OK;
690} 717}
691 718
@@ -711,7 +738,20 @@ server_handle_hello_ack (void *cls,
711 const struct GNUNET_ATS_Information*atsi) 738 const struct GNUNET_ATS_Information*atsi)
712{ 739{
713 struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; 740 struct GNUNET_STREAM_Socket *socket = *tunnel_ctx;
741 struct GNUNET_STREAM_MessageHeader *reply;
714 742
743 GNUNET_assert (socket->tunnel == tunnel);
744 if (STATE_HELLO_WAIT == socket->state)
745 {
746 socket->state = STATE_ESTABLISHED;
747 }
748 else
749 {
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
751 "Client sent HELLO_ACK when in state %d\n", socket->state);
752 /* FIXME: Send RESET? */
753
754 }
715 return GNUNET_OK; 755 return GNUNET_OK;
716} 756}
717 757
@@ -1073,12 +1113,12 @@ mesh_peer_connect_callback (void *cls,
1073 NULL); 1113 NULL);
1074 1114
1075 /* Call open callback */ 1115 /* Call open callback */
1076 if (NULL == socket->open_cls) 1116 if (NULL == socket->open_cb)
1077 { 1117 {
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 "STREAM_open callback is NULL\n"); 1119 "STREAM_open callback is NULL\n");
1080 } 1120 }
1081 if (NULL != socket->open_cb) 1121 else
1082 { 1122 {
1083 socket->open_cb (socket->open_cls, socket); 1123 socket->open_cb (socket->open_cls, socket);
1084 } 1124 }
@@ -1150,8 +1190,7 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg,
1150 case GNUNET_STREAM_OPTION_END: 1190 case GNUNET_STREAM_OPTION_END:
1151 break; 1191 break;
1152 } 1192 }
1153 1193 } while (GNUNET_STREAM_OPTION_END != option);
1154 } while (0 != option);
1155 va_end (vargs); /* End of variable args parsing */ 1194 va_end (vargs); /* End of variable args parsing */
1156 1195
1157 socket->mesh = GNUNET_MESH_connect (cfg, /* the configuration handle */ 1196 socket->mesh = GNUNET_MESH_connect (cfg, /* the configuration handle */
@@ -1168,7 +1207,7 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg,
1168 NULL, /* Tunnel context */ 1207 NULL, /* Tunnel context */
1169 &mesh_peer_connect_callback, 1208 &mesh_peer_connect_callback,
1170 &mesh_peer_disconnect_callback, 1209 &mesh_peer_disconnect_callback,
1171 (void *) socket); 1210 socket);
1172 // FIXME: if (NULL == socket->tunnel) ... 1211 // FIXME: if (NULL == socket->tunnel) ...
1173 1212
1174 return socket; 1213 return socket;
@@ -1183,17 +1222,28 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg,
1183void 1222void
1184GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket) 1223GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket)
1185{ 1224{
1225 struct MessageQueue *head;
1226
1186 /* Clear Transmit handles */ 1227 /* Clear Transmit handles */
1187 if (NULL != socket->transmit_handle) 1228 if (NULL != socket->transmit_handle)
1188 { 1229 {
1189 GNUNET_MESH_notify_transmit_ready_cancel (socket->transmit_handle); 1230 GNUNET_MESH_notify_transmit_ready_cancel (socket->transmit_handle);
1190 } 1231 }
1191 /* FIXME: Clear message queue */ 1232
1233 /* Clear existing message queue */
1234 while (NULL != socket->queue) {
1235 head = socket->queue;
1236 socket->queue = head->next;
1237 GNUNET_free (head->message);
1238 GNUNET_free (head);
1239 }
1240
1192 /* Close associated tunnel */ 1241 /* Close associated tunnel */
1193 if (NULL != socket->tunnel) 1242 if (NULL != socket->tunnel)
1194 { 1243 {
1195 GNUNET_MESH_tunnel_destroy (socket->tunnel); 1244 GNUNET_MESH_tunnel_destroy (socket->tunnel);
1196 } 1245 }
1246
1197 /* Close mesh connection */ 1247 /* Close mesh connection */
1198 if (NULL != socket->mesh) 1248 if (NULL != socket->mesh)
1199 { 1249 {
@@ -1258,7 +1308,6 @@ tunnel_cleaner (void *cls,
1258 const struct GNUNET_MESH_Tunnel *tunnel, 1308 const struct GNUNET_MESH_Tunnel *tunnel,
1259 void *tunnel_ctx) 1309 void *tunnel_ctx)
1260{ 1310{
1261 struct GNUNET_STREAM_ListenSocket *lsocket = cls;
1262 struct GNUNET_STREAM_Socket *socket = tunnel_ctx; 1311 struct GNUNET_STREAM_Socket *socket = tunnel_ctx;
1263 struct MessageQueue *head; 1312 struct MessageQueue *head;
1264 1313
@@ -1273,14 +1322,7 @@ tunnel_cleaner (void *cls,
1273 GNUNET_MESH_notify_transmit_ready_cancel (socket->transmit_handle); 1322 GNUNET_MESH_notify_transmit_ready_cancel (socket->transmit_handle);
1274 socket->transmit_handle = NULL; 1323 socket->transmit_handle = NULL;
1275 } 1324 }
1276 1325 socket->tunnel = NULL;
1277 /* Clear existing message queue */
1278 while (NULL != socket->queue) {
1279 head = socket->queue;
1280 socket->queue = head->next;
1281 GNUNET_free (head->message);
1282 GNUNET_free (head);
1283 }
1284} 1326}
1285 1327
1286 1328
@@ -1329,8 +1371,6 @@ GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
1329void 1371void
1330GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket) 1372GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket)
1331{ 1373{
1332 /* Do house keeping */
1333
1334 /* Close MESH connection */ 1374 /* Close MESH connection */
1335 GNUNET_MESH_disconnect (lsocket->mesh); 1375 GNUNET_MESH_disconnect (lsocket->mesh);
1336 1376