/** * Function called by transport telling us that a peer * disconnected. * * @param cls closure * @param peer the peer that disconnected */ static void handle_transport_notify_disconnect (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; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected from us; received notification from transport.\n", GNUNET_i2s (peer)); n = find_neighbour (peer); if (NULL == n) { GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s not found\n", GNUNET_i2s (peer)); return; } free_neighbour (n); }
/** * Wrapper around #free_neighbour(). * * @param cls unused * @param key peer identity * @param value the `struct Neighbour` to free * @return #GNUNET_OK (continue to iterate) */ static int free_neighbour_helper (void *cls, const struct GNUNET_PeerIdentity * key, void *value) { struct Neighbour *n = value; /* transport should have 'disconnected' all neighbours... */ GNUNET_break (0); free_neighbour (n); return GNUNET_OK; }
void send_packets_neighbour_ip6(neighbour *n){ long long current_time; long long delay = 1000; //Send or resend packets every 1 second current_time = current_timestamp(); if(current_time - n->last_response > n->holdtime){ printf("Neighbour is inactive removing him.\n"); free_neighbour(n,"holding time expired"); return; } if((!n->send_next_packet) && current_time - n->last_packet_sent < delay){ return; } n->send_next_packet = false; if(linkedlist_isempty(&n->packet_queue)){ if(n->last_ack_sent != n->pending_ack && n->pending_ack != -1){ int length = sizeof(struct eigrphdr); packetv4_param *packet = create_empty_packet(OPCODE_HELLO,0, n->sin); n->last_ack_sent = n->pending_ack; create_eigrp_header(packet, length, OPCODE_HELLO, n->proc->proccess_id, 0, n->pending_ack, 0); //Record packets sent n->proc->stats.packets_sent[packet->opcode]++; if(n->pending_ack != 0)n->proc->stats.acks_sent++; send_ip4_packet(packet,n->interface->socket4); n->last_packet_sent = current_time; free(packet); } }else{ packetv4_param *packet = linkedlist_peekfirst(&n->packet_queue); if(packet->seq_num == 0){ int seq_num = n->proc->seq_num++; //increase the seq_num by 1 packet->seq_num = seq_num; //assign the seq to the struct so it be retrived later to check for ack //create_eigrp_header(packet, packet->buffer_len, packet->opcode, n->proc->proccess_id, packet->seq_num , n->pending_ack, packet->flags); //n->last_ack_sent = n->pending_ack; //Save the seq num for the neighbour state change if( flags_are_set(packet->flags, FLAG_INIT) ){ n->init_seq = seq_num; } } int ack = n->pending_ack; if(ack == -1) ack = 0; create_eigrp_header(packet, packet->buffer_len, packet->opcode, n->proc->proccess_id, packet->seq_num , ack, packet->flags); n->last_ack_sent = n->pending_ack; //Record packets sent n->proc->stats.packets_sent[packet->opcode]++; if(n->pending_ack != 0)n->proc->stats.acks_sent++; send_ip4_packet(packet,n->interface->socket4); n->last_packet_sent = current_time; } }