Software / code / prosody
Comparison
core/s2smanager.lua @ 6779:6236668da30a
core.*: Remove use of module() function
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 21 Feb 2015 10:42:19 +0100 |
| parent | 6692:93eefa92527d |
| child | 7452:d916703d5e18 |
| child | 7947:24170d74b00b |
comparison
equal
deleted
inserted
replaced
| 6778:4009ae66e0f0 | 6779:6236668da30a |
|---|---|
| 20 incoming_s2s = {}; | 20 incoming_s2s = {}; |
| 21 prosody.incoming_s2s = incoming_s2s; | 21 prosody.incoming_s2s = incoming_s2s; |
| 22 local incoming_s2s = incoming_s2s; | 22 local incoming_s2s = incoming_s2s; |
| 23 local fire_event = prosody.events.fire_event; | 23 local fire_event = prosody.events.fire_event; |
| 24 | 24 |
| 25 module "s2smanager" | 25 local _ENV = nil; |
| 26 | 26 |
| 27 function new_incoming(conn) | 27 local function new_incoming(conn) |
| 28 local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming", hosts = {} }; | 28 local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming", hosts = {} }; |
| 29 session.log = logger_init("s2sin"..tostring(session):match("[a-f0-9]+$")); | 29 session.log = logger_init("s2sin"..tostring(session):match("[a-f0-9]+$")); |
| 30 incoming_s2s[session] = true; | 30 incoming_s2s[session] = true; |
| 31 return session; | 31 return session; |
| 32 end | 32 end |
| 33 | 33 |
| 34 function new_outgoing(from_host, to_host) | 34 local function new_outgoing(from_host, to_host) |
| 35 local host_session = { to_host = to_host, from_host = from_host, host = from_host, | 35 local host_session = { to_host = to_host, from_host = from_host, host = from_host, |
| 36 notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; | 36 notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; |
| 37 hosts[from_host].s2sout[to_host] = host_session; | 37 hosts[from_host].s2sout[to_host] = host_session; |
| 38 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); | 38 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); |
| 39 host_session.log = logger_init(conn_name); | 39 host_session.log = logger_init(conn_name); |
| 50 session.log("debug", "Attempt to close already-closed session"); | 50 session.log("debug", "Attempt to close already-closed session"); |
| 51 end; | 51 end; |
| 52 filter = function (type, data) return data; end; --luacheck: ignore 212/type | 52 filter = function (type, data) return data; end; --luacheck: ignore 212/type |
| 53 }; resting_session.__index = resting_session; | 53 }; resting_session.__index = resting_session; |
| 54 | 54 |
| 55 function retire_session(session, reason) | 55 local function retire_session(session, reason) |
| 56 local log = session.log or log; --luacheck: ignore 431/log | 56 local log = session.log or log; --luacheck: ignore 431/log |
| 57 for k in pairs(session) do | 57 for k in pairs(session) do |
| 58 if k ~= "log" and k ~= "id" and k ~= "conn" then | 58 if k ~= "log" and k ~= "id" and k ~= "conn" then |
| 59 session[k] = nil; | 59 session[k] = nil; |
| 60 end | 60 end |
| 66 function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end | 66 function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end |
| 67 session.sends2s = session.send; | 67 session.sends2s = session.send; |
| 68 return setmetatable(session, resting_session); | 68 return setmetatable(session, resting_session); |
| 69 end | 69 end |
| 70 | 70 |
| 71 function destroy_session(session, reason) | 71 local function destroy_session(session, reason) |
| 72 if session.destroyed then return; end | 72 if session.destroyed then return; end |
| 73 (session.log or log)("debug", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)..(reason and (": "..reason) or "")); | 73 (session.log or log)("debug", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)..(reason and (": "..reason) or "")); |
| 74 | 74 |
| 75 if session.direction == "outgoing" then | 75 if session.direction == "outgoing" then |
| 76 hosts[session.from_host].s2sout[session.to_host] = nil; | 76 hosts[session.from_host].s2sout[session.to_host] = nil; |
| 94 | 94 |
| 95 retire_session(session, reason); -- Clean session until it is GC'd | 95 retire_session(session, reason); -- Clean session until it is GC'd |
| 96 return true; | 96 return true; |
| 97 end | 97 end |
| 98 | 98 |
| 99 return _M; | 99 return { |
| 100 incoming_s2s = incoming_s2s; | |
| 101 new_incoming = new_incoming; | |
| 102 new_outgoing = new_outgoing; | |
| 103 retire_session = retire_session; | |
| 104 destroy_session = destroy_session; | |
| 105 }; |