+ if(flags & IO_WRITE) {
+ handle_meta_write(c);
+ } else {
+ handle_meta_connection_data(c);
+ }
+}
+
+bool do_outgoing_connection(outgoing_t *outgoing) {
+ const sockaddr_t *sa;
+ struct addrinfo *proxyai = NULL;
+ int result;
+
+begin:
+ sa = get_recent_address(outgoing->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;
+ c->address = *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);
+ }