📄 remote.c
字号:
{ GNUNET_free (temp_path); GNUNET_free (temp_remote_config_path); break; } temp = GNUNET_malloc (32); if (1 == sscanf (temp_path, "/tmp/%s", temp)) { temp_pos = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_host_list)); temp_pos->hostname = GNUNET_strdup (curr_host); temp_pos->username = GNUNET_strdup (ssh_username); friend_location_length = snprintf (NULL, 0, "%s/friends", temp_remote_config_path); temp_pos->remote_friend_file_path = GNUNET_malloc (friend_location_length + 1); snprintf (temp_pos->remote_friend_file_path, friend_location_length + 1, "%s/friends", temp_remote_config_path); GNUNET_REMOTE_start_daemon (remote_gnunetd_path, "/tmp/", temp, remote_config_path, curr_host, ssh_username, temp_pos->remote_friend_file_path); GNUNET_GC_get_configuration_value_number (basecfg, "NETWORK", "PORT", 0, 65535, 65535, &temp_port); temp_pos->port = (unsigned short) temp_port; temp_pos->next = head; head = temp_pos; array_of_pointers[count_started] = temp_pos; count_started++; } GNUNET_free (temp_remote_config_path); GNUNET_free (temp); UNLINK (temp_path); GNUNET_free (temp_path); if ((i < extra_daemons) && (j == daemons_per_machine - 1)) { length_temp = snprintf (NULL, 0, "%s%s%d", remote_pid_path, "pid", j + 1); temp_pid_file = GNUNET_malloc (length_temp + 1); snprintf (temp_pid_file, length_temp + 1, "%s%s%d", remote_pid_path, "pid", j + 1); GNUNET_GC_set_configuration_value_string (basecfg, NULL, "GNUNETD", "PIDFILE", temp_pid_file); GNUNET_free (temp_pid_file); temp_remote_config_path_length = snprintf (NULL, 0, "%s%d", remote_config_path, j); temp_remote_config_path = GNUNET_malloc (temp_remote_config_path_length + 1); snprintf (temp_remote_config_path, temp_remote_config_path_length + 1, "%s%d", remote_config_path, j); GNUNET_GC_set_configuration_value_string (basecfg, NULL, "PATHS", "GNUNETD_HOME", temp_remote_config_path); GNUNET_GC_set_configuration_value_number (basecfg, NULL, "NETWORK", "PORT", starting_port + ((j + 1) * port_increment)); GNUNET_GC_set_configuration_value_number (basecfg, NULL, "TCP", "PORT", starting_port + ((j + 1) * port_increment) + 1); GNUNET_GC_set_configuration_value_number (basecfg, NULL, "UDP", "PORT", starting_port + ((j + 1) * port_increment) + 1); temp_path = GNUNET_strdup ("/tmp/gnunetd.conf.XXXXXX"); ret = mkstemp (temp_path); if (ret == -1) { GNUNET_GE_LOG_STRERROR_FILE (NULL, GNUNET_GE_ERROR | GNUNET_GE_USER | GNUNET_GE_BULK, "mkstemp", temp_path); GNUNET_free (temp_path); GNUNET_free (temp_remote_config_path); break; } CLOSE (ret); if (0 != GNUNET_GC_write_configuration (basecfg, temp_path)) { GNUNET_free (temp_path); GNUNET_free (temp_remote_config_path); break; } temp = GNUNET_malloc (32); if (1 == sscanf (temp_path, "/tmp/%s", temp)) { temp_pos = GNUNET_malloc (sizeof (struct GNUNET_REMOTE_host_list)); temp_pos->hostname = GNUNET_strdup (curr_host); temp_pos->username = GNUNET_strdup (ssh_username); friend_location_length = snprintf (NULL, 0, "%s/friends", temp_remote_config_path); temp_pos->remote_friend_file_path = GNUNET_malloc (friend_location_length + 1); GNUNET_snprintf (temp_pos->remote_friend_file_path, friend_location_length + 1, "%s/friends", temp_remote_config_path); GNUNET_REMOTE_start_daemon (remote_gnunetd_path, "/tmp/", temp, remote_config_path, curr_host, ssh_username, temp_pos-> remote_friend_file_path); GNUNET_GC_get_configuration_value_number (basecfg, "NETWORK", "PORT", 0, 65535, 65535, &temp_port); temp_pos->port = (unsigned short) temp_port; temp_pos->next = head; head = temp_pos; array_of_pointers[count_started] = temp_pos; count_started++; } GNUNET_free (temp_remote_config_path); UNLINK (temp_path); GNUNET_free (temp_path); GNUNET_free (temp); } } GNUNET_GC_free (basecfg); ++i; } ret = GNUNET_REMOTE_create_topology (type_of_topology, number_of_daemons); GNUNET_free (base_config); GNUNET_free (remote_pid_path); GNUNET_free (data_dir); GNUNET_free (ssh_username); GNUNET_free (control_host); GNUNET_free (hostnames); GNUNET_free (remote_config_path); GNUNET_free (remote_gnunetd_path); return ret;}intGNUNET_REMOTE_create_topology (GNUNET_REMOTE_TOPOLOGIES t, int number_of_daemons){ FILE *temp_friend_handle; int ret; struct GNUNET_REMOTE_host_list *pos; struct GNUNET_REMOTE_friends_list *friend_pos; char *cmd; int length; ret = GNUNET_OK; switch (t) { case GNUNET_REMOTE_CLIQUE: fprintf (stderr, "Creating clique topology\n"); ret = GNUNET_REMOTE_connect_clique (head); break; case GNUNET_REMOTE_SMALL_WORLD: fprintf (stderr, "Creating small world topology\n"); ret = GNUNET_SYSERR; break; case GNUNET_REMOTE_RING: fprintf (stderr, "Creating ring topology\n"); ret = GNUNET_SYSERR; break; case GNUNET_REMOTE_2D_TORUS: fprintf (stderr, "Creating 2d torus topology\n"); ret = GNUNET_REMOTE_connect_2d_torus (number_of_daemons, list_as_array); break; default: ret = GNUNET_SYSERR; break; } if (ret == GNUNET_OK) { pos = head; while (pos != NULL) { /* Printing out the friends isn't necessary, but it's nice */ fprintf (stderr, _("Friend list of %s:%d\n"), pos->hostname, pos->port); temp_friend_handle = fopen ("friend.temp", "wt"); friend_pos = pos->friend_entries; while (friend_pos != NULL) { fprintf (stderr, "\t%s\n", (const char *) friend_pos->nodeid); fprintf (temp_friend_handle, "%s\n", (const char *) friend_pos->nodeid); friend_pos = friend_pos->next; } fclose (temp_friend_handle); length = snprintf (NULL, 0, "scp %s %s@%s:%s", "friend.temp", pos->username, pos->hostname, pos->remote_friend_file_path); cmd = GNUNET_malloc (length + 1); snprintf (cmd, length + 1, "scp %s %s@%s:%s", "friend.temp", pos->username, pos->hostname, pos->remote_friend_file_path); fprintf (stderr, _("scp command for friend file copy is : %s \n"), cmd); system (cmd); GNUNET_free (cmd); pos = pos->next; } system ("rm friend.temp"); pos = head; /* This loop goes over the friend entries of each peer and connects that * peer to each friend in the list. Note this is redundant, i.e. once * the two are connected, the second doesn't really need to try to connect * to the first later, but this IS simple. If performance becomes a problem * with MANY conns, we'll see... */ while (pos != NULL) { friend_pos = pos->friend_entries; while (friend_pos != NULL) { fprintf (stderr, _("connecting peer %s:%d to peer %s:%d\n"), pos->hostname, pos->port, friend_pos->hostentry->hostname, friend_pos->hostentry->port); GNUNET_REMOTE_connect_daemons (pos->hostname, pos->port, friend_pos->hostentry->hostname, friend_pos->hostentry->port); friend_pos = friend_pos->next; } pos = pos->next; } } else { fprintf (stderr, "connect didn't return well!\n"); } return ret;}/* end of remote.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -