# HG changeset patch # User Matthew Wild # Date 1228505041 0 # Node ID 099d8a102deb96e57be78a563836ad90d9536f56 # Parent 04ee161d936bf747a3e30526e625e26ed671fae5 Add TLS socket to readlist before handshake starts, fixes major slow-down on TLS connections diff -r 04ee161d936b -r 099d8a102deb core/presencemanager.lua --- a/core/presencemanager.lua Fri Dec 05 19:22:34 2008 +0000 +++ b/core/presencemanager.lua Fri Dec 05 19:24:01 2008 +0000 @@ -21,6 +21,7 @@ local log = require "util.logger".init("presencemanager") +local tostring = tostring; local require = require; local pairs, ipairs = pairs, ipairs; local t_concat = table.concat; @@ -121,6 +122,14 @@ else log("error", "presence recieved from client with no roster"); end + + if origin.conntimetotal then + local session = origin; + origin.log("BLAH", "***********\n\n\n\n\n\n****************"); + origin.send(st.stanza("message", { from = session.host, to=session.full_jid, type = "normal" }):body("Your login took "..tostring(session.conntimetotal).." seconds")); + origin.conntimetotal = nil; + end + end function send_presence_of_available_resources(user, host, jid, recipient_session, core_route_stanza) diff -r 04ee161d936b -r 099d8a102deb core/sessionmanager.lua --- a/core/sessionmanager.lua Fri Dec 05 19:22:34 2008 +0000 +++ b/core/sessionmanager.lua Fri Dec 05 19:24:01 2008 +0000 @@ -35,6 +35,8 @@ local rm_load_roster = require "core.rostermanager".load_roster; local config_get = require "core.configmanager".get; +local gettime = require "socket".gettime; + local st = require "util.stanza"; local newproxy = newproxy; @@ -45,7 +47,7 @@ local open_sessions = 0; function new_session(conn) - local session = { conn = conn, priority = 0, type = "c2s_unauthed" }; + local session = { conn = conn, priority = 0, type = "c2s_unauthed", conntime = gettime() }; if true then session.trace = newproxy(true); getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; print("Session got collected, now "..open_sessions.." sessions are allocated") end; @@ -109,6 +111,8 @@ if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end -- We don't support binding multiple resources + session.conntimetotal = gettime()-session.conntime; + resource = resource or uuid_generate(); --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing diff -r 04ee161d936b -r 099d8a102deb net/server.lua --- a/net/server.lua Fri Dec 05 19:22:34 2008 +0000 +++ b/net/server.lua Fri Dec 05 19:24:01 2008 +0000 @@ -504,13 +504,24 @@ handler.starttls = function (now) if not now then out_put("server.lua: we need to do tls, but delaying until later"); handler.need_tls = true; return; end out_put( "server.lua: attempting to start tls on "..tostring(socket) ) + local oldsocket = socket; socket, err = ssl_wrap( socket, sslctx ) -- wrap socket out_put("sslwrapped socket is "..tostring(socket)); if err then out_put( "server.lua: ssl error: ", err ) return nil, nil, err -- fatal error end - socket:settimeout( 1 ) + socket:settimeout(0); + + -- Add the new socket to our system + socketlist[ socket ] = handler + readlen = readlen + 1 + readlist[ readlen ] = socket + + -- Remove traces of the old socket + readlen = removesocket( readlist, oldsocket, readlen ) + socketlist [ oldsocket ] = nil; + send = socket.send receive = socket.receive close = socket.close @@ -536,9 +547,6 @@ handler.receivedata = handler._receivedata -- when handshake is done, replace the handshake function with regular functions handler.dispatchdata = handler._dispatchdata handler.need_tls = nil - socketlist[ client ] = handler - readlen = readlen + 1 - readlist[ readlen ] = client return true; else out_put( "server.lua: error during ssl handshake: ", err ) diff -r 04ee161d936b -r 099d8a102deb net/xmppclient_listener.lua --- a/net/xmppclient_listener.lua Fri Dec 05 19:22:34 2008 +0000 +++ b/net/xmppclient_listener.lua Fri Dec 05 19:24:01 2008 +0000 @@ -113,7 +113,7 @@ if not session then session = sm_new_session(conn); sessions[conn] = session; - + -- Logging functions -- local mainlog, log = log; diff -r 04ee161d936b -r 099d8a102deb plugins/mod_console.lua --- a/plugins/mod_console.lua Fri Dec 05 19:22:34 2008 +0000 +++ b/plugins/mod_console.lua Fri Dec 05 19:24:01 2008 +0000 @@ -33,7 +33,7 @@ local w = conn.write; local session = { conn = conn; send = function (t) w(tostring(t)); end; - print = function (t) w("| "..tostring(t).."\n"); end; + print = function (t) w("| "..tostring(t).."\r\n"); end; disconnect = function () conn.close(); end; }; session.env = setmetatable({}, default_env_mt); diff -r 04ee161d936b -r 099d8a102deb plugins/mod_saslauth.lua --- a/plugins/mod_saslauth.lua Fri Dec 05 19:22:34 2008 +0000 +++ b/plugins/mod_saslauth.lua Fri Dec 05 19:24:01 2008 +0000 @@ -24,6 +24,8 @@ local jid local base64 = require "util.encodings".base64; +local gettime = require "socket".gettime; + local usermanager_validate_credentials = require "core.usermanager".validate_credentials; local t_concat, t_insert = table.concat, table.insert; local tostring = tostring; @@ -64,14 +66,14 @@ end end -local function password_callback(node, host, mechanism, raw_host) +local function password_callback(node, host, mechanism) local password = (datamanager.load(node, host, "accounts") or {}).password; -- FIXME handle hashed passwords local func = function(x) return x; end; if password then if mechanism == "PLAIN" then return func, password; elseif mechanism == "DIGEST-MD5" then - return func, md5(node..":"..raw_host..":"..password); + return func, md5(node..":"..host..":"..password); end end return func, nil; @@ -142,6 +144,8 @@ :tag("bind", { xmlns = xmlns_bind}) :tag("jid"):text(session.full_jid)); end + + session.log("******", "Connection took "..tostring(session.conntimetotal).." seconds"); end); module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session",