diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-12-18 20:33:26 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-12-18 20:33:26 +0000 |
commit | 46244f4cb8abfb65de29fb8de8aad2209d449ecb (patch) | |
tree | f720b52f63d0ae27e06333f0c35d5312a0f290ec | |
parent | 91bbd8cd39ca071c3957f9905b8dd185d48f6b7a (diff) | |
download | gnunet-46244f4cb8abfb65de29fb8de8aad2209d449ecb.tar.gz gnunet-46244f4cb8abfb65de29fb8de8aad2209d449ecb.zip |
- send notification immediately if a connection fails to be created
- allow to queue messages with no connection
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.c | 49 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_peer.c | 25 |
2 files changed, 58 insertions, 16 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index ef2df2ce3..c31ee2aab 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c | |||
@@ -791,6 +791,39 @@ send_broken (struct MeshConnection *c, | |||
791 | 791 | ||
792 | 792 | ||
793 | /** | 793 | /** |
794 | * Send a notification that a connection is broken, when a connection | ||
795 | * isn't even created. | ||
796 | * | ||
797 | * @param connection_id Connection ID. | ||
798 | * @param id1 Peer that has disconnected. | ||
799 | * @param id2 Peer that has disconnected. | ||
800 | * @param peer Peer to notify (neighbor who sent the connection). | ||
801 | */ | ||
802 | static void | ||
803 | send_broken2 (struct GNUNET_HashCode *connection_id, | ||
804 | const struct GNUNET_PeerIdentity *id1, | ||
805 | const struct GNUNET_PeerIdentity *id2, | ||
806 | GNUNET_PEER_Id peer_id) | ||
807 | { | ||
808 | struct GNUNET_MESH_ConnectionBroken *msg; | ||
809 | struct MeshPeer *neighbor; | ||
810 | |||
811 | msg = GNUNET_new (struct GNUNET_MESH_ConnectionBroken); | ||
812 | msg->header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken)); | ||
813 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN); | ||
814 | msg->cid = *connection_id; | ||
815 | msg->peer1 = *id1; | ||
816 | msg->peer2 = *id2; | ||
817 | neighbor = GMP_get_short (peer_id); | ||
818 | GMP_queue_add (neighbor, msg, | ||
819 | GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED, | ||
820 | sizeof (struct GNUNET_MESH_ConnectionBroken), | ||
821 | NULL, GNUNET_SYSERR, /* connection, fwd */ | ||
822 | NULL, NULL); /* continuation */ | ||
823 | } | ||
824 | |||
825 | |||
826 | /** | ||
794 | * Send keepalive packets for a connection. | 827 | * Send keepalive packets for a connection. |
795 | * | 828 | * |
796 | * @param c Connection to keep alive.. | 829 | * @param c Connection to keep alive.. |
@@ -1383,15 +1416,29 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1383 | size, &own_pos); | 1416 | size, &own_pos); |
1384 | if (NULL == path) | 1417 | if (NULL == path) |
1385 | return GNUNET_OK; | 1418 | return GNUNET_OK; |
1419 | if (0 == own_pos) | ||
1420 | { | ||
1421 | GNUNET_break_op (0); | ||
1422 | return GNUNET_OK; | ||
1423 | } | ||
1386 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); | 1424 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); |
1387 | GMP_add_path_to_all (path, GNUNET_NO); | ||
1388 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n"); | 1425 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n"); |
1389 | c = GMC_new (cid, NULL, path_duplicate (path), own_pos); | 1426 | c = GMC_new (cid, NULL, path_duplicate (path), own_pos); |
1390 | if (NULL == c) | 1427 | if (NULL == c) |
1391 | { | 1428 | { |
1429 | if (path->length - 1 == own_pos) | ||
1430 | { | ||
1431 | /* If we are destination, why did the creation fail? */ | ||
1432 | GNUNET_break (0); | ||
1433 | return GNUNET_OK; | ||
1434 | } | ||
1435 | send_broken2 (cid, &my_full_id, | ||
1436 | GNUNET_PEER_resolve2 (path->peers[own_pos + 1]), | ||
1437 | path->peers[own_pos - 1]); | ||
1392 | path_destroy (path); | 1438 | path_destroy (path); |
1393 | return GNUNET_OK; | 1439 | return GNUNET_OK; |
1394 | } | 1440 | } |
1441 | GMP_add_path_to_all (path, GNUNET_NO); | ||
1395 | connection_reset_timeout (c, GNUNET_YES); | 1442 | connection_reset_timeout (c, GNUNET_YES); |
1396 | } | 1443 | } |
1397 | else | 1444 | else |
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 4d183bbd6..8f13d0bb1 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c | |||
@@ -858,9 +858,7 @@ queue_send (void *cls, size_t size, void *buf) | |||
858 | case GNUNET_MESSAGE_TYPE_MESH_KX: | 858 | case GNUNET_MESSAGE_TYPE_MESH_KX: |
859 | case GNUNET_MESSAGE_TYPE_MESH_ACK: | 859 | case GNUNET_MESSAGE_TYPE_MESH_ACK: |
860 | case GNUNET_MESSAGE_TYPE_MESH_POLL: | 860 | case GNUNET_MESSAGE_TYPE_MESH_POLL: |
861 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 861 | LOG (GNUNET_ERROR_TYPE_DEBUG, "* raw: %s\n", GM_m2s (queue->type)); |
862 | "* raw: %s\n", | ||
863 | GM_m2s (queue->type)); | ||
864 | data_size = send_core_data_raw (queue->cls, size, buf); | 862 | data_size = send_core_data_raw (queue->cls, size, buf); |
865 | break; | 863 | break; |
866 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: | 864 | case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: |
@@ -911,14 +909,13 @@ queue_send (void *cls, size_t size, void *buf) | |||
911 | if (NULL == peer->core_transmit) | 909 | if (NULL == peer->core_transmit) |
912 | { | 910 | { |
913 | peer->core_transmit = | 911 | peer->core_transmit = |
914 | GNUNET_CORE_notify_transmit_ready(core_handle, | 912 | GNUNET_CORE_notify_transmit_ready (core_handle, |
915 | 0, | 913 | 0, 0, |
916 | 0, | 914 | GNUNET_TIME_UNIT_FOREVER_REL, |
917 | GNUNET_TIME_UNIT_FOREVER_REL, | 915 | dst_id, |
918 | dst_id, | 916 | queue->size, |
919 | queue->size, | 917 | &queue_send, |
920 | &queue_send, | 918 | peer); |
921 | peer); | ||
922 | queue->start_waiting = GNUNET_TIME_absolute_get (); | 919 | queue->start_waiting = GNUNET_TIME_absolute_get (); |
923 | } | 920 | } |
924 | else | 921 | else |
@@ -956,7 +953,6 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls) | |||
956 | struct MeshPeer *peer; | 953 | struct MeshPeer *peer; |
957 | 954 | ||
958 | peer = queue->peer; | 955 | peer = queue->peer; |
959 | GNUNET_assert (NULL != queue->c); | ||
960 | 956 | ||
961 | if (GNUNET_YES == clear_cls) | 957 | if (GNUNET_YES == clear_cls) |
962 | { | 958 | { |
@@ -1013,7 +1009,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls) | |||
1013 | * build the message to be sent if not already prebuilt. | 1009 | * build the message to be sent if not already prebuilt. |
1014 | * @param type Type of the message, 0 for a raw message. | 1010 | * @param type Type of the message, 0 for a raw message. |
1015 | * @param size Size of the message. | 1011 | * @param size Size of the message. |
1016 | * @param c Connection this message belongs to (cannot be NULL). | 1012 | * @param c Connection this message belongs to (can be NULL). |
1017 | * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) | 1013 | * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) |
1018 | * @param cont Continuation to be called once CORE has taken the message. | 1014 | * @param cont Continuation to be called once CORE has taken the message. |
1019 | * @param cont_cls Closure for @c cont. | 1015 | * @param cont_cls Closure for @c cont. |
@@ -1034,7 +1030,6 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size, | |||
1034 | "queue add %s %s towards %s (size %u) on c %p (%s)\n", | 1030 | "queue add %s %s towards %s (size %u) on c %p (%s)\n", |
1035 | GM_f2s (fwd), GM_m2s (type), GMP_2s(peer), | 1031 | GM_f2s (fwd), GM_m2s (type), GMP_2s(peer), |
1036 | size, c, GMC_2s (c)); | 1032 | size, c, GMC_2s (c)); |
1037 | GNUNET_assert (NULL != c); | ||
1038 | 1033 | ||
1039 | if (NULL == peer->connections) | 1034 | if (NULL == peer->connections) |
1040 | { | 1035 | { |
@@ -1055,7 +1050,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size, | |||
1055 | 1050 | ||
1056 | LOG (GNUNET_ERROR_TYPE_DEBUG, "priority %d\n", priority); | 1051 | LOG (GNUNET_ERROR_TYPE_DEBUG, "priority %d\n", priority); |
1057 | 1052 | ||
1058 | call_core = GMC_is_sendable (c, fwd); | 1053 | call_core = NULL == c ? GNUNET_YES : GMC_is_sendable (c, fwd); |
1059 | queue = GNUNET_malloc (sizeof (struct MeshPeerQueue)); | 1054 | queue = GNUNET_malloc (sizeof (struct MeshPeerQueue)); |
1060 | queue->cls = cls; | 1055 | queue->cls = cls; |
1061 | queue->type = type; | 1056 | queue->type = type; |