Merge 0.9->trunk
authorMatthew Wild <mwild1@gmail.com>
Mon, 29 Apr 2013 00:36:04 +0100
changeset 5534 522e99b898a0
parent 5528 2539e60cc070 (current diff)
parent 5533 df3c78221f26 (diff)
child 5536 abb6c6e3d6dc
Merge 0.9->trunk
prosodyctl
--- a/core/moduleapi.lua	Sat Apr 27 18:03:19 2013 +0100
+++ b/core/moduleapi.lua	Mon Apr 29 00:36:04 2013 +0100
@@ -319,7 +319,13 @@
 end
 
 function api:provides(name, item)
-	if not item then item = self.environment; end
+	-- if not item then item = setmetatable({}, { __index = function(t,k) return rawget(self.environment, k); end }); end
+	if not item then
+		item = {}
+		for k,v in pairs(self.environment) do
+			if k ~= "module" then item[k] = v; end
+		end
+	end
 	if not item.name then
 		local item_name = self.name;
 		-- Strip a provider prefix to find the item name
@@ -329,6 +335,7 @@
 		end
 		item.name = item_name;
 	end
+	item._provided_by = self.name;
 	self:add_item(name.."-provider", item);
 end
 
--- a/net/server.lua	Sat Apr 27 18:03:19 2013 +0100
+++ b/net/server.lua	Mon Apr 29 00:36:04 2013 +0100
@@ -51,6 +51,7 @@
 		if use_luaevent then
 			local event_settings = {
 				ACCEPT_DELAY = settings.event_accept_retry_interval;
+				ACCEPT_QUEUE = settings.tcp_backlog;
 				CLEAR_DELAY = settings.event_clear_interval;
 				CONNECT_TIMEOUT = settings.connect_timeout;
 				DEBUG = settings.debug;
--- a/net/server_event.lua	Sat Apr 27 18:03:19 2013 +0100
+++ b/net/server_event.lua	Mon Apr 29 00:36:04 2013 +0100
@@ -23,6 +23,7 @@
 	HANDSHAKE_TIMEOUT     = 60,  -- timeout in seconds per handshake attempt
 	MAX_READ_LENGTH       = 1024 * 1024 * 1024 * 1024,  -- max bytes allowed to read from sockets
 	MAX_SEND_LENGTH       = 1024 * 1024 * 1024 * 1024,  -- max bytes size of write buffer (for writing on sockets)
+	ACCEPT_QUEUE          = 128,  -- might influence the length of the pending sockets queue
 	ACCEPT_DELAY          = 10,  -- seconds to wait until the next attempt of a full server to accept
 	READ_TIMEOUT          = 60 * 60 * 6,  -- timeout in seconds for read data from socket
 	WRITE_TIMEOUT         = 180,  -- timeout in seconds for write data on socket
--- a/net/server_select.lua	Sat Apr 27 18:03:19 2013 +0100
+++ b/net/server_select.lua	Mon Apr 29 00:36:04 2013 +0100
@@ -101,6 +101,7 @@
 
 local _selecttimeout
 local _sleeptime
+local _tcpbacklog
 
 local _starttime
 local _currenttime
@@ -139,6 +140,7 @@
 
 _selecttimeout = 1 -- timeout of socket.select
 _sleeptime = 0 -- time to wait at the end of every loop
+_tcpbacklog = 128 -- some kind of hint to the OS
 
 _maxsendlen = 51000 * 1024 -- max len of send buffer
 _maxreadlen = 25000 * 1024 -- max len of read buffer
@@ -211,7 +213,7 @@
 	handler.resume = function( )
 		if handler.paused then
 			if not socket then
-				socket = socket_bind( ip, serverport );
+				socket = socket_bind( ip, serverport, _tcpbacklog );
 				socket:settimeout( 0 )
 			end
 			_readlistlen = addsocket(_readlist, socket, _readlistlen)
@@ -720,7 +722,7 @@
 		return nil, err
 	end
 	addr = addr or "*"
-	local server, err = socket_bind( addr, port )
+	local server, err = socket_bind( addr, port, _tcpbacklog )
 	if err then
 		out_error( "server.lua, [", addr, "]:", port, ": ", err )
 		return nil, err
@@ -772,6 +774,7 @@
 	return {
 		select_timeout = _selecttimeout;
 		select_sleep_time = _sleeptime;
+		tcp_backlog = _tcpbacklog;
 		max_send_buffer_size = _maxsendlen;
 		max_receive_buffer_size = _maxreadlen;
 		select_idle_check_interval = _checkinterval;
@@ -792,6 +795,7 @@
 	_maxsendlen = tonumber( new.max_send_buffer_size ) or _maxsendlen
 	_maxreadlen = tonumber( new.max_receive_buffer_size ) or _maxreadlen
 	_checkinterval = tonumber( new.select_idle_check_interval ) or _checkinterval
+	_tcpbacklog = tonumber( new.tcp_backlog ) or _tcpbacklog
 	_sendtimeout = tonumber( new.send_timeout ) or _sendtimeout
 	_readtimeout = tonumber( new.read_timeout ) or _readtimeout
 	_maxselectlen = new.max_connections or _maxselectlen
--- a/plugins/mod_s2s/mod_s2s.lua	Sat Apr 27 18:03:19 2013 +0100
+++ b/plugins/mod_s2s/mod_s2s.lua	Mon Apr 29 00:36:04 2013 +0100
@@ -348,7 +348,7 @@
 			end
 		end
 
-		session:open_stream()
+		session:open_stream(session.to_host, session.from_host)
 		if session.version >= 1.0 then
 			local features = st.stanza("stream:features");
 			
@@ -448,7 +448,11 @@
 	local log = session.log or log;
 	if session.conn then
 		if session.notopen then
-			session:open_stream()
+			if session.direction == "incoming" then
+				session:open_stream(session.to_host, session.from_host);
+			else
+				session:open_stream(session.from_host, session.to_host);
+			end
 		end
 		if reason then -- nil == no err, initiated by us, false == initiated by remote
 			if type(reason) == "string" then -- assume stream error
@@ -496,8 +500,6 @@
 end
 
 function session_open_stream(session, from, to)
-	local from = from or session.from_host;
-	local to = to or session.to_host;
 	local attr = {
 		["xmlns:stream"] = 'http://etherx.jabber.org/streams',
 		xmlns = 'jabber:server',
@@ -506,8 +508,7 @@
 		id = session.streamid,
 		from = from, to = to,
 	}
-	local local_host = session.direction == "outgoing" and from or to;
-	if not local_host or (hosts[local_host] and hosts[local_host].modules.dialback) then
+	if not from or (hosts[from] and hosts[from].modules.dialback) then
 		attr["xmlns:db"] = 'jabber:server:dialback';
 	end
 
--- a/prosodyctl	Sat Apr 27 18:03:19 2013 +0100
+++ b/prosodyctl	Mon Apr 29 00:36:04 2013 +0100
@@ -654,7 +654,7 @@
 
 function cert_commands.config(arg)
 	if #arg >= 1 and arg[1] ~= "--help" then
-		local conf_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cnf";
+		local conf_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".cnf";
 		if ask_overwrite(conf_filename) then
 			return nil, conf_filename;
 		end
@@ -687,7 +687,7 @@
 
 function cert_commands.key(arg)
 	if #arg >= 1 and arg[1] ~= "--help" then
-		local key_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".key";
+		local key_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".key";
 		if ask_overwrite(key_filename) then
 			return nil, key_filename;
 		end
@@ -709,7 +709,7 @@
 
 function cert_commands.request(arg)
 	if #arg >= 1 and arg[1] ~= "--help" then
-		local req_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".req";
+		local req_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".req";
 		if ask_overwrite(req_filename) then
 			return nil, req_filename;
 		end
@@ -727,7 +727,7 @@
 
 function cert_commands.generate(arg)
 	if #arg >= 1 and arg[1] ~= "--help" then
-		local cert_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".crt";
+		local cert_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".crt";
 		if ask_overwrite(cert_filename) then
 			return nil, cert_filename;
 		end