gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r7980 - GNUnet/src/applications/dv/module


From: gnunet
Subject: [GNUnet-SVN] r7980 - GNUnet/src/applications/dv/module
Date: Tue, 2 Dec 2008 20:47:29 -0700 (MST)

Author: nevans
Date: 2008-12-02 20:47:29 -0700 (Tue, 02 Dec 2008)
New Revision: 7980

Modified:
   GNUnet/src/applications/dv/module/dv.c
Log:


Modified: GNUnet/src/applications/dv/module/dv.c
===================================================================
--- GNUnet/src/applications/dv/module/dv.c      2008-12-03 03:46:58 UTC (rev 
7979)
+++ GNUnet/src/applications/dv/module/dv.c      2008-12-03 03:47:29 UTC (rev 
7980)
@@ -40,82 +40,36 @@
  */
 
 unsigned long long fisheye_depth;
+unsigned long long max_table_size;
+unsigned short curr_table_size;
+unsigned short closing = 0;
 
-struct GNUNET_dv_connected_neighbor
+struct GNUNET_dv_neighbor
 {
   /**
    * Generic list structure for neighbor lists
    */
-  struct GNUNET_dv_connected_neighbor *next;
+  struct GNUNET_dv_neighbor *next;
 
   /**
-   * Neighbor list of neighbor
-   */
-  struct GNUNET_dv_extended_neighbor *neighbors;
-
-  /**
    * Identity of neighbor
    */
   GNUNET_PeerIdentity *neighbor;
 
   /**
-   * Distance (hops) to neighbor, should never be in list if larger than
-   * fisheye_distance.
-   */
-  unsigned int distance;
-
-  /**
-   * Sequence number of value, used to decide if data is new (could compare
-   * values either/as well)
-   */
-  unsigned int sequence_number;
-
-  /**
-   * Cost to neighbor, used for actual distance vector computations
-   */
-  unsigned int cost;
-};
-
-struct GNUNET_dv_extended_neighbor
-{
-  /**
-   * Generic list structure for neighbor lists
-   */
-  struct GNUNET_dv_extended_neighbor *next;
-
-  /**
-   * Identity of neighbor
-   */
-  GNUNET_PeerIdentity *neighbor;
-
-  /**
    * Identity of referrer (where we got the information)
    */
   GNUNET_PeerIdentity *referrer;
 
   /**
-   * Distance (hops) to neighbor, should never be in list if larger than
-   * fisheye_distance.
-   */
-  unsigned int distance;
-
-  /**
-   * Sequence number of value, used to decide if data is new (could compare
-   * values either/as well)
-   */
-  unsigned int sequence_number;
-
-  /**
    * Cost to neighbor, used for actual distance vector computations
    */
   unsigned int cost;
 };
 
 
-struct GNUNET_dv_connected_neighbor *connected_neighbors;
+struct GNUNET_dv_neighbor *neighbors;
 
-struct GNUNET_dv_extended_neighbor *extended_neighbors;
-
 static GNUNET_CoreAPIForPlugins *coreAPI;
 
 static struct GNUNET_Mutex *dvMutex;
@@ -133,12 +87,17 @@
     return GNUNET_SYSERR;     /* invalid message */
   }
   nmsg = (const p2p_dv_MESSAGE_NeighborInfo *) message;
-  if ((nmsg->distance + 1 <= fisheye_depth) && 
(findConnectedNeighbor(&nmsg->neighbor) == NULL))
-    ret = addUpdateExtendedNeighbor(sender,&nmsg->neighbor, nmsg->cost, 
nmsg->distance, nmsg->sequence_number);
+  /*
+   * Need to fix nmsg->cost comparison to make sense!
+   */
+  /*if ((nmsg->cost + 1 <= fisheye_depth) && 
(findNeighbor(&nmsg->neighbor,sender) == NULL))*/
+
+  ret = addUpdateNeighbor(&nmsg->neighbor,sender, nmsg->cost);
+
   if (GNUNET_OK != ret)
     GNUNET_GE_LOG (coreAPI->ectx,
                      GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
-                     _("Problem adding neighbor in `%s'\n"),
+                     _("Problem adding/updating neighbor in `%s'\n"),
                      "dv");
 
   return ret;
