-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 = time(NULL);
-
- connection_add(c);
-
- do_outgoing_connection(c);
+void handle_meta_connection_error(struct bufferevent *event, short what, void *data) {
+ connection_t *c = data;
+ logger(LOG_EMERG, _("handle_meta_connection_error() called: %d: %s"), what, strerror(errno));
+ terminate_connection(c, c->status.active);
+}
+
+void setup_outgoing_connection(outgoing_t *outgoing) {
+ connection_t *c;
+ node_t *n;
+
+ cp();
+
+ n = lookup_node(outgoing->name);
+
+ if(n)
+ if(n->connection) {
+ ifdebug(CONNECTIONS) logger(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(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 = time(NULL);
+
+ connection_add(c);
+
+ do_outgoing_connection(c);
+
+ event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c);
+ event_add(&c->inevent, NULL);
+ c->buffer = bufferevent_new(c->socket, handle_meta_read, handle_meta_write, handle_meta_connection_error, c);
+ if(!c->buffer) {
+ logger(LOG_EMERG, _("bufferevent_new() failed: %s"), strerror(errno));
+ abort();
+ }
+ bufferevent_disable(c->buffer, EV_READ);