-void setup_outgoing_connection(outgoing_t *outgoing)
-{
- connection_t *c;
- node_t *n;
-cp
- n = lookup_node(outgoing->name);
-
- if(n)
- if(n->connection)
- {
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_INFO, _("Already connected to %s"), outgoing->name);
- n->connection->outgoing = outgoing;
- return;
- }
-
- c = new_connection();
- c->name = xstrdup(outgoing->name);
- c->outcipher = myself->connection->outcipher;
- c->outdigest = myself->connection->outdigest;
- c->outmaclength = myself->connection->outmaclength;
- c->outcompression = myself->connection->outcompression;
-
- init_configuration(&c->config_tree);
- read_connection_config(c);
-
- outgoing->cfg = lookup_config(c->config_tree, "Address");
-
- if(!outgoing->cfg)
- {
- syslog(LOG_ERR, _("No address specified for %s"), c->name);
- free_connection(c);
- free(outgoing->name);
- free(outgoing);
- return;
- }
-
- c->outgoing = outgoing;
- c->last_ping_time = now;
-
- connection_add(c);
-
- do_outgoing_connection(c);
+void setup_outgoing_connection(outgoing_t *outgoing) {
+ connection_t *c;
+ node_t *n;
+
+ if(event_initialized(&outgoing->ev))
+ event_del(&outgoing->ev);
+
+ n = lookup_node(outgoing->name);
+
+ if(n)
+ if(n->connection) {
+ logger(DEBUG_CONNECTIONS, LOG_INFO, "Already connected to %s", outgoing->name);
+
+ n->connection->outgoing = outgoing;
+ return;
+ }
+
+ c = new_connection();
+ c->name = xstrdup(outgoing->name);
+ c->outcipher = myself->connection->outcipher;
+ c->outdigest = myself->connection->outdigest;
+ c->outmaclength = myself->connection->outmaclength;
+ c->outcompression = myself->connection->outcompression;
+
+ init_configuration(&c->config_tree);
+ read_connection_config(c);
+
+ outgoing->cfg = lookup_config(c->config_tree, "Address");
+
+ if(!outgoing->cfg) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "No address specified for %s", c->name);
+ free_connection(c);
+ return;
+ }
+
+ c->outgoing = outgoing;
+ c->last_ping_time = time(NULL);
+
+ connection_add(c);
+
+ if (do_outgoing_connection(c)) {
+ event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c);
+ event_set(&c->outevent, c->socket, EV_WRITE | EV_PERSIST, handle_meta_write, c);
+ event_add(&c->inevent, NULL);
+ }