+
+ goto begin;
+ }
+
+ /* Now that there is a working socket, fill in the rest and register this connection. */
+
+ c->status.connecting = true;
+ c->status.initiator = true;
+ c->name = xstrdup(outgoing->node->name);
+ c->last_ping_time = mesh->loop.now.tv_sec;
+
+ connection_add(mesh, c);
+
+ io_add(&mesh->loop, &c->io, handle_meta_io, c, c->socket, IO_READ | IO_WRITE);
+}
+
+void reset_outgoing(outgoing_t *outgoing) {
+ if(outgoing->ai) {
+ if(outgoing->state == OUTGOING_RECENT || outgoing->state == OUTGOING_KNOWN) {
+ free_known_addresses(outgoing->ai);
+ } else {
+ freeaddrinfo(outgoing->ai);
+ }
+ }
+
+ outgoing->ai = NULL;
+ outgoing->aip = NULL;
+ outgoing->state = OUTGOING_START;
+}
+
+void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
+ timeout_del(&mesh->loop, &outgoing->ev);
+
+ if(outgoing->node->connection) {
+ logger(mesh, MESHLINK_INFO, "Already connected to %s", outgoing->node->name);
+
+ outgoing->node->connection->outgoing = outgoing;