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

📄 remotetopologies.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
      node1temp->next = list_as_array[i]->friend_entries;      node2temp->next = list_as_array[nodeToConnect]->friend_entries;      list_as_array[i]->friend_entries = node1temp;      list_as_array[nodeToConnect]->friend_entries = node2temp;      /* Second connect to the node immediately above */      if (i < cols)        nodeToConnect = (rows * cols) - cols + i;      else        nodeToConnect = i - cols;      if (nodeToConnect < number_of_daemons)        {          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));          node1temp->next = list_as_array[i]->friend_entries;          node2temp->next = list_as_array[nodeToConnect]->friend_entries;          list_as_array[i]->friend_entries = node1temp;          list_as_array[nodeToConnect]->friend_entries = node2temp;        }    }  GNUNET_free (node1);  GNUNET_free (node2);  return GNUNET_OK;}intGNUNET_REMOTE_connect_small_world (int number_of_daemons,                                   struct GNUNET_REMOTE_host_list                                   **list_as_array){  return GNUNET_SYSERR;}/*** Establish a connection between two GNUnet daemons** @param port1 client port of the first daemon* @param port2 client port of the second daemon* @param ip1 client ip or hostname for the first daemon* @param ip2 client ip or hostname for the second daemon* @return GNUNET_OK on success, GNUNET_SYSERR on failure*/intGNUNET_REMOTE_connect_daemons (char *hostname1, unsigned short port1,                               char *hostname2, unsigned short port2){  char host[128];  struct GNUNET_GC_Configuration *cfg1 = GNUNET_GC_create ();  struct GNUNET_GC_Configuration *cfg2 = GNUNET_GC_create ();  struct GNUNET_ClientServerConnection *sock1;  struct GNUNET_ClientServerConnection *sock2;  int ret;  GNUNET_EncName *host1entry;  GNUNET_EncName *host2entry;  host1entry = GNUNET_malloc (sizeof (GNUNET_EncName));  host2entry = GNUNET_malloc (sizeof (GNUNET_EncName));  GNUNET_MessageHello *h1;  GNUNET_MessageHello *h2;  ret = GNUNET_SYSERR;  GNUNET_snprintf (host, 128, "%s:%u", hostname1, port1);  GNUNET_GC_set_configuration_value_string (cfg1, NULL, "NETWORK", "HOST",                                            host);  GNUNET_snprintf (host, 128, "%s:%u", hostname2, port2);  GNUNET_GC_set_configuration_value_string (cfg2, NULL, "NETWORK", "HOST",                                            host);  if ((GNUNET_OK ==       GNUNET_wait_for_daemon_running (NULL, cfg1, 300 * GNUNET_CRON_SECONDS))      && (GNUNET_OK ==          GNUNET_wait_for_daemon_running (NULL, cfg2,                                          300 * GNUNET_CRON_SECONDS)))    {      sock1 = GNUNET_client_connection_create (NULL, cfg1);      sock2 = GNUNET_client_connection_create (NULL, cfg2);      ret = -20;      fprintf (stderr, _("Waiting for peers to connect"));      h1 = NULL;      h2 = NULL;      while ((ret++ < -1) && (GNUNET_shutdown_test () == GNUNET_NO))        {          if ((GNUNET_OK == GNUNET_IDENTITY_get_self (sock1,                                                      &h1)) &&              (GNUNET_OK == GNUNET_IDENTITY_get_self (sock2,                                                      &h2)) &&              (GNUNET_OK == GNUNET_IDENTITY_peer_add (sock1,                                                      h2)) &&              (GNUNET_OK == GNUNET_IDENTITY_peer_add (sock2, h1)))            {              fprintf (stderr, ".");              if (GNUNET_YES == GNUNET_IDENTITY_request_connect (sock1,                                                                 &h2->                                                                 senderIdentity))                {                  ret = GNUNET_OK;                  break;                }              if (GNUNET_YES == GNUNET_IDENTITY_request_connect (sock2,                                                                 &h1->                                                                 senderIdentity))                {                  ret = GNUNET_OK;                  break;                }              GNUNET_thread_sleep (100 * GNUNET_CRON_MILLISECONDS);            }        }      GNUNET_hash_to_enc (&h1->senderIdentity.hashPubKey, host1entry);      GNUNET_hash_to_enc (&h2->senderIdentity.hashPubKey, host2entry);      GNUNET_free_non_null (h1);      GNUNET_free_non_null (h2);      if (ret != GNUNET_OK)        {          fprintf (stderr,                   "\nFailed to connect `%s' and `%s'\n",                   (const char *) host1entry, (const char *) host2entry);          fprintf (stderr, "Connections of `%s':\n",                   (const char *) host1entry);          GNUNET_IDENTITY_request_peer_infos (sock1, &printInfo, NULL);          fprintf (stderr, "Connections of `%s':\n",                   (const char *) host2entry);          GNUNET_IDENTITY_request_peer_infos (sock2, &printInfo, NULL);        }      fprintf (stderr, "%s\n", ret == GNUNET_OK ? "Connected nodes." : "?");      GNUNET_client_connection_destroy (sock1);      GNUNET_client_connection_destroy (sock2);    }  else    {      fprintf (stderr, "Failed to establish connection with peers.\n");    }  GNUNET_GC_free (cfg1);  GNUNET_GC_free (cfg2);  GNUNET_free (host1entry);  GNUNET_free (host2entry);  return ret;}intGNUNET_REMOTE_get_daemons_information (char *hostname1, unsigned short port1,                                       char *hostname2, unsigned short port2,                                       GNUNET_EncName ** host1entry,                                       GNUNET_EncName ** host2entry){  char host[128];  struct GNUNET_GC_Configuration *cfg1 = GNUNET_GC_create ();  struct GNUNET_GC_Configuration *cfg2 = GNUNET_GC_create ();  struct GNUNET_ClientServerConnection *sock1;  struct GNUNET_ClientServerConnection *sock2;  int ret;  GNUNET_MessageHello *h1;  GNUNET_MessageHello *h2;  ret = GNUNET_SYSERR;  GNUNET_snprintf (host, 128, "%s:%u", hostname1, port1);  GNUNET_GC_set_configuration_value_string (cfg1, NULL, "NETWORK", "HOST",                                            host);  GNUNET_snprintf (host, 128, "%s:%u", hostname2, port2);  GNUNET_GC_set_configuration_value_string (cfg2, NULL, "NETWORK", "HOST",                                            host);  if ((GNUNET_OK ==       GNUNET_wait_for_daemon_running (NULL, cfg1, 300 * GNUNET_CRON_SECONDS))      && (GNUNET_OK ==          GNUNET_wait_for_daemon_running (NULL, cfg2,                                          300 * GNUNET_CRON_SECONDS)))    {      sock1 = GNUNET_client_connection_create (NULL, cfg1);      sock2 = GNUNET_client_connection_create (NULL, cfg2);      ret = -20;      while ((ret++ < -1) && (GNUNET_shutdown_test () == GNUNET_NO))        {          h1 = NULL;          h2 = NULL;          if ((GNUNET_OK == GNUNET_IDENTITY_get_self (sock1, &h1))              && (GNUNET_OK == GNUNET_IDENTITY_get_self (sock2, &h2)))            {              ret = GNUNET_OK;              break;            }          GNUNET_thread_sleep (100 * GNUNET_CRON_MILLISECONDS);        }      GNUNET_hash_to_enc (&h1->senderIdentity.hashPubKey, *host1entry);      GNUNET_hash_to_enc (&h2->senderIdentity.hashPubKey, *host2entry);      GNUNET_free_non_null (h1);      GNUNET_free_non_null (h2);      GNUNET_client_connection_destroy (sock1);      GNUNET_client_connection_destroy (sock2);    }  else    {      fprintf (stderr, _("Failed to establish connection with peers.\n"));    }  GNUNET_GC_free (cfg1);  GNUNET_GC_free (cfg2);  return ret;}/* end of remotetopologies.c */

⌨️ 快捷键说明

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