aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_compression.lua13
-rw-r--r--plugins/mod_console.lua4
-rw-r--r--plugins/mod_proxy65.lua43
3 files changed, 45 insertions, 15 deletions
diff --git a/plugins/mod_compression.lua b/plugins/mod_compression.lua
index 802e1822..8fdf9dcc 100644
--- a/plugins/mod_compression.lua
+++ b/plugins/mod_compression.lua
@@ -44,7 +44,7 @@ module:hook("s2s-stream-features",
end
);
--- S2Sout handling aka the client perspective in the S2S connection
+-- Hook to activate compression if remote server supports it.
module:hook_stanza(xmlns_stream, "features",
function (session, stanza)
if not session.compressed then
@@ -135,15 +135,14 @@ local function setup_decompression(session, inflate_stream)
end;
end
--- TODO Support compression on S2S level too.
module:add_handler({"s2sout_unauthed", "s2sout"}, "compressed", xmlns_compression_protocol,
function(session ,stanza)
session.log("debug", "Activating compression...")
-- create deflate and inflate streams
- deflate_stream = get_deflate_stream(session);
+ local deflate_stream = get_deflate_stream(session);
if not deflate_stream then return end
- inflate_stream = get_inflate_stream(session);
+ local inflate_stream = get_inflate_stream(session);
if not inflate_stream then return end
-- setup compression for session.w
@@ -161,7 +160,7 @@ module:add_handler({"s2sout_unauthed", "s2sout"}, "compressed", xmlns_compressio
local default_stream_attr = {xmlns = "jabber:server", ["xmlns:stream"] = "http://etherx.jabber.org/streams",
["xmlns:db"] = 'jabber:server:dialback', version = "1.0", to = session.to_host, from = session.from_host};
session.sends2s("<?xml version='1.0'?>");
- session.sends2s(st.stanza("stream:stream", default_stream_attr):top_tag());
+ session.sends2s(st.stanza("stream:stream", default_stream_attr):top_tag());
session.compressed = true;
end
);
@@ -181,10 +180,10 @@ module:add_handler({"c2s_unauthed", "c2s", "s2sin_unauthed", "s2sin"}, "compress
session.log("info", method.." compression selected.");
-- create deflate and inflate streams
- deflate_stream = get_deflate_stream(session);
+ local deflate_stream = get_deflate_stream(session);
if not deflate_stream then return end
- inflate_stream = get_inflate_stream(session);
+ local inflate_stream = get_inflate_stream(session);
if not inflate_stream then return end
(session.sends2s or session.send)(st.stanza("compressed", {xmlns=xmlns_compression_protocol}));
diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua
index 9962b3f6..5e6b6846 100644
--- a/plugins/mod_console.lua
+++ b/plugins/mod_console.lua
@@ -478,7 +478,7 @@ function def_env.s2s:show(match_jid)
for remotehost, session in pairs(host_session.s2sout) do
if (not match_jid) or remotehost:match(match_jid) or host:match(match_jid) then
count_out = count_out + 1;
- print(" "..host.." -> "..remotehost..(session.secure and " (encrypted)" or ""));
+ print(" "..host.." -> "..remotehost..(session.secure and " (encrypted)" or "")..(session.compressed and " (compressed)" or ""));
if session.sendq then
print(" There are "..#session.sendq.." queued outgoing stanzas for this connection");
end
@@ -515,7 +515,7 @@ function def_env.s2s:show(match_jid)
-- Pft! is what I say to list comprehensions
or (session.hosts and #array.collect(keys(session.hosts)):filter(subhost_filter)>0)) then
count_in = count_in + 1;
- print(" "..host.." <- "..(session.from_host or "(unknown)")..(session.secure and " (encrypted)" or ""));
+ print(" "..host.." <- "..(session.from_host or "(unknown)")..(session.secure and " (encrypted)" or "")..(session.compressed and " (compressed)" or ""));
if session.type == "s2sin_unauthed" then
print(" Connection not yet authenticated");
end
diff --git a/plugins/mod_proxy65.lua b/plugins/mod_proxy65.lua
index 504cfc0c..af618c01 100644
--- a/plugins/mod_proxy65.lua
+++ b/plugins/mod_proxy65.lua
@@ -55,8 +55,12 @@ function connlistener.onincoming(conn, data)
if session.setup then
if session.sha ~= nil and transfers[session.sha] ~= nil then
local sha = session.sha;
- if transfers[sha].activated == true and transfers[sha].initiator == conn and transfers[sha].target ~= nil then
- transfers[sha].target:write(data);
+ if transfers[sha].activated == true and transfers[sha].target ~= nil then
+ if transfers[sha].initiator == conn then
+ transfers[sha].target:write(data);
+ else
+ transfers[sha].initiator:write(data);
+ end
return;
end
end
@@ -67,7 +71,7 @@ function connlistener.onincoming(conn, data)
data:sub(4):byte() == 0x03 and -- ATYP must be 3
data:sub(5):byte() == 40 and -- SHA1 HASH length must be 40 (0x28)
data:sub(-2):byte() == 0x00 and -- PORT must be 0, size 2 byte
- data:sub(-1):byte() == 0x00
+ data:sub(-1):byte() == 0x00
then
local sha = data:sub(6, 45); -- second param is not count! it's the ending index (included!)
if transfers[sha] == nil then
@@ -80,10 +84,13 @@ function connlistener.onincoming(conn, data)
transfers[sha].initiator = conn;
session.sha = sha;
module:log("debug", "initiator connected ... ");
+ throttle_sending(conn, transfers[sha].target);
+ throttle_sending(transfers[sha].target, conn);
end
conn:write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte)
+ conn:lock_read(true)
else
- log:module("warn", "Neither data transfer nor initial connect of a participator of a transfer.")
+ module:log("warn", "Neither data transfer nor initial connect of a participator of a transfer.")
conn.close();
end
else
@@ -237,6 +244,8 @@ function handle_to_domain(origin, stanza)
elseif(transfers[sha] ~= nil and transfers[sha].initiator ~= nil and transfers[sha].target ~= nil) then
origin.send(reply);
transfers[sha].activated = true;
+ transfers[sha].target:lock_read(false);
+ transfers[sha].initiator:lock_read(false);
end
else
module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to));
@@ -247,9 +256,31 @@ function handle_to_domain(origin, stanza)
end
if not connlisteners.register(module.host .. ':proxy65', connlistener) then
- error("mod_proxy65: Could not establish a connection listener. Check your configuration please.");
- error(" one possible cause for this would be that two proxy65 components share the same port.");
+ module:log("error", "mod_proxy65: Could not establish a connection listener. Check your configuration please.");
+ module:log("error", "Possibly two proxy65 components are configured to share the same port.");
end
connlisteners.start(module.host .. ':proxy65');
component = componentmanager.register_component(host, handle_to_domain);
+local sender_lock_threshold = 4096;
+function throttle_sending(sender, receiver)
+ sender:pattern(sender_lock_threshold);
+ local sender_locked;
+ local _sendbuffer = receiver.sendbuffer;
+ function receiver.sendbuffer()
+ _sendbuffer();
+ if sender_locked and receiver.bufferlen() < sender_lock_threshold then
+ sender:lock_read(false); -- Unlock now
+ sender_locked = nil;
+ end
+ end
+
+ local _readbuffer = sender.readbuffer;
+ function sender.readbuffer()
+ _readbuffer();
+ if not sender_locked and receiver.bufferlen() >= sender_lock_threshold then
+ sender_locked = true;
+ sender:lock_read(true);
+ end
+ end
+end