+bool do_outgoing_connection(outgoing_t *outgoing) {
+ const sockaddr_t *sa;
+ struct addrinfo *proxyai = NULL;
+ int result;
+
+begin:
+ sa = get_recent_address(outgoing->node->address_cache);
+
+ if(!sa) {
+ logger(DEBUG_CONNECTIONS, LOG_ERR, "Could not set up a meta connection to %s", outgoing->node->name);
+ retry_outgoing(outgoing);
+ return false;
+ }
+
+ connection_t *c = new_connection();
+ c->outgoing = outgoing;
+ memcpy(&c->address, sa, SALEN(sa->sa));
+ c->hostname = sockaddr2hostname(&c->address);
+
+ logger(DEBUG_CONNECTIONS, LOG_INFO, "Trying to connect to %s (%s)", outgoing->node->name, c->hostname);
+
+ if(!proxytype) {
+ c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
+ configure_tcp(c);
+ } else if(proxytype == PROXY_EXEC) {
+ do_outgoing_pipe(c, proxyhost);
+ } else {
+ proxyai = str2addrinfo(proxyhost, proxyport, SOCK_STREAM);
+
+ if(!proxyai) {
+ free_connection(c);
+ goto begin;
+ }
+
+ logger(DEBUG_CONNECTIONS, LOG_INFO, "Using proxy at %s port %s", proxyhost, proxyport);
+ c->socket = socket(proxyai->ai_family, SOCK_STREAM, IPPROTO_TCP);
+ configure_tcp(c);
+ }
+
+ if(c->socket == -1) {
+ logger(DEBUG_CONNECTIONS, LOG_ERR, "Creating socket for %s failed: %s", c->hostname, sockstrerror(sockerrno));
+ free_connection(c);