-int ack_h(connection_t *c)
-{
- char address[MAX_STRING_SIZE];
- char port[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" "MAX_STRING" %d %d", hisport, address, port, &weight, &options) != 5)
- {
- 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(address, 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;
+bool ack_h(connection_t *c, char *request) {
+ char hisport[MAX_STRING_SIZE];
+ char *hisaddress;
+ int weight, mtu;
+ uint32_t options;
+ node_t *n;
+ bool choice;
+
+ if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &weight, &options) != 3) {
+ logger(LOG_ERR, "Got bad %s from %s (%s)", "ACK", c->name,
+ c->hostname);
+ return false;
+ }
+
+ /* 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. */
+ ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Established a second connection with %s (%s), closing old connection", n->connection->name, n->connection->hostname);
+
+ if(n->connection->outgoing) {
+ if(c->outgoing)
+ logger(LOG_WARNING, "Two outgoing connections to the same node!");
+ else
+ c->outgoing = n->connection->outgoing;
+
+ n->connection->outgoing = NULL;
+ }
+
+ terminate_connection(n->connection, false);
+ /* Run graph algorithm to purge key and make sure up/down scripts are rerun with new IP addresses and stuff */
+ graph();
+ }
+ }
+
+ n->connection = c;
+ c->node = n;
+ if(!(c->options & options & OPTION_PMTU_DISCOVERY)) {
+ c->options &= ~OPTION_PMTU_DISCOVERY;
+ options &= ~OPTION_PMTU_DISCOVERY;
+ }
+ c->options |= options;
+
+ if(get_config_int(lookup_config(c->config_tree, "PMTU"), &mtu) && mtu < n->mtu)
+ n->mtu = mtu;
+
+ if(get_config_int(lookup_config(myself->connection->config_tree, "PMTU"), &mtu) && mtu < n->mtu)
+ n->mtu = mtu;
+
+ if(get_config_bool(lookup_config(c->config_tree, "ClampMSS"), &choice)) {
+ if(choice)
+ c->options |= OPTION_CLAMP_MSS;
+ else
+ c->options &= ~OPTION_CLAMP_MSS;
+ }
+
+ /* Activate this connection */
+
+ c->allow_request = ALL;
+ c->status.active = true;
+
+ ifdebug(CONNECTIONS) logger(LOG_NOTICE, "Connection with %s (%s) activated", c->name,
+ c->hostname);
+
+ /* Send him everything we know */
+
+ send_everything(c);
+
+ /* Create an edge_t for this connection */
+
+ c->edge = new_edge();
+ c->edge->from = myself;
+ c->edge->to = n;
+ sockaddr2str(&c->address, &hisaddress, NULL);
+ c->edge->address = str2sockaddr(hisaddress, hisport);
+ free(hisaddress);
+ c->edge->weight = (weight + c->estimated_weight) / 2;
+ c->edge->connection = c;
+ c->edge->options = c->options;
+
+ edge_add(c->edge);
+
+ /* Notify everyone of the new edge */
+
+ if(tunnelserver)
+ send_add_edge(c, c->edge);
+ else
+ send_add_edge(broadcast, c->edge);
+
+ /* Run MST and SSSP algorithms */
+
+ graph();
+
+ return true;