Software / code / prosody
Comparison
core/s2smanager.lua @ 10061:5c71693c8345
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 08 Jul 2019 02:44:32 +0200 |
| parent | 9938:4e8ba156738b |
| child | 10102:77a21eef243b |
comparison
equal
deleted
inserted
replaced
| 10060:7a36b7ac309b | 10061:5c71693c8345 |
|---|---|
| 11 local hosts = prosody.hosts; | 11 local hosts = prosody.hosts; |
| 12 local tostring, pairs, setmetatable | 12 local tostring, pairs, setmetatable |
| 13 = tostring, pairs, setmetatable; | 13 = tostring, pairs, setmetatable; |
| 14 | 14 |
| 15 local logger_init = require "util.logger".init; | 15 local logger_init = require "util.logger".init; |
| 16 local sessionlib = require "util.session"; | |
| 16 | 17 |
| 17 local log = logger_init("s2smanager"); | 18 local log = logger_init("s2smanager"); |
| 18 | 19 |
| 19 local prosody = _G.prosody; | 20 local prosody = _G.prosody; |
| 20 local incoming_s2s = {}; | 21 local incoming_s2s = {}; |
| 24 | 25 |
| 25 local _ENV = nil; | 26 local _ENV = nil; |
| 26 -- luacheck: std none | 27 -- luacheck: std none |
| 27 | 28 |
| 28 local function new_incoming(conn) | 29 local function new_incoming(conn) |
| 29 local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming", hosts = {} }; | 30 local host_session = sessionlib.new("s2sin"); |
| 30 session.log = logger_init("s2sin"..tostring(session):match("[a-f0-9]+$")); | 31 sessionlib.set_id(host_session); |
| 31 incoming_s2s[session] = true; | 32 sessionlib.set_logger(host_session); |
| 32 return session; | 33 sessionlib.set_conn(host_session, conn); |
| 34 host_session.direction = "incoming"; | |
| 35 host_session.hosts = {}; | |
| 36 incoming_s2s[host_session] = true; | |
| 37 return host_session; | |
| 33 end | 38 end |
| 34 | 39 |
| 35 local function new_outgoing(from_host, to_host) | 40 local function new_outgoing(from_host, to_host) |
| 36 local host_session = { to_host = to_host, from_host = from_host, host = from_host, | 41 local host_session = sessionlib.new("s2sout"); |
| 37 notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; | 42 sessionlib.set_id(host_session); |
| 43 sessionlib.set_logger(host_session); | |
| 44 host_session.to_host = to_host; | |
| 45 host_session.from_host = from_host; | |
| 46 host_session.host = from_host; | |
| 47 host_session.notopen = true; | |
| 48 host_session.direction = "outgoing"; | |
| 38 hosts[from_host].s2sout[to_host] = host_session; | 49 hosts[from_host].s2sout[to_host] = host_session; |
| 39 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); | |
| 40 host_session.log = logger_init(conn_name); | |
| 41 return host_session; | 50 return host_session; |
| 42 end | 51 end |
| 43 | 52 |
| 44 local resting_session = { -- Resting, not dead | 53 local resting_session = { -- Resting, not dead |
| 45 destroyed = true; | 54 destroyed = true; |
| 47 open_stream = function (session) | 56 open_stream = function (session) |
| 48 session.log("debug", "Attempt to open stream on resting session"); | 57 session.log("debug", "Attempt to open stream on resting session"); |
| 49 end; | 58 end; |
| 50 close = function (session) | 59 close = function (session) |
| 51 session.log("debug", "Attempt to close already-closed session"); | 60 session.log("debug", "Attempt to close already-closed session"); |
| 61 end; | |
| 62 reset_stream = function (session) | |
| 63 session.log("debug", "Attempt to reset stream of already-closed session"); | |
| 52 end; | 64 end; |
| 53 filter = function (type, data) return data; end; --luacheck: ignore 212/type | 65 filter = function (type, data) return data; end; --luacheck: ignore 212/type |
| 54 }; resting_session.__index = resting_session; | 66 }; resting_session.__index = resting_session; |
| 55 | 67 |
| 56 local function retire_session(session, reason) | 68 local function retire_session(session, reason) |