-int ack_h(connection_t *c)
-{
- char myaddress[MAX_STRING_SIZE];
- char hisport[MAX_STRING_SIZE];
- char *hisaddress, *dummy;
- int weight;
- int options;
- node_t *n;
- connection_t *other;
- avl_node_t *node;
-cp
- if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %d %d", hisport, myaddress, &weight, &options) != 4)
- {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name, c->hostname);
- return -1;
- }
-
- /* Check if we already have a node_t for him */
-
- n = lookup_node(c->name);
-
- if(!n)
- {
- n = new_node();
- n->name = xstrdup(c->name);
- node_add(n);
- }
- else
- {
- if(n->connection)
- {
- /* Oh dear, we already have a connection to this node. */
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_DEBUG, _("Established a second connection with %s (%s), closing old connection"), n->name, n->hostname);
- terminate_connection(n->connection, 0);
- }
-
- /* FIXME: check if information in existing node matches that of the other end of this connection */
- }
-
- n->connection = c;
- c->node = n;
- c->options |= options;
-
- /* Create an edge_t for this connection */
-
- c->edge = new_edge();
-cp
- c->edge->from.node = myself;
-// c->edge->from.tcpaddress = str2sockaddr(address, port);
- c->edge->from.udpaddress = str2sockaddr(myaddress, myport);
- c->edge->to.node = n;
-// c->edge->to.tcpaddress = c->address;
- sockaddr2str(&c->address, &hisaddress, &dummy);
- c->edge->to.udpaddress = str2sockaddr(hisaddress, hisport);
- free(hisaddress);
- free(dummy);
- c->edge->weight = (weight + c->estimated_weight) / 2;
- c->edge->connection = c;
- c->edge->options = c->options;
-cp
- edge_add(c->edge);
-
- /* Activate this connection */
-
- c->allow_request = ALL;
- c->status.active = 1;
-
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection with %s (%s) activated"), c->name, c->hostname);
-
-cp
- /* Send him everything we know */
-
- send_everything(c);
-
- /* Notify others of this connection */
-
- for(node = connection_tree->head; node; node = node->next)
- {
- other = (connection_t *)node->data;
-
- if(other->status.active && other != c)
- send_add_edge(other, c->edge);
- }
-
- /* Run MST and SSSP algorithms */
-
- graph();
-
- /* Succesful connection, reset timeout if this is an outgoing connection. */
-
- if(c->outgoing)
- c->outgoing->timeout = 0;
-cp
- return 0;