Software /
code /
prosody
Comparison
core/s2smanager.lua @ 621:cd2cab5400fc
Add support for dialback piggy-backing. Fixes #37. Thanks to CShadowRun for helping me test :)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 13 Dec 2008 17:43:52 +0000 |
parent | 615:4ae3e81513f3 |
child | 631:6957fe7b0313 |
comparison
equal
deleted
inserted
replaced
620:9f9f69d67edb | 621:cd2cab5400fc |
---|---|
45 | 45 |
46 local dialback_secret = sha256_hash(tostring{} .. math.random() .. socket.gettime(), true); | 46 local dialback_secret = sha256_hash(tostring{} .. math.random() .. socket.gettime(), true); |
47 | 47 |
48 local dns = require "net.dns"; | 48 local dns = require "net.dns"; |
49 | 49 |
50 incoming_s2s = {}; | |
51 local incoming_s2s = incoming_s2s; | |
52 | |
50 module "s2smanager" | 53 module "s2smanager" |
51 | 54 |
52 local function compare_srv_priorities(a,b) return a.priority < b.priority or a.weight < b.weight; end | 55 local function compare_srv_priorities(a,b) return a.priority < b.priority or a.weight < b.weight; end |
53 | 56 |
54 function send_to_host(from_host, to_host, data) | 57 function send_to_host(from_host, to_host, data) |
89 end | 92 end |
90 | 93 |
91 local open_sessions = 0; | 94 local open_sessions = 0; |
92 | 95 |
93 function new_incoming(conn) | 96 function new_incoming(conn) |
94 local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming" }; | 97 local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming", hosts = {} }; |
95 if true then | 98 if true then |
96 session.trace = newproxy(true); | 99 session.trace = newproxy(true); |
97 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; | 100 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; |
98 end | 101 end |
99 open_sessions = open_sessions + 1; | 102 open_sessions = open_sessions + 1; |
100 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); | 103 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); |
101 session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end | 104 session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end |
105 incoming_s2s[session] = true; | |
102 return session; | 106 return session; |
103 end | 107 end |
104 | 108 |
105 function new_outgoing(from_host, to_host) | 109 function new_outgoing(from_host, to_host) |
106 local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; | 110 local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; |
237 | 241 |
238 function verify_dialback(id, to, from, key) | 242 function verify_dialback(id, to, from, key) |
239 return key == generate_dialback(id, to, from); | 243 return key == generate_dialback(id, to, from); |
240 end | 244 end |
241 | 245 |
242 function make_authenticated(session) | 246 function make_authenticated(session, host) |
243 if session.type == "s2sout_unauthed" then | 247 if session.type == "s2sout_unauthed" then |
244 session.type = "s2sout"; | 248 session.type = "s2sout"; |
245 elseif session.type == "s2sin_unauthed" then | 249 elseif session.type == "s2sin_unauthed" then |
246 session.type = "s2sin"; | 250 session.type = "s2sin"; |
251 if host then | |
252 session.hosts[host].authed = true; | |
253 end | |
254 elseif session.type == "s2sin" and host then | |
255 session.hosts[host].authed = true; | |
247 else | 256 else |
248 return false; | 257 return false; |
249 end | 258 end |
250 session.log("info", "connection is now authenticated"); | 259 session.log("info", "connection is now authenticated"); |
251 | 260 |
282 | 291 |
283 -- FIXME: Flush sendq here/report errors to originators | 292 -- FIXME: Flush sendq here/report errors to originators |
284 | 293 |
285 if session.direction == "outgoing" then | 294 if session.direction == "outgoing" then |
286 hosts[session.from_host].s2sout[session.to_host] = nil; | 295 hosts[session.from_host].s2sout[session.to_host] = nil; |
296 elseif session.direction == "incoming" then | |
297 incoming_s2s[session] = nil; | |
287 end | 298 end |
288 | 299 |
289 for k in pairs(session) do | 300 for k in pairs(session) do |
290 if k ~= "trace" then | 301 if k ~= "trace" then |
291 session[k] = nil; | 302 session[k] = nil; |