gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12435 - gnunet/src/dht


From: gnunet
Subject: [GNUnet-SVN] r12435 - gnunet/src/dht
Date: Mon, 2 Aug 2010 16:19:28 +0200

Author: nevans
Date: 2010-08-02 16:19:28 +0200 (Mon, 02 Aug 2010)
New Revision: 12435

Modified:
   gnunet/src/dht/dht.h
   gnunet/src/dht/gnunet-service-dht.c
Log:
don't try to connect to all peers, but only those advantageous for routing

Modified: gnunet/src/dht/dht.h
===================================================================
--- gnunet/src/dht/dht.h        2010-08-02 14:10:16 UTC (rev 12434)
+++ gnunet/src/dht/dht.h        2010-08-02 14:19:28 UTC (rev 12435)
@@ -214,7 +214,7 @@
  *        route message, what should it do?  It can either drop the message
  *        or try to forward it towards the original peer...  However, for
  *        that to work we would need to include the original peer identity
- *        in the GET request, which adds even more data to the message.
+ *        in the GET request, which adds more data to the message.
  */
 struct GNUNET_DHT_P2PRouteResultMessage
 {

Modified: gnunet/src/dht/gnunet-service-dht.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht.c 2010-08-02 14:10:16 UTC (rev 12434)
+++ gnunet/src/dht/gnunet-service-dht.c 2010-08-02 14:19:28 UTC (rev 12435)
@@ -1112,7 +1112,33 @@
   add_pending_message (client, pending_message);
 }
 
+/**
+ * Consider whether or not we would like to have this peer added to
+ * our routing table.  Check whether bucket for this peer is full,
+ * if so return negative; if not return positive.  Since peers are
+ * only added on CORE level connect, this doesn't actually add the
+ * peer to the routing table.
+ *
+ * @param peer the peer we are considering adding
+ *
+ * @return GNUNET_YES if we want this peer, GNUNET_NO if not (bucket
+ *         already full)
+ *
+ * FIXME: Think about making a context for this call so that we can
+ *        ping the oldest peer in the current bucket and consider
+ *        removing it in lieu of the new peer.
+ */
+static int consider_peer (struct GNUNET_PeerIdentity *peer)
+{
+  int bucket;
 
+  bucket = find_current_bucket(&peer->hashPubKey);
+  if ((k_buckets[bucket].peers_size < bucket_size) || ((bucket == 
lowest_bucket) && (lowest_bucket > 0)))
+    return GNUNET_YES;
+
+  return GNUNET_NO;
+}
+
 /**
  * Main function that handles whether or not to route a result
  * message to other peers, or to send to our local client.
@@ -1125,6 +1151,7 @@
                                 struct GNUNET_MessageHeader *msg,
                                 struct DHT_MessageContext *message_context)
 {
+  struct GNUNET_PeerIdentity new_peer;
   struct DHTQueryRecord *record;
   struct DHTRouteSource *pos;
   struct PeerInfo *peer_info;
@@ -1145,15 +1172,19 @@
         GNUNET_break_op(0);
 
       hello_msg = &msg[1];
-      if (ntohs(hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO)
+      if ((ntohs(hello_msg->type) != GNUNET_MESSAGE_TYPE_HELLO) || 
(GNUNET_SYSERR == GNUNET_HELLO_get_id(hello_msg, &new_peer)))
       {
         GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Received non-HELLO 
message type in find peer result message!\n", my_short_id, "DHT");
         GNUNET_break_op(0);
       }
-      else
+      else /* We have a valid hello, and peer id stored in new_peer */
       {
-        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Received HELLO message 
for another peer, offering to transport!\n", my_short_id, "DHT");
-        GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg);
+        if (GNUNET_YES == consider_peer(&new_peer))
+        {
+          GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Received HELLO message 
for another peer, offering to transport!\n", my_short_id, "DHT");
+          GNUNET_TRANSPORT_offer_hello(transport_handle, hello_msg);
+          GNUNET_CORE_peer_request_connect(sched, cfg, 
GNUNET_TIME_UNIT_FOREVER_REL, &new_peer, NULL, NULL); /* FIXME: Do we need 
this??? */
+        }
       }
 
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]