- /* Okay, before we active the connection, we check if there is another entry
- in the connection list with the same name. If so, it presumably is an
- old connection that has timed out but we don't know it yet.
- */
+ if(sscanf(c->buffer, "%*d %hd %d", &port, &weight) != 2)
+ {
+ 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);
+ n->address = c->address;
+ n->hostname = xstrdup(c->hostname);
+ n->port = port;
+
+ /* FIXME: Also check if no other tinc daemon uses the same IP and port for UDP traffic */
+
+ node_add(n);
+ }
+ else
+ {
+ if(n->connection)
+ {
+ /* Oh dear, we already have a connection to this node. */
+ 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;
+
+ /* Check some options
+
+ if((cfg = get_config_val(c->config, config_indirectdata)))
+ {
+ if(cfg->data.val == stupid_true)
+ c->options |= OPTION_INDIRECT;
+ }