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 host_session = { |
30 local host_session = sessionlib.new("s2sin"); |
30 conn = conn, |
31 sessionlib.set_id(host_session); |
31 type = "s2sin_unauthed", |
32 sessionlib.set_logger(host_session); |
32 direction = "incoming", |
33 sessionlib.set_conn(host_session, conn); |
33 hosts = {}, |
34 host_session.direction = "incoming"; |
34 }; |
35 host_session.session.hosts = {}; |
35 host_session.log = logger_init("s2sin"..tostring(host_session):match("[a-f0-9]+$")); |
|
36 incoming_s2s[host_session] = true; |
36 incoming_s2s[host_session] = true; |
37 return host_session; |
37 return host_session; |
38 end |
38 end |
39 |
39 |
40 local function new_outgoing(from_host, to_host) |
40 local function new_outgoing(from_host, to_host) |
41 local host_session = { |
41 local host_session = sessionlib.new("s2sout"); |
42 to_host = to_host, |
42 sessionlib.set_id(host_session); |
43 from_host = from_host, |
43 sessionlib.set_logger(host_session); |
44 host = from_host, |
44 host_session.to_host = to_host; |
45 notopen = true, |
45 host_session.from_host = from_host; |
46 type = "s2sout_unauthed", |
46 host_session.host = from_host; |
47 direction = "outgoing", |
47 host_session.notopen = true; |
48 }; |
48 host_session.direction = "outgoing"; |
49 hosts[from_host].s2sout[to_host] = host_session; |
49 hosts[from_host].s2sout[to_host] = host_session; |
50 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); |
|
51 host_session.log = logger_init(conn_name); |
|
52 return host_session; |
50 return host_session; |
53 end |
51 end |
54 |
52 |
55 local resting_session = { -- Resting, not dead |
53 local resting_session = { -- Resting, not dead |
56 destroyed = true; |
54 destroyed = true; |