⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remotetopologies.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
/*     This file is part of GNUnet.     (C) 2008 Christian Grothoff (and other contributing authors)     GNUnet is free software; you can redistribute it and/or modify     it under the terms of the GNU General Public License as published     by the Free Software Foundation; either version 2, or (at your     option) any later version.     GNUnet is distributed in the hope that it will be useful, but     WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     General Public License for more details.     You should have received a copy of the GNU General Public License     along with GNUnet; see the file COPYING.  If not, write to the     Free Software Foundation, Inc., 59 Temple Place - Suite 330,     Boston, MA 02111-1307, USA.*//** * @file applications/testing/remotetopologies.c * @brief helper to set up topologies for testing * @author Nathan Evans */#include "remote.h"static intprintInfo (void *data,           const GNUNET_PeerIdentity *           identity,           const void *address,           unsigned int addr_len,           GNUNET_CronTime last_message,           unsigned int trust, unsigned int bpmFromPeer){  GNUNET_EncName oth;  GNUNET_hash_to_enc (&identity->hashPubKey, &oth);  fprintf (stderr,           "%s: %llu - %u\n", (const char *) &oth, last_message, bpmFromPeer);  return GNUNET_OK;}intGNUNET_REMOTE_connect_clique (struct GNUNET_REMOTE_host_list *main_list){  struct GNUNET_REMOTE_host_list *pos = main_list;  struct GNUNET_REMOTE_host_list *iter_pos = main_list;  GNUNET_EncName *node1;  GNUNET_EncName *node2;  struct GNUNET_REMOTE_friends_list *node1temp;  struct GNUNET_REMOTE_friends_list *node2temp;  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));  while ((pos != NULL) && (pos->next != NULL))    {      iter_pos = pos->next;      while (iter_pos != NULL)        {          if (GNUNET_OK ==              GNUNET_REMOTE_get_daemons_information (pos->hostname, pos->port,                                                     iter_pos->hostname,                                                     iter_pos->port, &node1,                                                     &node2))            {              node1temp =                GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));              node2temp =                GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));              node2temp->hostentry = pos;              node1temp->hostentry = iter_pos;              node1temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));              node2temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));              memcpy (node1temp->nodeid, node2, sizeof (GNUNET_EncName));              memcpy (node2temp->nodeid, node1, sizeof (GNUNET_EncName));              node1temp->next = pos->friend_entries;              node2temp->next = iter_pos->friend_entries;              pos->friend_entries = node1temp;              iter_pos->friend_entries = node2temp;            }          iter_pos = iter_pos->next;        }      pos = pos->next;    }  GNUNET_free (node1);  GNUNET_free (node2);  return GNUNET_OK;}intGNUNET_REMOTE_connect_ring (struct GNUNET_REMOTE_host_list *main_list){  struct GNUNET_REMOTE_host_list *pos = main_list;  struct GNUNET_REMOTE_host_list *iter_pos = main_list;  GNUNET_EncName *node1;  GNUNET_EncName *node2;  struct GNUNET_REMOTE_friends_list *node1temp;  struct GNUNET_REMOTE_friends_list *node2temp;  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));  while (pos->next != NULL)    {      iter_pos = pos->next;      if (GNUNET_OK ==          GNUNET_REMOTE_get_daemons_information (pos->hostname, pos->port,                                                 iter_pos->hostname,                                                 iter_pos->port, &node1,                                                 &node2))        {          node1temp =            GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));          node2temp =            GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));          node2temp->hostentry = pos;          node1temp->hostentry = iter_pos;          node1temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));          node2temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));          memcpy (node1temp->nodeid, node2, sizeof (GNUNET_EncName));          memcpy (node2temp->nodeid, node1, sizeof (GNUNET_EncName));          node1temp->next = pos->friend_entries;          node2temp->next = iter_pos->friend_entries;          pos->friend_entries = node1temp;          iter_pos->friend_entries = node2temp;        }      pos = pos->next;    }  iter_pos = main_list;  if (GNUNET_OK ==      GNUNET_REMOTE_get_daemons_information (pos->hostname, pos->port,                                             iter_pos->hostname,                                             iter_pos->port, &node1, &node2))    {      node1temp = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));      node2temp = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));      node2temp->hostentry = pos;      node1temp->hostentry = iter_pos;      node1temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));      node2temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));      memcpy (node1temp->nodeid, node2, sizeof (GNUNET_EncName));      memcpy (node2temp->nodeid, node1, sizeof (GNUNET_EncName));      node1temp->next = pos->friend_entries;      node2temp->next = iter_pos->friend_entries;      pos->friend_entries = node1temp;      iter_pos->friend_entries = node2temp;    }  GNUNET_free (node1);  GNUNET_free (node2);  return GNUNET_OK;}intGNUNET_REMOTE_connect_2d_torus (unsigned int number_of_daemons,                                struct GNUNET_REMOTE_host_list                                **list_as_array){  unsigned int i;  unsigned int square;  unsigned int rows;  unsigned int cols;  unsigned int toggle = 1;  unsigned int nodeToConnect;  GNUNET_EncName *node1;  GNUNET_EncName *node2;  struct GNUNET_REMOTE_friends_list *node1temp;  struct GNUNET_REMOTE_friends_list *node2temp;  node1 = GNUNET_malloc (sizeof (GNUNET_EncName));  node2 = GNUNET_malloc (sizeof (GNUNET_EncName));  square = floor (sqrt (number_of_daemons));  rows = square;  cols = square;  if (square * square != number_of_daemons)    {      while (rows * cols < number_of_daemons)        {          if (toggle % 2 == 0)            rows++;          else            cols++;          toggle++;        }    }  fprintf (stderr,           _("Connecting nodes in 2d torus topology: %u rows %u columns\n"),           rows, cols);  /* Rows and columns are all sorted out, now iterate over all nodes and connect each   * to the node to its right and above.  Once this is over, we'll have our torus!   * Special case for the last node (if the rows and columns are not equal), connect   * to the first in the row to maintain topology.   */  for (i = 0; i < number_of_daemons; i++)    {      /* First connect to the node to the right */      if (((i + 1) % cols != 0) && (i + 1 != number_of_daemons))        nodeToConnect = i + 1;      else if (i + 1 == number_of_daemons)        nodeToConnect = rows * cols - cols;      else        nodeToConnect = i - cols + 1;      fprintf (stderr, "connecting node %u to %u\n", i, nodeToConnect);      GNUNET_REMOTE_get_daemons_information (list_as_array[i]->hostname,                                             list_as_array[i]->port,                                             list_as_array                                             [nodeToConnect]->hostname,                                             list_as_array                                             [nodeToConnect]->port, &node1,                                             &node2);      node1temp = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));      node2temp = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_friends_list));      node2temp->hostentry = list_as_array[i];      node1temp->hostentry = list_as_array[nodeToConnect];      node1temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));      node2temp->nodeid = GNUNET_malloc (sizeof (GNUNET_EncName));      memcpy (node1temp->nodeid, node2, sizeof (GNUNET_EncName));      memcpy (node2temp->nodeid, node1, sizeof (GNUNET_EncName));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -