static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message) { struct PeerContext *p = cls; struct PeerContext *t = NULL; if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) t = p1; if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) t = p2; GNUNET_assert (t != NULL); char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); GNUNET_free (ps); if (0 >= p1_c) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer 1 did not receive validation callbacks for peer 2\n"); } if (0 >= p2_c) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer 2 did not receive validation callbacks for peer 1\n"); } if ((0 >= p1_c) || (0 >= p2_c)) { if (NULL != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } else end (); }
static size_t notify_ready (void *cls, size_t size, void *buf) { struct PeerContext *p = cls; struct GNUNET_MessageHeader *hdr; th = NULL; if (buf == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout occurred while waiting for transmit_ready\n"); if (NULL != die_task) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); ok = 42; return 0; } GNUNET_assert (size >= TEST_MESSAGE_SIZE); memset (buf, '\0', TEST_MESSAGE_SIZE); hdr = buf; hdr->size = htons (TEST_MESSAGE_SIZE); hdr->type = htons (TEST_MESSAGE_TYPE); { char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, GNUNET_i2s (&p->id)); GNUNET_free (ps); } return TEST_MESSAGE_SIZE; }
static void restart_task () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') restarting, \n", p->no, GNUNET_i2s (&p->id)); GNUNET_TRANSPORT_TESTING_restart_peer (p, NULL, &restart_cb, p); }
static void print_info (const struct GNUNET_PeerIdentity *id, const char *transport, const char *addr, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout) { if ((GNUNET_YES == iterate_all) || (GNUNET_YES == monitor_connections) ) { FPRINTF (stdout, _("Peer `%s': %s %s in state `%s' until %s\n"), GNUNET_i2s (id), (NULL == transport) ? "<none>" : transport, (NULL == transport) ? "<none>" : addr, GNUNET_TRANSPORT_ps2s (state), GNUNET_STRINGS_absolute_time_to_string (state_timeout)); } else { /* Only connected peers, skip state */ FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (id), transport, addr); } }
/** * Function called to notify transport users that another * peer disconnected from us. * * @param cls closure * @param peer the peer that disconnected */ static void monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); GNUNET_assert(monitor_connect_counter > 0); monitor_connect_counter--; FPRINTF (stdout, _("%24s: %-17s %4s (%u connections in total)\n"), now_str, _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter); }
/** * Task called when it is time to destroy an inactive stream. * * @param cls the 'struct StreamHandle' to tear down * @param tc scheduler context, unused */ static void stream_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct StreamHandle *sh = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout on stream to %s\n", GNUNET_i2s (&sh->target)); sh->timeout_task = GNUNET_SCHEDULER_NO_TASK; destroy_stream_handle (sh); }
/** * One of our neighbours has excess bandwidth, remember this. * * @param cls NULL * @param pid identity of the peer with excess bandwidth */ static void handle_transport_notify_excess_bw (void *cls, const struct GNUNET_PeerIdentity *pid) { struct Neighbour *n; n = find_neighbour (pid); if (NULL == n) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s not found\n", GNUNET_i2s (pid)); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %s has excess bandwidth available\n", GNUNET_i2s (pid)); n->has_excess_bandwidth = GNUNET_YES; GSC_SESSIONS_solicit (pid); }
static void start_cb (struct PeerContext *p, void *cls) { static int started; started++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, GNUNET_i2s (&p->id)); if (started != 2) return; char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (sender_c); cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, NULL); }
static int reset_address_it (void *cls, const GNUNET_HashCode * key, void *value) { struct ATS_Address *aa = value; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resetting interval for peer `%s' address %p from %llu to 0\n", GNUNET_i2s (&aa->peer), aa, aa->block_interval); aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; aa->block_interval = GNUNET_TIME_UNIT_ZERO; return GNUNET_OK; }
static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, GNUNET_i2s (peer)); GNUNET_free (ps); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; if (shutdown_ == GNUNET_YES) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n"); GNUNET_SCHEDULER_add_now (&end, NULL); } }
/** * Obtain statistics and/or change preferences for the given peer. * * @param h core handle * @param peer identifies the peer * @param amount reserve N bytes for receiving, negative * amounts can be used to undo a (recent) reservation; * @param preference increase incoming traffic share preference by this amount; * in the absence of "amount" reservations, we use this * preference value to assign proportional bandwidth shares * to all connected peers * @param info function to call with the resulting configuration information * @param info_cls closure for info * @return NULL on error */ struct GNUNET_ATS_InformationRequestContext * GNUNET_ATS_peer_change_preference (struct GNUNET_ATS_SchedulingHandle *h, const struct GNUNET_PeerIdentity *peer, int32_t amount, uint64_t preference, GNUNET_ATS_PeerConfigurationInfoCallback info, void *info_cls) { struct GNUNET_ATS_InformationRequestContext *irc; struct PeerRecord *pr; struct RequestInfoMessage *rim; struct ControlMessage *cm; pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey); if (NULL == pr) { /* attempt to change preference on peer that is not connected */ GNUNET_assert (0); return NULL; } if (pr->pcic != NULL) { /* second change before first one is done */ GNUNET_break (0); return NULL; } irc = GNUNET_malloc (sizeof (struct GNUNET_ATS_InformationRequestContext)); irc->h = h; irc->pr = pr; cm = GNUNET_malloc (sizeof (struct ControlMessage) + sizeof (struct RequestInfoMessage)); cm->cont = &change_preference_send_continuation; cm->cont_cls = irc; irc->cm = cm; rim = (struct RequestInfoMessage *) &cm[1]; rim->header.size = htons (sizeof (struct RequestInfoMessage)); rim->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_REQUEST_INFO); rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++); rim->reserved = htonl (0); rim->reserve_inbound = htonl (amount); rim->preference_change = GNUNET_htonll (preference); rim->peer = *peer; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n", GNUNET_i2s (peer), (unsigned int) pr->rim_id); GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, h->control_pending_tail, cm); pr->pcic = info; pr->pcic_cls = info_cls; pr->pcic_ptr = irc; /* for free'ing irc */ if (NULL != h->client) trigger_next_request (h, GNUNET_NO); return irc; }
static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no, GNUNET_i2s (peer)); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; }
static void disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct TestMessageContext *pos = cls; /* Disconnect from the respective cores */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id)); if (pos->peer1handle != NULL) GNUNET_CORE_disconnect (pos->peer1handle); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id)); if (pos->peer2handle != NULL) GNUNET_CORE_disconnect (pos->peer2handle); /* Set handles to NULL so test case can be ended properly */ pos->peer1handle = NULL; pos->peer2handle = NULL; pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK; /* Decrement total connections so new can be established */ total_server_connections -= 2; }
static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; char *p2_s; struct PeerContext *p2; GNUNET_assert (NULL != p); GNUNET_assert (NULL != p->tth); p2 = find_peer_context (p->tth, peer); if (p->nc != NULL) p->nc (p->cb_cls, peer); if (p2 != NULL) GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); else GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer)); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", "Peers %s connected to peer %u (`%s')\n", p2_s, p->no, GNUNET_i2s (&p->id)); GNUNET_free (p2_s); /* Find ConnectingContext */ struct ConnectingContext *cc = find_connecting_context (p->tth, p, p2); if (cc == NULL) return; if (p == cc->p1) cc->p1_c = GNUNET_YES; if (p == cc->p2) cc->p2_c = GNUNET_YES; if ((cc->p1_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES)) { cc->cb (cc->p1, cc->p2, cc->cb_cls); GNUNET_TRANSPORT_TESTING_connect_peers_cancel (p->tth, cc); } }
/** * Method called whenever a given peer connects. * * @param cls closure * @param peer peer identity this notification is about * @param atsi performance data for the connection * @param atsi_count number of records in 'atsi' */ static void connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) { struct TestMessageContext *pos = cls; if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity))) { pos->peer1notified = GNUNET_YES; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' notified of connection to peer `%s'\n", GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); } else return; if (pos->peer2connected == GNUNET_YES) /* Already connected and notified of connection, send message! */ { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n", GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&pos->peer1->id.hashPubKey)); if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0, TIMEOUT, &pos->peer2->id, sizeof (struct GNUNET_TestMessage), &transmit_ready, pos)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", GNUNET_i2s (&pos->peer2->id)); transmit_ready_failed++; } else { transmit_ready_scheduled++; } } }
/** * Check if an additional connection from the given peer is allowed. * * @param peer connection to check * @return GNUNET_OK if the connection is allowed */ static int is_connection_allowed (struct Peer *peer) { if (0 == memcmp (&my_identity, &peer->pid, sizeof (struct GNUNET_PeerIdentity))) return GNUNET_SYSERR; /* disallow connections to self */ if (peer->is_friend) return GNUNET_OK; if (GNUNET_YES == friends_only) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Determined that `%s' is not allowed to connect (not a friend)\n", GNUNET_i2s (&peer->pid)); return GNUNET_SYSERR; } if (friend_count >= minimum_friend_count) return GNUNET_OK; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Determined that `%s' is not allowed to connect (not enough connected friends)\n", GNUNET_i2s (&peer->pid)); return GNUNET_SYSERR; }
/** * Perform an update for an address * * @param cur the address to update */ static void perf_update_address (struct ATS_Address *cur) { int r_type; int abs_val; double rel_val; r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2); switch (r_type) { case 0: abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); rel_val = (100 + (double) abs_val) / 100; GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DELAY", abs_val, rel_val); ph.sf->s_address_update_property (ph.sf->cls, cur, GNUNET_ATS_QUALITY_NET_DELAY, abs_val, rel_val); break; case 1: abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10); rel_val = (100 + (double) abs_val) / 100; GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", abs_val, rel_val); ph.sf->s_address_update_property (ph.sf->cls, cur, GNUNET_ATS_QUALITY_NET_DISTANCE, abs_val, rel_val); break; default: break; } }
/** * Process friend found in FRIENDS file. * * @param cls pointer to an `unsigned int` to be incremented per friend found * @param pid identity of the friend */ static void handle_friend (void *cls, const struct GNUNET_PeerIdentity *pid) { unsigned int *entries_found = cls; struct Peer *fl; if (0 == memcmp (pid, &my_identity, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Found myself `%s' in friend list (useless, ignored)\n"), GNUNET_i2s (pid)); return; } (*entries_found)++; fl = make_peer (pid, NULL, GNUNET_YES); GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Found friend `%s' in configuration\n"), GNUNET_i2s (&fl->pid)); }
static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { if (cls == cc1) { cc1 = NULL; GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc2); } if (cls == cc2) { cc2 = NULL; GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc1); } char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); }
static void restart_cb (struct PeerContext *p, void *cls) { static int c; c++; if (c != 2) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarted peer %u (`%4s'), issuing reconnect\n", p->no, GNUNET_i2s (&p->id)); reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, p); }
static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) { static int c; c++; struct PeerContext *p = cls; struct PeerContext *t = NULL; if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) t = p1; if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) t = p2; GNUNET_assert (t != NULL); char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, t->no, GNUNET_i2s (peer)); GNUNET_free (ps); }
/** * Function called by transport to notify us that * a peer connected to us (on the network level). * * @param cls closure * @param peer the peer that connected */ static void handle_transport_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct Neighbour *n; if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_break (0); return; } n = find_neighbour (peer); if (NULL != n) { /* duplicate connect notification!? */ GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s exists already\n", GNUNET_i2s (peer)); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received connection from `%s'.\n", GNUNET_i2s (peer)); n = GNUNET_new (struct Neighbour); n->peer = *peer; GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (neighbours, &n->peer, n, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"), GNUNET_CONTAINER_multipeermap_size (neighbours), GNUNET_NO); n->kxinfo = GSC_KX_start (peer); }
/** * Function that will be called whenever two daemons are connected by * the testing library. * * @param cls closure * @param first peer id for first daemon * @param second peer id for the second daemon * @param distance distance between the connected peers * @param first_cfg config for the first daemon * @param second_cfg config for the second daemon * @param first_daemon handle for the first daemon * @param second_daemon handle for the second daemon * @param emsg error message (NULL on success) */ static void connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, const struct GNUNET_PeerIdentity *second, uint32_t distance, const struct GNUNET_CONFIGURATION_Handle *first_cfg, const struct GNUNET_CONFIGURATION_Handle *second_cfg, struct GNUNET_TESTING_Daemon *first_daemon, struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) { if (emsg == NULL) { total_connections++; } else { failed_connections++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Problem with new connection (%s)\n", emsg); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: (%s)\n", GNUNET_i2s (first)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: (%s)\n", GNUNET_i2s (second)); } }
static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { cc = NULL; { char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); } s_connected = GNUNET_YES; send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); }
/** * Function called if DV receives a message for this peer. * * @param cls closure * @param sender sender of the message * @param distance how far did the message travel * @param msg actual message payload */ static void message_cb (void *cls, const struct GNUNET_PeerIdentity *sender, uint32_t distance, const struct GNUNET_MessageHeader *msg) { if (verbose) fprintf (stderr, "Message: %s at %u sends %u bytes of type %u\n", GNUNET_i2s (sender), (unsigned int) distance, (unsigned int) ntohs (msg->size), (unsigned int) ntohs (msg->type)); }
/** * Function that will be called whenever the plugin internally * cleans up a session pointer and hence the service needs to * discard all of those sessions as well. Plugins that do not * use sessions can simply omit calling this function and always * use NULL wherever a session pointer is needed. This function * should be called BEFORE a potential "TransmitContinuation" * from the "TransmitFunction". * * @param cls closure * @param peer which peer was the session for * @param session which session is being destoyed */ static void plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, struct Session *session) { const char *transport_name = cls; struct GNUNET_HELLO_Address address; GNUNET_assert (strlen (transport_name) > 0); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", session, GNUNET_i2s (peer)); if (NULL != session) GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "transport-ats", "Telling ATS to destroy session %p from peer %s\n", session, GNUNET_i2s (peer)); address.peer = *peer; address.address = NULL; address.address_length = 0; address.transport_name = transport_name; GST_neighbours_session_terminated (peer, session); GNUNET_ATS_address_destroyed (GST_ats, &address, session); }
/** * Builds a path from a PeerIdentity array. * * @param peers PeerIdentity array. * @param size Size of the @c peers array. * @param myid ID of local peer, to find @c own_pos. * @param own_pos Output parameter: own position in the path. * * @return Fixed and shortened path. */ struct CadetPeerPath * path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers, unsigned int size, GNUNET_PEER_Id myid, unsigned int *own_pos) { struct CadetPeerPath *path; GNUNET_PEER_Id shortid; unsigned int i; unsigned int j; unsigned int offset; /* Create path */ LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); path = path_new (size); *own_pos = 0; offset = 0; for (i = 0; i < size; i++) { LOG (GNUNET_ERROR_TYPE_DEBUG, " - %u: taking %s\n", i, GNUNET_i2s (&peers[i])); shortid = GNUNET_PEER_intern (&peers[i]); /* Check for loops / duplicates */ for (j = 0; j < i - offset; j++) { if (path->peers[j] == shortid) { LOG (GNUNET_ERROR_TYPE_DEBUG, " already exists at pos %u\n", j); offset = i - j; LOG (GNUNET_ERROR_TYPE_DEBUG, " offset now %u\n", offset); GNUNET_PEER_change_rc (shortid, -1); } } LOG (GNUNET_ERROR_TYPE_DEBUG, " storing at %u\n", i - offset); path->peers[i - offset] = shortid; if (path->peers[i - offset] == myid) *own_pos = i - offset; } path->length -= offset; if (path->peers[*own_pos] != myid) { /* create path: self not found in path through self */ GNUNET_break_op (0); path_destroy (path); return NULL; } return path; }
static void request_address_simple (const struct GNUNET_PeerIdentity *peer) { struct ATS_Address *aa; aa = NULL; /* Get address with: stick to current address, lower distance, lower latency */ GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, &find_address_it, &aa); if (aa == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Suggesting address %p for peer `%s'\n", aa, GNUNET_i2s (peer)); if (aa->active == GNUNET_NO) { aa->active = GNUNET_YES; active_addr_count++; if (ats_mode == SIMPLE) { recalculate_assigned_bw (); } } else { /* just to be sure... */ GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr, aa->addr_len, aa->session_id, aa->ats, aa->ats_count, aa->assigned_bw_out, aa->assigned_bw_in); } }
static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) { struct PeerContext *pc = cls; if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) return; GNUNET_assert (pc->connect_status == 0); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection established to peer `%4s'\n", GNUNET_i2s (peer)); if (GNUNET_SCHEDULER_NO_TASK != con_task) { GNUNET_SCHEDULER_cancel (con_task); con_task = GNUNET_SCHEDULER_NO_TASK; } pc->connect_status = 1; if (pc == &p1) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking core (1) for transmission to peer `%4s'\n", GNUNET_i2s (&p2.id)); if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_YES, 0, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 145), &p2.id, sizeof (struct GNUNET_MessageHeader), &transmit_ready, &p1)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n", GNUNET_i2s (&p2.id)); } } }
/** * Black list check result for try_connect call * If connection to the peer is allowed request adddress and ??? * * @param cls the message * @param peer the peer * @param address the address * @param session the session * @param result the result */ static void connect_bl_check_cont (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, int result) { struct GNUNET_MessageHeader *msg = cls; if (GNUNET_OK == result) { /* Blacklist allows to speak to this peer, forward SYN to neighbours */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received SYN message from peer `%s' at `%s'\n", GNUNET_i2s (peer), GST_plugins_a2s (address)); if (GNUNET_OK != GST_neighbours_handle_session_syn (msg, peer)) { GST_blacklist_abort_matching (address, session); kill_session (address->transport_name, session); } GNUNET_free (msg); return; } GNUNET_free (msg); if (GNUNET_SYSERR == result) return; /* check was aborted, session destroyed */ /* Blacklist denies to speak to this peer */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Discarding SYN message from `%s' due to denied blacklist check\n", GNUNET_i2s (peer)); kill_session (address->transport_name, session); }