@@ -147,10 +106,10 @@
 static void
 peer_disconnect_handler (const GNUNET_PeerIdentity * peer, void *unused)
 {
-  struct GNUNET_dv_connected_neighbor *pos = connected_neighbors;
-  struct GNUNET_dv_connected_neighbor *prev = NULL;
+  struct GNUNET_dv_neighbor *pos = neighbors;
+  struct GNUNET_dv_neighbor *prev = NULL;
   int not_found = 1;
-
+  GNUNET_mutex_lock(dvMutex);
   while ((pos->next != NULL) && (not_found))
   {
     prev = pos;
@@ -160,122 +119,104 @@
   }
   if ((prev == NULL) && (memcmp(&peer, &pos->next->neighbor, 
sizeof(GNUNET_PeerIdentity)) == 0))
   {
-    GNUNET_free(connected_neighbors->neighbor);
-    if (connected_neighbors->neighbors != NULL)
-    {
-      //Free all neighbors list, not sure what that requires yet!
-    }
-    GNUNET_free(connected_neighbors);
-    connected_neighbors = NULL;
+    if (neighbors->referrer != NULL)
+      GNUNET_free(neighbors->referrer);
+    GNUNET_free(neighbors);
+    neighbors = NULL;
+    curr_table_size = 0;
   }
   else if (prev != NULL)
   {
     prev->next = pos->next;
     GNUNET_free(pos->neighbor);
-    if (pos->neighbors != NULL)
-    {
-      //Free all neighbors list, not sure what that requires yet!
-    }
+    if (pos->referrer != NULL)
+      GNUNET_free(pos->referrer);
     GNUNET_free(pos);
   }
-
+  GNUNET_mutex_unlock(dvMutex);
   return;
 }
 
-struct GNUNET_dv_connected_neighbor
-*findConnectedNeighbor(const GNUNET_PeerIdentity *neighbor)
+struct GNUNET_dv_neighbor
+*findNeighbor(const GNUNET_PeerIdentity *neighbor, const GNUNET_PeerIdentity 
*referrer)
 {
-  struct GNUNET_dv_connected_neighbor *pos = connected_neighbors;
+  struct GNUNET_dv_neighbor *pos = neighbors;
 
   while (pos != NULL)
   {
     if (memcmp(&neighbor, &pos->neighbor, sizeof(GNUNET_PeerIdentity)) == 0)
-      return pos;
+    {
+      if ((referrer == NULL) && (&pos->referrer == NULL))
+        return pos;
+      else if ((referrer != NULL) && (&pos->referrer != NULL) && 
(memcmp(&referrer, &pos->referrer, sizeof(GNUNET_PeerIdentity)) == 0))
+        return pos;
+    }
     pos = pos->next;
   }
   return pos;
 }
 
 static int
-addUpdateConnectedNeighbor(const GNUNET_PeerIdentity *neighbor, unsigned int 
cost, unsigned int distance, unsigned int sequence_number)
+addUpdateNeighbor(const GNUNET_PeerIdentity *neighbor,const 
GNUNET_PeerIdentity *referrer, unsigned int cost)
 {
   int ret = GNUNET_OK;
-  struct GNUNET_dv_connected_neighbor *dv_neighbor = 
findConnectedNeighbor(neighbor);
 
+  GNUNET_mutex_lock(dvMutex);
+  struct GNUNET_dv_neighbor *dv_neighbor = findNeighbor(neighbor,referrer);
+
   if (dv_neighbor != NULL)
   {
-    if ((dv_neighbor->sequence_number < sequence_number) || (sequence_number 
== 0))
+    if (dv_neighbor->cost != cost)
     {
-      GNUNET_mutex_lock(dvMutex);
       dv_neighbor->cost = cost;
-      dv_neighbor->distance = distance;
-      dv_neighbor->sequence_number = sequence_number;
-      GNUNET_mutex_unlock(dvMutex);
     }
   }
   else
   {
-    dv_neighbor = GNUNET_malloc(sizeof(struct GNUNET_dv_connected_neighbor));
-
+    dv_neighbor = GNUNET_malloc(sizeof(struct GNUNET_dv_neighbor));
     dv_neighbor->cost = cost;
-    dv_neighbor->distance = distance;
-    dv_neighbor->sequence_number = sequence_number;
     dv_neighbor->neighbor = malloc(sizeof(GNUNET_PeerIdentity));
     memcpy(&dv_neighbor->neighbor, &neighbor, sizeof(GNUNET_PeerIdentity));
 
-    GNUNET_mutex_lock(dvMutex);
-    dv_neighbor->next = connected_neighbors;
-    connected_neighbors = dv_neighbor;
-    GNUNET_mutex_unlock(dvMutex);
-  }
-
-  return ret;
-}
-
-static int
-addUpdateExtendedNeighbor(const GNUNET_PeerIdentity *neighbor, const 
GNUNET_PeerIdentity *referent, unsigned int cost, unsigned int distance, 
unsigned int sequence_number)
-{
-  int ret = GNUNET_OK;
-  struct GNUNET_dv_extended_neighbor *dv_neighbor = 
findExtendedNeighbor(neighbor);
-
-  if (dv_neighbor != NULL)
-  {
-    if ((dv_neighbor->sequence_number < sequence_number) || (sequence_number 
== 0))
+    if (referrer != NULL)
     {
-      GNUNET_mutex_lock(dvMutex);
-      dv_neighbor->cost = cost;
-      dv_neighbor->distance = distance;
-      dv_neighbor->sequence_number = sequence_number;
-      GNUNET_mutex_unlock(dvMutex);
+      dv_neighbor->referrer = malloc(sizeof(GNUNET_PeerIdentity));
+      memcpy(&dv_neighbor->referrer, &referrer, sizeof(GNUNET_PeerIdentity));
     }
-  }
-  else
-  {
-    dv_neighbor = GNUNET_malloc(sizeof(struct GNUNET_dv_extended_neighbor));
+    else
+    {
+      dv_neighbor->referrer = NULL;
+    }
 
-    dv_neighbor->cost = cost;
-    dv_neighbor->distance = distance;
-    dv_neighbor->sequence_number = sequence_number;
-    dv_neighbor->neighbor = malloc(sizeof(GNUNET_PeerIdentity));
-    memcpy(&dv_neighbor->neighbor, &neighbor, sizeof(GNUNET_PeerIdentity));
-
-    GNUNET_mutex_lock(dvMutex);
-    dv_neighbor->next = connected_neighbors;
-    connected_neighbors = dv_neighbor;
-    GNUNET_mutex_unlock(dvMutex);
+    dv_neighbor->next = neighbors;
+    neighbors = dv_neighbor;
+    curr_table_size++;
   }
-
+  GNUNET_mutex_unlock(dvMutex);
   return ret;
 }
 
 
 static void
