Comparison

mod_onions/mod_onions.lua @ 1343:7dbde05b48a9

all the things: Remove trailing whitespace
author Florian Zeitz <florob@babelmonkeys.de>
date Tue, 11 Mar 2014 18:44:01 +0100
parent 1299:a7d6c6d2c7b5
child 1467:f10a3a5ba28f
comparison
equal deleted inserted replaced
1342:0ae065453dc9 1343:7dbde05b48a9
29 -- The socks5listener handles connection while still connecting to the proxy, 29 -- The socks5listener handles connection while still connecting to the proxy,
30 -- then it hands them over to the normal listener (in mod_s2s) 30 -- then it hands them over to the normal listener (in mod_s2s)
31 local socks5listener = { default_port = proxy_port, default_mode = "*a", default_interface = "*" }; 31 local socks5listener = { default_port = proxy_port, default_mode = "*a", default_interface = "*" };
32 32
33 local function socks5_connect_sent(conn, data) 33 local function socks5_connect_sent(conn, data)
34 34
35 local session = sessions[conn]; 35 local session = sessions[conn];
36 36
37 if #data < 5 then 37 if #data < 5 then
38 session.socks5_buffer = data; 38 session.socks5_buffer = data;
39 return; 39 return;
46 session:close(false); 46 session:close(false);
47 return; 47 return;
48 end 48 end
49 49
50 module:log("debug", "Succesfully connected to SOCKS5 proxy."); 50 module:log("debug", "Succesfully connected to SOCKS5 proxy.");
51 51
52 local response = byte(data, 4); 52 local response = byte(data, 4);
53 53
54 if response == 0x01 then 54 if response == 0x01 then
55 if #data < 10 then 55 if #data < 10 then
56 -- let's try again when we have enough 56 -- let's try again when we have enough
94 if t then 94 if t then
95 return conn:write(tostring(t)); 95 return conn:write(tostring(t));
96 end 96 end
97 end 97 end
98 end 98 end
99 99
100 session.open_stream = function () 100 session.open_stream = function ()
101 session.sends2s(st.stanza("stream:stream", { 101 session.sends2s(st.stanza("stream:stream", {
102 xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', 102 xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback',
103 ["xmlns:stream"]='http://etherx.jabber.org/streams', 103 ["xmlns:stream"]='http://etherx.jabber.org/streams',
104 from=session.from_host, to=session.to_host, version='1.0', ["xml:lang"]='en'}):top_tag()); 104 from=session.from_host, to=session.to_host, version='1.0', ["xml:lang"]='en'}):top_tag());
105 end 105 end
106 106
107 conn.setlistener(conn, listener); 107 conn.setlistener(conn, listener);
108 108
109 listener.register_outgoing(conn, session); 109 listener.register_outgoing(conn, session);
110 110
111 listener.onconnect(conn); 111 listener.onconnect(conn);
145 function socks5listener.onconnect(conn) 145 function socks5listener.onconnect(conn)
146 module:log("debug", "Connected to SOCKS5 proxy, sending SOCKS5 handshake."); 146 module:log("debug", "Connected to SOCKS5 proxy, sending SOCKS5 handshake.");
147 147
148 -- Socks version 5, 1 method, no auth 148 -- Socks version 5, 1 method, no auth
149 conn:write(c(5) .. c(1) .. c(0)); 149 conn:write(c(5) .. c(1) .. c(0));
150 150
151 sessions[conn].socks5_handler = socks5_handshake_sent; 151 sessions[conn].socks5_handler = socks5_handshake_sent;
152 end 152 end
153 153
154 function socks5listener.register_outgoing(conn, session) 154 function socks5listener.register_outgoing(conn, session)
155 session.direction = "outgoing"; 155 session.direction = "outgoing";
171 session.socks5_handler(conn, data); 171 session.socks5_handler(conn, data);
172 end 172 end
173 end 173 end
174 174
175 local function connect_socks5(host_session, connect_host, connect_port) 175 local function connect_socks5(host_session, connect_host, connect_port)
176 176
177 local conn, handler = socket.tcp(); 177 local conn, handler = socket.tcp();
178 178
179 module:log("debug", "Connecting to " .. connect_host .. ":" .. connect_port); 179 module:log("debug", "Connecting to " .. connect_host .. ":" .. connect_port);
180 180
181 -- this is not necessarily the same as .to_host (it can be that this is a SRV record) 181 -- this is not necessarily the same as .to_host (it can be that this is a SRV record)