Software /
code /
prosody
Comparison
plugins/mod_s2s/mod_s2s.lua @ 4818:3bda6fc02652
mod_s2s: Become a shared module (yay)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 04 May 2012 01:50:17 +0100 |
parent | 4814:474684c07a3a |
child | 4819:4fa47fc6f20c |
comparison
equal
deleted
inserted
replaced
4817:9cc1d3e49f19 | 4818:3bda6fc02652 |
---|---|
65 sendq[i] = nil; | 65 sendq[i] = nil; |
66 end | 66 end |
67 session.sendq = nil; | 67 session.sendq = nil; |
68 end | 68 end |
69 | 69 |
70 module:hook("route/remote", function (event) | 70 -- Handles stanzas to existing s2s sessions |
71 function route_to_existing_session(event) | |
71 local from_host, to_host, stanza = event.from_host, event.to_host, event.stanza; | 72 local from_host, to_host, stanza = event.from_host, event.to_host, event.stanza; |
72 if not hosts[from_host] then | 73 if not hosts[from_host] then |
73 log("warn", "Attempt to send stanza from %s - a host we don't serve", from_host); | 74 log("warn", "Attempt to send stanza from %s - a host we don't serve", from_host); |
74 return false; | 75 return false; |
75 end | 76 end |
99 host.sends2s(stanza); | 100 host.sends2s(stanza); |
100 host.log("debug", "stanza sent over "..host.type); | 101 host.log("debug", "stanza sent over "..host.type); |
101 return true; | 102 return true; |
102 end | 103 end |
103 end | 104 end |
104 end, 200); | 105 end |
105 | 106 |
106 module:hook("route/remote", function (event) | 107 -- Create a new outgoing session for a stanza |
108 function route_to_new_session(event) | |
107 local from_host, to_host, stanza = event.from_host, event.to_host, event.stanza; | 109 local from_host, to_host, stanza = event.from_host, event.to_host, event.stanza; |
108 log("debug", "opening a new outgoing connection for this stanza"); | 110 log("debug", "opening a new outgoing connection for this stanza"); |
109 local host_session = s2s_new_outgoing(from_host, to_host); | 111 local host_session = s2s_new_outgoing(from_host, to_host); |
110 | 112 |
111 -- Store in buffer | 113 -- Store in buffer |
117 log("warn", "Connection to %s failed already, destroying session...", to_host); | 119 log("warn", "Connection to %s failed already, destroying session...", to_host); |
118 s2s_destroy_session(host_session, "Connection failed"); | 120 s2s_destroy_session(host_session, "Connection failed"); |
119 return false; | 121 return false; |
120 end | 122 end |
121 return true; | 123 return true; |
122 end, 100); | 124 end |
125 | |
126 function module.add_host(module) | |
127 if module:get_option_boolean("disallow_s2s", false) then | |
128 return nil, "This host has disallow_s2s set"; | |
129 end | |
130 module:hook("route/remote", route_to_existing_session, 200); | |
131 module:hook("route/remote", route_to_new_session, 100); | |
132 end | |
123 | 133 |
124 --- Helper to check that a session peer's certificate is valid | 134 --- Helper to check that a session peer's certificate is valid |
125 local function check_cert_status(session) | 135 local function check_cert_status(session) |
126 local conn = session.conn:socket() | 136 local conn = session.conn:socket() |
127 local cert | 137 local cert |