-initialAddConnectedNeighbor(const GNUNET_PeerIdentity *neighbor, void *cls)
+initialAddNeighbor(const GNUNET_PeerIdentity *neighbor, void *cls)
 {
-  addUpdateConnectedNeighbor(neighbor, GNUNET_DV_LEAST_COST, 
GNUNET_DV_MAX_DISTANCE, GNUNET_DV_INITIAL_SEQUENCE_NUMBER);
+  addUpdateNeighbor(neighbor, NULL, GNUNET_DV_LEAST_COST);
   return;
 }
 
+static void *
+connection_poll_dv_calc_thread (void *rcls)
+{
+  static GNUNET_CoreAPIForPlugins *capi = rcls;
+
+  while (!closing)
+  {
+    capi->p2p_connections_iterate(&initialAddNeighbor,(void *)NULL);
+    GNUNET_thread_sleep(30 * GNUNET_CRON_SECONDS);
+  }
+
+}
+
 int
 initialize_module_dv (GNUNET_CoreAPIForPlugins * capi)
 {
@@ -297,15 +238,24 @@
                                  &p2pHandleDVNeighborMessage))
     ok = GNUNET_SYSERR;
 
-  if (GNUNET_SYSERR == 
capi->p2p_connections_iterate(&initialAddConnectedNeighbor,
+  GNUNET_thread_create (&connection_poll_thread, &coreAPI, 1024 * 4);
+
+  /*
+   if (GNUNET_SYSERR == capi->p2p_connections_iterate(&initialAddNeighbor,
       (void *)NULL))
     ok = GNUNET_SYSERR;
+  */
 
   GNUNET_GC_get_configuration_value_number (coreAPI->cfg,
                                               "DV",
                                               "FISHEYEDEPTH",
                                               0, -1, 3, &fisheye_depth);
 
+  GNUNET_GC_get_configuration_value_number (coreAPI->cfg,
+                                                "DV",
+                                                "TABLESIZE",
+                                                0, -1, 100, &max_table_size);
+
   GNUNET_GE_ASSERT (capi->ectx,
                     0 == GNUNET_GC_set_configuration_value_string (capi->cfg,
                                                                    capi->ectx,
@@ -320,7 +270,7 @@
 void
 done_module_dv ()
 {
-
+  closing = 1;
   coreAPI->p2p_ciphertext_handler_unregister 
(GNUNET_P2P_PROTO_DV_NEIGHBOR_MESSAGE,
                                   &p2pHandleDVNeighborMessage);
 





reply via email to

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