aboutsummaryrefslogtreecommitdiffstats
path: root/net/connect.lua
diff options
context:
space:
mode:
Diffstat (limited to 'net/connect.lua')
-rw-r--r--net/connect.lua40
1 files changed, 28 insertions, 12 deletions
diff --git a/net/connect.lua b/net/connect.lua
index b812ffcd..2d929087 100644
--- a/net/connect.lua
+++ b/net/connect.lua
@@ -2,6 +2,17 @@ local server = require "net.server";
local log = require "util.logger".init("net.connect");
local new_id = require "util.id".short;
+-- TODO #1246 Happy Eyeballs
+-- FIXME RFC 6724
+-- FIXME Error propagation from resolvers doesn't work
+-- FIXME #1428 Reuse DNS resolver object between service and basic resolver
+-- FIXME #1429 Close DNS resolver object when done
+
+local default_connector_options = {
+ use_ipv4 = true;
+ use_ipv6 = true;
+};
+
local pending_connection_methods = {};
local pending_connection_mt = {
__name = "pending_connection";
@@ -38,7 +49,7 @@ local function attempt_connection(p)
p:log("debug", "Next target to try is %s:%d", ip, port);
local conn, err = server.addclient(ip, port, pending_connection_listeners, p.options.pattern or "*a", p.options.sslctx, conn_type, extra);
if not conn then
- log("debug", "Connection attempt failed immediately: %s", tostring(err));
+ log("debug", "Connection attempt failed immediately: %s", err);
p.last_error = err or "unknown reason";
return attempt_connection(p);
end
@@ -71,19 +82,24 @@ function pending_connection_listeners.ondisconnect(conn, reason)
attempt_connection(p);
end
-local function connect(target_resolver, listeners, options, data)
- local p = setmetatable({
- id = new_id();
- target_resolver = target_resolver;
- listeners = assert(listeners);
- options = options or {};
- data = data;
- }, pending_connection_mt);
+local function new_connector(connector_options)
+ local function connect(target_resolver, listeners, options, data)
+ local p = setmetatable({
+ id = new_id();
+ target_resolver = target_resolver;
+ listeners = assert(listeners);
+ options = options or {};
+ data = data;
+ connector_options = connector_options or default_connector_options;
+ }, pending_connection_mt);
- p:log("debug", "Starting connection process");
- attempt_connection(p);
+ p:log("debug", "Starting connection process");
+ attempt_connection(p);
+ end
+ return connect;
end
return {
- connect = connect;
+ connect = new_connector(default_connector_options);
+ new_connector = new_connector;
};