aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2011-02-16 15:46:32 +0000
committerNathan S. Evans <evans@in.tum.de>2011-02-16 15:46:32 +0000
commite054285d845aad88df678b60ee532d71d5115f4b (patch)
tree8e6959f564947afd8a0132641aa8964db2c12f89 /src/core/core_api.c
parentfe4cd8976e16e6c44fd4f8c499ff6b253106c68b (diff)
downloadgnunet-e054285d845aad88df678b60ee532d71d5115f4b.tar.gz
gnunet-e054285d845aad88df678b60ee532d71d5115f4b.zip
handle out of sync connect callback scenario
Diffstat (limited to 'src/core/core_api.c')
-rw-r--r--src/core/core_api.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index f4a197909..57bf64ad7 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -921,7 +921,7 @@ main_notify_handler (void *cls,
921 &cnm->peer, 921 &cnm->peer,
922 sizeof (struct GNUNET_PeerIdentity))) 922 sizeof (struct GNUNET_PeerIdentity)))
923 { 923 {
924 /* disconnect from self!? */ 924 /* connect to self!? */
925 GNUNET_break (0); 925 GNUNET_break (0);
926 return; 926 return;
927 } 927 }
@@ -1716,7 +1716,9 @@ peer_request_connect_cont (void *cls,
1716 * @param peer who should we connect to 1716 * @param peer who should we connect to
1717 * @param cont function to call once the request has been completed (or timed out) 1717 * @param cont function to call once the request has been completed (or timed out)
1718 * @param cont_cls closure for cont 1718 * @param cont_cls closure for cont
1719 * @return NULL on error (cont will not be called), otherwise handle for cancellation 1719 *
1720 * @return NULL on error or already connected,
1721 * otherwise handle for cancellation
1720 */ 1722 */
1721struct GNUNET_CORE_PeerRequestHandle * 1723struct GNUNET_CORE_PeerRequestHandle *
1722GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, 1724GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
@@ -1728,10 +1730,25 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
1728 struct GNUNET_CORE_PeerRequestHandle *ret; 1730 struct GNUNET_CORE_PeerRequestHandle *ret;
1729 struct ControlMessage *cm; 1731 struct ControlMessage *cm;
1730 struct ConnectMessage *msg; 1732 struct ConnectMessage *msg;
1733 struct PeerRecord *pr;
1734 static struct GNUNET_TRANSPORT_ATS_Information distance[2];
1731 1735
1732 if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers, 1736 if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers,
1733 &peer->hashPubKey)) 1737 &peer->hashPubKey))
1734 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "core_api", "Received CONNECT requests for already connected peer!\n"); 1738 {
1739 pr = GNUNET_CONTAINER_multihashmap_get(h->peers, &peer->hashPubKey);
1740 GNUNET_assert(pr != NULL);
1741 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1742 distance[0].value = htonl (1);
1743 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1744 distance[1].value = htonl (0);
1745
1746 if (NULL != h->connects)
1747 h->connects (h->cls,
1748 &pr->peer,
1749 &distance[0]);
1750 return NULL;
1751 }
1735 1752
1736 cm = GNUNET_malloc (sizeof (struct ControlMessage) + 1753 cm = GNUNET_malloc (sizeof (struct ControlMessage) +
1737 sizeof (struct ConnectMessage)); 1754 sizeof (struct ConnectMessage));