Changeset

1071:8f59b45fe6a7

mod_onions: Copy the code to find the bit module from mod_websockets.
author Thijs Alkemade <me@thijsalkema.de>
date Sat, 15 Jun 2013 12:48:56 +0200 (2013-06-15)
parents 1070:dee31eeae7ae
children 1072:4dbdb1b465e8
files mod_onions/mod_onions.lua
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_onions/mod_onions.lua	Fri Jun 14 20:29:15 2013 +0200
+++ b/mod_onions/mod_onions.lua	Sat Jun 15 12:48:56 2013 +0200
@@ -1,9 +1,21 @@
 local wrapclient = require "net.server".wrapclient;
 local s2s_new_outgoing = require "core.s2smanager".new_outgoing;
 local initialize_filters = require "util.filters".initialize;
-local bit = require "bit32";
 local st = require "util.stanza";
+
 local portmanager = require "core.portmanager";
+
+local softreq = require "util.dependencies".softreq;
+
+local bit;
+pcall(function() bit = require"bit"; end);
+bit = bit or softreq"bit32"
+if not bit then module:log("error", "No bit module found. Either LuaJIT 2, lua-bitop or Lua 5.2 is required"); end
+
+local band = bit.band;
+local rshift = bit.rshift;
+local lshift = bit.lshift;
+
 local byte = string.byte;
 local c = string.char;
 
@@ -51,7 +63,7 @@
 		local ip2 = byte(data, 6);
 		local ip3 = byte(data, 7);
 		local ip4 = byte(data, 8);
-		local port = bit.band(byte(data, 9), bit.lshift(byte(data, 10), 8));
+		local port = band(byte(data, 9), lshift(byte(data, 10), 8));
 		module:log("debug", "Should connect to: "..ip1.."."..ip2.."."..ip3.."."..ip4..":"..port);
 
 		if not (ip1 == 0 and ip2 == 0 and ip3 == 0 and ip4 == 0 and port == 0) then
@@ -125,7 +137,7 @@
 
 	-- version 5, connect, (reserved), type: domainname, (length, hostname), port
 	conn:send(c(5) .. c(1) .. c(0) .. c(3) .. c(#session.socks5_to) .. session.socks5_to);
-	conn:send(c(bit.rshift(session.socks5_port, 8)) .. c(bit.band(session.socks5_port, 0xff)));
+	conn:send(c(rshift(session.socks5_port, 8)) .. c(band(session.socks5_port, 0xff)));
 
 	session.socks5_handler = socks5_connect_sent;
 end