static void terminate_peer (struct PeerContext *p) { if (NULL != p->ch) { GNUNET_CORE_disconnect (p->ch); p->ch = NULL; } if (NULL != p->ghh) { GNUNET_TRANSPORT_hello_get_cancel (p->ghh); p->ghh = NULL; } if (NULL != p->oh) { GNUNET_TRANSPORT_offer_hello_cancel (p->oh); p->oh = NULL; } if (NULL != p->ats_sh) { GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); p->ats_sh = NULL; } if (NULL != p->ats) { GNUNET_ATS_connectivity_done (p->ats); p->ats = NULL; } }
/** * Free all resources associated with the given peer. * * @param cls closure (not used) * @param pid identity of the peer * @param value peer to free * @return #GNUNET_YES (always: continue to iterate) */ static int free_peer (void *cls, const struct GNUNET_PeerIdentity * pid, void *value) { struct Peer *pos = value; GNUNET_break (NULL == pos->mq); GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (peers, pid, pos)); if (NULL != pos->hello_delay_task) { GNUNET_SCHEDULER_cancel (pos->hello_delay_task); pos->hello_delay_task = NULL; } if (NULL != pos->sh) { GNUNET_ATS_connectivity_suggest_cancel (pos->sh); pos->sh = NULL; } if (NULL != pos->hello) { GNUNET_free_non_null (pos->hello); pos->hello = NULL; } if (NULL != pos->filter) { GNUNET_CONTAINER_bloomfilter_free (pos->filter); pos->filter = NULL; } GNUNET_free (pos); return GNUNET_YES; }
/** * Recalculate how much we want to be connected to the specified peer * and let ATS know about the result. * * @param pos peer to consider connecting to */ static void attempt_connect (struct Peer *pos) { uint32_t strength; if (0 == memcmp (&my_identity, &pos->pid, sizeof (struct GNUNET_PeerIdentity))) return; /* This is myself, nothing to do. */ if (connection_count < target_connection_count) strength = 1; else strength = 0; if ( (friend_count < minimum_friend_count) || (GNUNET_YES == friends_only) ) { if (pos->is_friend) strength += 10; /* urgently needed */ else strength = 0; /* disallowed */ } if (pos->is_friend) strength *= 2; /* friends always count more */ if (NULL != pos->mq) strength *= 2; /* existing connections preferred */ if (strength == pos->strength) return; /* nothing to do */ if (NULL != pos->sh) { GNUNET_ATS_connectivity_suggest_cancel (pos->sh); pos->sh = NULL; } pos->strength = strength; if (0 != strength) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to connect to `%s' with strength %u\n", GNUNET_i2s (&pos->pid), (unsigned int) strength); GNUNET_STATISTICS_update (stats, gettext_noop ("# connect requests issued to ATS"), 1, GNUNET_NO); pos->sh = GNUNET_ATS_connectivity_suggest (ats, &pos->pid, strength); } }
static void terminate_peer (struct PeerContext *p) { if (p->nth != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (p->nth); p->nth = NULL; } if (NULL != p->ch) { GNUNET_CORE_disconnect (p->ch); p->ch = NULL; } if (NULL != p->th) { GNUNET_TRANSPORT_get_hello_cancel (p->ghh); GNUNET_TRANSPORT_disconnect (p->th); p->th = NULL; } if (NULL != p->ats_sh) { GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); p->ats_sh = NULL; } if (NULL != p->ats) { GNUNET_ATS_connectivity_done (p->ats); p->ats = NULL; } if (NULL != p->stats) { GNUNET_STATISTICS_destroy (p->stats, GNUNET_NO); p->stats = NULL; } if (NULL != p->hello) { GNUNET_free (p->hello); p->hello = NULL; } }
/** * Main interpreter loop. Runs the steps of the test. * * @param cls NULL * @param tc unused */ static void interpreter (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Command *cmd; interpreter_task = NULL; while (1) { cmd = &test_commands[off]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "#%u: %d %s\n", off, (int) cmd->code, (NULL != cmd->label) ? cmd->label : ""); switch (cmd->code) { case CMD_END_PASS: ret = 0; GNUNET_SCHEDULER_shutdown (); return; case CMD_ADD_ADDRESS: { struct GNUNET_HELLO_Address *addr; struct GNUNET_ATS_Session *session; addr = make_address (cmd->details.add_address.pid, cmd->details.add_address.addr_num, cmd->details.add_address.addr_flags); session = make_session (cmd->details.add_address.session); if (cmd->details.add_address.expect_fail) GNUNET_log_skip (1, GNUNET_NO); cmd->details.add_address.ar = GNUNET_ATS_address_add (sched_ats, addr, session, &cmd->details.add_address.properties); GNUNET_free (addr); if (cmd->details.add_address.expect_fail) { GNUNET_log_skip (0, GNUNET_YES); } else if (NULL == cmd->details.add_address.ar) { GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); return; } off++; break; } case CMD_DEL_ADDRESS: { struct Command *add; add = find_command (CMD_ADD_ADDRESS, cmd->details.del_address.add_label); GNUNET_assert (NULL != add->details.add_address.ar); GNUNET_ATS_address_destroy (add->details.add_address.ar); add->details.add_address.ar = NULL; off++; break; } case CMD_AWAIT_ADDRESS_SUGGESTION: { struct GNUNET_PeerIdentity pid; struct GNUNET_HELLO_Address *addr; struct Command *add; struct AddressSuggestData *asd; int done; make_peer (cmd->details.await_address_suggestion.pid, &pid); asd = find_address_suggestion (&pid); if (NULL == asd) return; if (GNUNET_NO == asd->active) return; /* last suggestion was to disconnect, wait longer */ done = GNUNET_YES; if (NULL != cmd->details.await_address_suggestion.add_label) { done = GNUNET_NO; add = find_command (CMD_ADD_ADDRESS, cmd->details.await_address_suggestion.add_label); addr = make_address (add->details.add_address.pid, add->details.add_address.addr_num, add->details.add_address.addr_flags); if ( (asd->session == make_session (add->details.add_address.session)) && (0 == GNUNET_HELLO_address_cmp (addr, asd->address)) ) done = GNUNET_YES; GNUNET_free (addr); } if (GNUNET_NO == done) return; off++; break; } case CMD_AWAIT_DISCONNECT_SUGGESTION: { struct GNUNET_PeerIdentity pid; struct AddressSuggestData *asd; make_peer (cmd->details.await_disconnect_suggestion.pid, &pid); asd = find_address_suggestion (&pid); if (NULL == asd) return; /* odd, no suggestion at all yet!? */ if (GNUNET_YES == asd->active) return; /* last suggestion was to activate, wait longer */ /* last suggestion was to deactivate, condition satisfied! */ off++; break; } case CMD_REQUEST_CONNECTION_START: { struct GNUNET_PeerIdentity pid; make_peer (cmd->details.request_connection_start.pid, &pid); cmd->details.request_connection_start.csh = GNUNET_ATS_connectivity_suggest (con_ats, &pid, 1); off++; break; } case CMD_REQUEST_CONNECTION_STOP: { struct Command *start; start = find_command (CMD_REQUEST_CONNECTION_START, cmd->details.request_connection_stop.connect_label); GNUNET_ATS_connectivity_suggest_cancel (start->details.request_connection_start.csh); start->details.request_connection_start.csh = NULL; off++; break; } case CMD_AWAIT_ADDRESS_INFORMATION: { struct AddressInformationData *aid; struct Command *add; struct Command *update; struct GNUNET_HELLO_Address *addr; const struct GNUNET_ATS_Properties *cmp; add = find_command (CMD_ADD_ADDRESS, cmd->details.await_address_information.add_label); update = find_command (CMD_UPDATE_ADDRESS, cmd->details.await_address_information.update_label); addr = make_address (add->details.add_address.pid, add->details.add_address.addr_num, add->details.add_address.addr_flags); aid = find_address_information (addr); GNUNET_free (addr); if (NULL == update) cmp = &add->details.add_address.properties; else cmp = &update->details.update_address.properties; if ( (NULL != aid) && (cmp->delay.rel_value_us == aid->properties.delay.rel_value_us) && (cmp->utilization_out == aid->properties.utilization_out) && (cmp->utilization_in == aid->properties.utilization_in) && (cmp->distance == aid->properties.distance) && (cmp->scope == aid->properties.scope) ) { off++; break; } return; } case CMD_UPDATE_ADDRESS: { struct Command *add; add = find_command (CMD_ADD_ADDRESS, cmd->details.update_address.add_label); GNUNET_assert (NULL != add->details.add_address.ar); GNUNET_ATS_address_update (add->details.add_address.ar, &cmd->details.update_address.properties); off++; break; } case CMD_ADD_SESSION: { struct Command *add; struct GNUNET_ATS_Session *session; add = find_command (CMD_ADD_ADDRESS, cmd->details.add_session.add_label); session = make_session (cmd->details.add_session.session); GNUNET_assert (NULL != add->details.add_address.ar); GNUNET_ATS_address_add_session (add->details.add_address.ar, session); off++; break; } case CMD_DEL_SESSION: { struct Command *add_address; struct Command *add_session; struct GNUNET_ATS_Session *session; add_session = find_command (CMD_ADD_SESSION, cmd->details.del_session.add_session_label); add_address = find_command (CMD_ADD_ADDRESS, add_session->details.add_session.add_label); GNUNET_assert (NULL != add_address->details.add_address.ar); session = make_session (add_session->details.add_session.session); GNUNET_ATS_address_del_session (add_address->details.add_address.ar, session); off++; break; } case CMD_CHANGE_PREFERENCE: { struct GNUNET_PeerIdentity pid; make_peer (cmd->details.change_preference.pid, &pid); GNUNET_ATS_performance_change_preference (perf_ats, &pid, GNUNET_ATS_PREFERENCE_END); off++; break; } case CMD_PROVIDE_FEEDBACK: { struct GNUNET_PeerIdentity pid; make_peer (cmd->details.provide_feedback.pid, &pid); GNUNET_ATS_performance_give_feedback (perf_ats, &pid, cmd->details.provide_feedback.scope, GNUNET_ATS_PREFERENCE_END); off++; break; } case CMD_LIST_ADDRESSES: { struct GNUNET_PeerIdentity pid; make_peer (cmd->details.list_addresses.pid, &pid); cmd->details.list_addresses.alh = GNUNET_ATS_performance_list_addresses (perf_ats, &pid, cmd->details.list_addresses.all, &info_cb, cmd); return; } case CMD_RESERVE_BANDWIDTH: { struct GNUNET_PeerIdentity pid; make_peer (cmd->details.reserve_bandwidth.pid, &pid); cmd->details.reserve_bandwidth.rc = GNUNET_ATS_reserve_bandwidth (perf_ats, &pid, cmd->details.reserve_bandwidth.amount, &reservation_cb, cmd); return; } case CMD_SLEEP: off++; interpreter_task = GNUNET_SCHEDULER_add_delayed (cmd->details.sleep.delay, &interpreter, NULL); return; } /* end switch */ } /* end while(1) */ }