Software /
code /
prosody
Annotate
net/server.lua @ 319:4a8a949c3870
Fix for putting TLS in stream:features for connections already using TLS. Thanks to albert for spotting.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 16 Nov 2008 00:29:15 +0000 |
parent | 127:93f3c6b94c75 |
child | 328:a1d25769970f |
rev | line source |
---|---|
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
1 --[[ |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
2 |
64 | 3 server.lua by blastbeat of the luadch project |
4 | |
5 re-used here under the MIT/X Consortium License | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
6 |
64 | 7 - this script contains the server loop of the program |
8 - other scripts can reg a server here | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
9 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
10 ]]-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
11 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
12 ----------------------------------// DECLARATION //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
13 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
14 --// constants //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
15 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
16 local STAT_UNIT = 1 / ( 1024 * 1024 ) -- mb |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
17 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
18 --// lua functions //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
19 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
20 local function use( what ) return _G[ what ] end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
21 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
22 local type = use "type" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
23 local pairs = use "pairs" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
24 local ipairs = use "ipairs" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
25 local tostring = use "tostring" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
26 local collectgarbage = use "collectgarbage" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
27 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
28 --// lua libs //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
29 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
30 local table = use "table" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
31 local coroutine = use "coroutine" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
32 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
33 --// lua lib methods //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
34 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
35 local table_concat = table.concat |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
36 local table_remove = table.remove |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
37 local string_sub = use'string'.sub |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
38 local coroutine_wrap = coroutine.wrap |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
39 local coroutine_yield = coroutine.yield |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
40 local print = print; |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
41 local out_put = function () end --print; |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
42 local out_error = print; |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
43 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
44 --// extern libs //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
45 |
98
3a2d327c4856
server.lua should degrade gracefully when LuaSec not present
Matthew Wild <mwild1@gmail.com>
parents:
74
diff
changeset
|
46 local luasec = select(2, pcall(require, "ssl")) |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
47 local luasocket = require "socket" |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
48 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
49 --// extern lib methods //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
50 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
51 local ssl_wrap = ( luasec and luasec.wrap ) |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
52 local socket_bind = luasocket.bind |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
53 local socket_select = luasocket.select |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
54 local ssl_newcontext = ( luasec and luasec.newcontext ) |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
55 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
56 --// functions //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
57 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
58 local loop |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
59 local stats |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
60 local addtimer |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
61 local closeall |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
62 local addserver |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
63 local firetimer |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
64 local closesocket |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
65 local removesocket |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
66 local wrapserver |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
67 local wraptcpclient |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
68 local wrapsslclient |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
69 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
70 --// tables //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
71 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
72 local listener |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
73 local readlist |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
74 local writelist |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
75 local socketlist |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
76 local timelistener |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
77 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
78 --// simple data types //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
79 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
80 local _ |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
81 local readlen = 0 -- length of readlist |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
82 local writelen = 0 -- lenght of writelist |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
83 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
84 local sendstat= 0 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
85 local receivestat = 0 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
86 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
87 ----------------------------------// DEFINITION //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
88 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
89 listener = { } -- key = port, value = table |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
90 readlist = { } -- array with sockets to read from |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
91 writelist = { } -- arrary with sockets to write to |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
92 socketlist = { } -- key = socket, value = wrapped socket |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
93 timelistener = { } |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
94 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
95 stats = function( ) |
64 | 96 return receivestat, sendstat |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
97 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
98 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
99 wrapserver = function( listener, socket, ip, serverport, mode, sslctx ) -- this function wraps a server |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
100 |
64 | 101 local dispatch, disconnect = listener.listener, listener.disconnect -- dangerous |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
102 |
64 | 103 local wrapclient, err |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
104 |
64 | 105 if sslctx then |
106 if not ssl_newcontext then | |
107 return nil, "luasec not found" | |
108 end | |
109 if type( sslctx ) ~= "table" then | |
110 out_error "server.lua: wrong server sslctx" | |
111 return nil, "wrong server sslctx" | |
112 end | |
113 sslctx, err = ssl_newcontext( sslctx ) | |
114 if not sslctx then | |
115 err = err or "wrong sslctx parameters" | |
116 out_error( "server.lua: ", err ) | |
117 return nil, err | |
118 end | |
119 wrapclient = wrapsslclient | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
120 wrapclient = wraptlsclient |
64 | 121 else |
122 wrapclient = wraptcpclient | |
123 end | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
124 |
64 | 125 local accept = socket.accept |
126 local close = socket.close | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
127 |
64 | 128 --// public methods of the object //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
129 |
64 | 130 local handler = { } |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
131 |
64 | 132 handler.shutdown = function( ) end |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
133 |
64 | 134 --[[handler.listener = function( data, err ) |
135 return ondata( handler, data, err ) | |
136 end]] | |
137 handler.ssl = function( ) | |
138 return sslctx and true or false | |
139 end | |
140 handler.close = function( closed ) | |
141 _ = not closed and close( socket ) | |
142 writelen = removesocket( writelist, socket, writelen ) | |
143 readlen = removesocket( readlist, socket, readlen ) | |
144 socketlist[ socket ] = nil | |
145 handler = nil | |
146 end | |
147 handler.ip = function( ) | |
148 return ip | |
149 end | |
150 handler.serverport = function( ) | |
151 return serverport | |
152 end | |
153 handler.socket = function( ) | |
154 return socket | |
155 end | |
156 handler.receivedata = function( ) | |
157 local client, err = accept( socket ) -- try to accept | |
158 if client then | |
159 local ip, clientport = client:getpeername( ) | |
160 client:settimeout( 0 ) | |
161 local handler, client, err = wrapclient( listener, client, ip, serverport, clientport, mode, sslctx ) -- wrap new client socket | |
162 if err then -- error while wrapping ssl socket | |
163 return false | |
164 end | |
165 out_put( "server.lua: accepted new client connection from ", ip, ":", clientport ) | |
166 return dispatch( handler ) | |
167 elseif err then -- maybe timeout or something else | |
168 out_put( "server.lua: error with new client connection: ", err ) | |
169 return false | |
170 end | |
171 end | |
172 return handler | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
173 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
174 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
175 wrapsslclient = function( listener, socket, ip, serverport, clientport, mode, sslctx ) -- this function wraps a ssl cleint |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
176 |
64 | 177 local dispatch, disconnect = listener.listener, listener.disconnect |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
178 |
64 | 179 --// transform socket to ssl object //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
180 |
64 | 181 local err |
182 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket | |
183 if err then | |
184 out_put( "server.lua: ssl error: ", err ) | |
185 return nil, nil, err -- fatal error | |
186 end | |
187 socket:settimeout( 0 ) | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
188 |
64 | 189 --// private closures of the object //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
190 |
64 | 191 local writequeue = { } -- buffer for messages to send |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
192 |
64 | 193 local eol -- end of buffer |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
194 |
64 | 195 local sstat, rstat = 0, 0 |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
196 |
64 | 197 --// local import of socket methods //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
198 |
64 | 199 local send = socket.send |
200 local receive = socket.receive | |
201 local close = socket.close | |
202 --local shutdown = socket.shutdown | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
203 |
64 | 204 --// public methods of the object //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
205 |
64 | 206 local handler = { } |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
207 |
64 | 208 handler.getstats = function( ) |
209 return rstat, sstat | |
210 end | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
211 |
64 | 212 handler.listener = function( data, err ) |
213 return listener( handler, data, err ) | |
214 end | |
215 handler.ssl = function( ) | |
216 return true | |
217 end | |
218 handler.send = function( _, data, i, j ) | |
219 return send( socket, data, i, j ) | |
220 end | |
221 handler.receive = function( pattern, prefix ) | |
222 return receive( socket, pattern, prefix ) | |
223 end | |
224 handler.shutdown = function( pattern ) | |
225 --return shutdown( socket, pattern ) | |
226 end | |
227 handler.close = function( closed ) | |
228 close( socket ) | |
229 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen | |
230 readlen = removesocket( readlist, socket, readlen ) | |
231 socketlist[ socket ] = nil | |
232 out_put "server.lua: closed handler and removed socket from list" | |
233 end | |
234 handler.ip = function( ) | |
235 return ip | |
236 end | |
237 handler.serverport = function( ) | |
238 return serverport | |
239 end | |
240 handler.clientport = function( ) | |
241 return clientport | |
242 end | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
243 |
64 | 244 handler.write = function( data ) |
245 if not eol then | |
246 writelen = writelen + 1 | |
247 writelist[ writelen ] = socket | |
248 eol = 0 | |
249 end | |
250 eol = eol + 1 | |
251 writequeue[ eol ] = data | |
252 end | |
253 handler.writequeue = function( ) | |
254 return writequeue | |
255 end | |
256 handler.socket = function( ) | |
257 return socket | |
258 end | |
259 handler.mode = function( ) | |
260 return mode | |
261 end | |
262 handler._receivedata = function( ) | |
263 local data, err, part = receive( socket, mode ) -- receive data in "mode" | |
264 if not err or ( err == "timeout" or err == "wantread" ) then -- received something | |
265 local data = data or part or "" | |
266 local count = #data * STAT_UNIT | |
267 rstat = rstat + count | |
268 receivestat = receivestat + count | |
269 out_put( "server.lua: read data '", data, "', error: ", err ) | |
270 return dispatch( handler, data, err ) | |
271 else -- connections was closed or fatal error | |
272 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) | |
273 handler.close( ) | |
274 disconnect( handler, err ) | |
275 writequeue = nil | |
276 handler = nil | |
277 return false | |
278 end | |
279 end | |
280 handler._dispatchdata = function( ) -- this function writes data to handlers | |
281 local buffer = table_concat( writequeue, "", 1, eol ) | |
282 local succ, err, byte = send( socket, buffer ) | |
283 local count = ( succ or 0 ) * STAT_UNIT | |
284 sstat = sstat + count | |
285 sendstat = sendstat + count | |
286 out_put( "server.lua: sended '", buffer, "', bytes: ", succ, ", error: ", err, ", part: ", byte, ", to: ", ip, ":", clientport ) | |
287 if succ then -- sending succesful | |
288 --writequeue = { } | |
289 eol = nil | |
290 writelen = removesocket( writelist, socket, writelen ) -- delete socket from writelist | |
291 return true | |
292 elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write | |
293 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer | |
294 writequeue[ 1 ] = buffer -- insert new buffer in queue | |
295 eol = 1 | |
296 return true | |
297 else -- connection was closed during sending or fatal error | |
298 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) | |
299 handler.close( ) | |
300 disconnect( handler, err ) | |
301 writequeue = nil | |
302 handler = nil | |
303 return false | |
304 end | |
305 end | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
306 |
64 | 307 -- // COMPAT // -- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
308 |
64 | 309 handler.getIp = handler.ip |
310 handler.getPort = handler.clientport | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
311 |
64 | 312 --// handshake //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
313 |
64 | 314 local wrote |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
315 |
64 | 316 handler.handshake = coroutine_wrap( function( client ) |
317 local err | |
318 for i = 1, 10 do -- 10 handshake attemps | |
319 _, err = client:dohandshake( ) | |
320 if not err then | |
321 out_put( "server.lua: ssl handshake done" ) | |
322 writelen = ( wrote and removesocket( writelist, socket, writelen ) ) or writelen | |
323 handler.receivedata = handler._receivedata -- when handshake is done, replace the handshake function with regular functions | |
324 handler.dispatchdata = handler._dispatchdata | |
325 return dispatch( handler ) | |
326 else | |
327 out_put( "server.lua: error during ssl handshake: ", err ) | |
328 if err == "wantwrite" then | |
329 if wrote == nil then | |
330 writelen = writelen + 1 | |
331 writelist[ writelen ] = client | |
332 wrote = true | |
333 end | |
334 end | |
335 coroutine_yield( handler, nil, err ) -- handshake not finished | |
336 end | |
337 end | |
338 _ = err ~= "closed" and close( socket ) | |
339 handler.close( ) | |
340 disconnect( handler, err ) | |
341 writequeue = nil | |
342 handler = nil | |
343 return false -- handshake failed | |
344 end | |
345 ) | |
346 handler.receivedata = handler.handshake | |
347 handler.dispatchdata = handler.handshake | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
348 |
64 | 349 handler.handshake( socket ) -- do handshake |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
350 |
64 | 351 socketlist[ socket ] = handler |
352 readlen = readlen + 1 | |
353 readlist[ readlen ] = socket | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
354 |
64 | 355 return handler, socket |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
356 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
357 |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
358 wraptlsclient = function( listener, socket, ip, serverport, clientport, mode, sslctx ) -- this function wraps a tls cleint |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
359 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
360 local dispatch, disconnect = listener.listener, listener.disconnect |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
361 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
362 --// transform socket to ssl object //-- |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
363 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
364 local err |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
365 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
366 socket:settimeout( 0 ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
367 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
368 --// private closures of the object //-- |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
369 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
370 local writequeue = { } -- buffer for messages to send |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
371 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
372 local eol -- end of buffer |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
373 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
374 local sstat, rstat = 0, 0 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
375 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
376 --// local import of socket methods //-- |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
377 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
378 local send = socket.send |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
379 local receive = socket.receive |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
380 local close = socket.close |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
381 --local shutdown = socket.shutdown |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
382 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
383 --// public methods of the object //-- |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
384 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
385 local handler = { } |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
386 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
387 handler.getstats = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
388 return rstat, sstat |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
389 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
390 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
391 handler.listener = function( data, err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
392 return listener( handler, data, err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
393 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
394 handler.ssl = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
395 return false |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
396 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
397 handler.send = function( _, data, i, j ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
398 return send( socket, data, i, j ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
399 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
400 handler.receive = function( pattern, prefix ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
401 return receive( socket, pattern, prefix ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
402 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
403 handler.shutdown = function( pattern ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
404 --return shutdown( socket, pattern ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
405 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
406 handler.close = function( closed ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
407 close( socket ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
408 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
409 readlen = removesocket( readlist, socket, readlen ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
410 socketlist[ socket ] = nil |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
411 out_put "server.lua: closed handler and removed socket from list" |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
412 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
413 handler.ip = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
414 return ip |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
415 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
416 handler.serverport = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
417 return serverport |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
418 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
419 handler.clientport = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
420 return clientport |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
421 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
422 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
423 handler.write = function( data ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
424 if not eol then |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
425 writelen = writelen + 1 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
426 writelist[ writelen ] = socket |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
427 eol = 0 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
428 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
429 eol = eol + 1 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
430 writequeue[ eol ] = data |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
431 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
432 handler.writequeue = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
433 return writequeue |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
434 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
435 handler.socket = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
436 return socket |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
437 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
438 handler.mode = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
439 return mode |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
440 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
441 handler._receivedata = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
442 local data, err, part = receive( socket, mode ) -- receive data in "mode" |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
443 if not err or ( err == "timeout" or err == "wantread" ) then -- received something |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
444 local data = data or part or "" |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
445 local count = #data * STAT_UNIT |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
446 rstat = rstat + count |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
447 receivestat = receivestat + count |
66 | 448 --out_put( "server.lua: read data '", data, "', error: ", err ) |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
449 return dispatch( handler, data, err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
450 else -- connections was closed or fatal error |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
451 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
452 handler.close( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
453 disconnect( handler, err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
454 writequeue = nil |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
455 handler = nil |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
456 return false |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
457 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
458 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
459 handler._dispatchdata = function( ) -- this function writes data to handlers |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
460 local buffer = table_concat( writequeue, "", 1, eol ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
461 local succ, err, byte = send( socket, buffer ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
462 local count = ( succ or 0 ) * STAT_UNIT |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
463 sstat = sstat + count |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
464 sendstat = sendstat + count |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
465 out_put( "server.lua: sended '", buffer, "', bytes: ", succ, ", error: ", err, ", part: ", byte, ", to: ", ip, ":", clientport ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
466 if succ then -- sending succesful |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
467 --writequeue = { } |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
468 eol = nil |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
469 writelen = removesocket( writelist, socket, writelen ) -- delete socket from writelist |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
470 if handler.need_tls then |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
471 out_put("server.lua: connection is ready for tls handshake"); |
66 | 472 handler.starttls(true); |
473 if handler.need_tls then | |
474 out_put("server.lua: uh-oh... we still want tls, something must be wrong"); | |
475 end | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
476 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
477 return true |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
478 elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
479 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
480 writequeue[ 1 ] = buffer -- insert new buffer in queue |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
481 eol = 1 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
482 return true |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
483 else -- connection was closed during sending or fatal error |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
484 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
485 handler.close( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
486 disconnect( handler, err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
487 writequeue = nil |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
488 handler = nil |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
489 return false |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
490 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
491 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
492 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
493 handler.receivedata, handler.dispatchdata = handler._receivedata, handler._dispatchdata; |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
494 -- // COMPAT // -- |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
495 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
496 handler.getIp = handler.ip |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
497 handler.getPort = handler.clientport |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
498 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
499 --// handshake //-- |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
500 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
501 local wrote, read |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
502 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
503 handler.starttls = function (now) |
66 | 504 if not now then out_put("server.lua: we need to do tls, but delaying until later"); handler.need_tls = true; return; end |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
505 out_put( "server.lua: attempting to start tls on "..tostring(socket) ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
506 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
507 out_put("sslwrapped socket is "..tostring(socket)); |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
508 if err then |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
509 out_put( "server.lua: ssl error: ", err ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
510 return nil, nil, err -- fatal error |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
511 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
512 socket:settimeout( 1 ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
513 send = socket.send |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
514 receive = socket.receive |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
515 close = socket.close |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
516 handler.ssl = function( ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
517 return true |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
518 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
519 handler.send = function( _, data, i, j ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
520 return send( socket, data, i, j ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
521 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
522 handler.receive = function( pattern, prefix ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
523 return receive( socket, pattern, prefix ) |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
524 end |
66 | 525 |
319
4a8a949c3870
Fix for putting TLS in stream:features for connections already using TLS. Thanks to albert for spotting.
Matthew Wild <mwild1@gmail.com>
parents:
127
diff
changeset
|
526 handler.starttls = nil; |
4a8a949c3870
Fix for putting TLS in stream:features for connections already using TLS. Thanks to albert for spotting.
Matthew Wild <mwild1@gmail.com>
parents:
127
diff
changeset
|
527 |
66 | 528 handler.handshake = coroutine_wrap( function( client ) |
529 local err | |
530 for i = 1, 10 do -- 10 handshake attemps | |
531 _, err = client:dohandshake( ) | |
532 if not err then | |
533 out_put( "server.lua: ssl handshake done" ) | |
534 writelen = ( wrote and removesocket( writelist, socket, writelen ) ) or writelen | |
535 handler.receivedata = handler._receivedata -- when handshake is done, replace the handshake function with regular functions | |
536 handler.dispatchdata = handler._dispatchdata | |
537 handler.need_tls = nil | |
538 socketlist[ client ] = handler | |
539 readlen = readlen + 1 | |
540 readlist[ readlen ] = client | |
541 return true; | |
542 else | |
543 out_put( "server.lua: error during ssl handshake: ", err ) | |
544 if err == "wantwrite" then | |
545 if wrote == nil then | |
546 writelen = writelen + 1 | |
547 writelist[ writelen ] = client | |
548 wrote = true | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
549 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
550 end |
66 | 551 coroutine_yield( handler, nil, err ) -- handshake not finished |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
552 end |
66 | 553 end |
554 _ = err ~= "closed" and close( socket ) | |
555 handler.close( ) | |
556 disconnect( handler, err ) | |
557 writequeue = nil | |
558 handler = nil | |
559 return false -- handshake failed | |
560 end | |
561 ) | |
562 handler.receivedata = handler.handshake | |
563 handler.dispatchdata = handler.handshake | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
564 |
66 | 565 handler.handshake( socket ) -- do handshake |
566 end | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
567 socketlist[ socket ] = handler |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
568 readlen = readlen + 1 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
569 readlist[ readlen ] = socket |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
570 |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
571 return handler, socket |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
572 end |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
573 |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
574 wraptcpclient = function( listener, socket, ip, serverport, clientport, mode ) -- this function wraps a socket |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
575 |
64 | 576 local dispatch, disconnect = listener.listener, listener.disconnect |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
577 |
64 | 578 --// private closures of the object //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
579 |
64 | 580 local writequeue = { } -- list for messages to send |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
581 |
64 | 582 local eol |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
583 |
64 | 584 local rstat, sstat = 0, 0 |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
585 |
64 | 586 --// local import of socket methods //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
587 |
64 | 588 local send = socket.send |
589 local receive = socket.receive | |
590 local close = socket.close | |
591 local shutdown = socket.shutdown | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
592 |
64 | 593 --// public methods of the object //-- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
594 |
64 | 595 local handler = { } |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
596 |
64 | 597 handler.getstats = function( ) |
598 return rstat, sstat | |
599 end | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
600 |
64 | 601 handler.listener = function( data, err ) |
602 return listener( handler, data, err ) | |
603 end | |
604 handler.ssl = function( ) | |
605 return false | |
606 end | |
607 handler.send = function( _, data, i, j ) | |
608 return send( socket, data, i, j ) | |
609 end | |
610 handler.receive = function( pattern, prefix ) | |
611 return receive( socket, pattern, prefix ) | |
612 end | |
613 handler.shutdown = function( pattern ) | |
614 return shutdown( socket, pattern ) | |
615 end | |
616 handler.close = function( closed ) | |
617 _ = not closed and shutdown( socket ) | |
618 _ = not closed and close( socket ) | |
619 writelen = ( eol and removesocket( writelist, socket, writelen ) ) or writelen | |
620 readlen = removesocket( readlist, socket, readlen ) | |
621 socketlist[ socket ] = nil | |
622 out_put "server.lua: closed handler and removed socket from list" | |
623 end | |
624 handler.ip = function( ) | |
625 return ip | |
626 end | |
627 handler.serverport = function( ) | |
628 return serverport | |
629 end | |
630 handler.clientport = function( ) | |
631 return clientport | |
632 end | |
633 handler.write = function( data ) | |
634 if not eol then | |
635 writelen = writelen + 1 | |
636 writelist[ writelen ] = socket | |
637 eol = 0 | |
638 end | |
639 eol = eol + 1 | |
640 writequeue[ eol ] = data | |
641 end | |
642 handler.writequeue = function( ) | |
643 return writequeue | |
644 end | |
645 handler.socket = function( ) | |
646 return socket | |
647 end | |
648 handler.mode = function( ) | |
649 return mode | |
650 end | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
651 |
64 | 652 handler.receivedata = function( ) |
653 local data, err, part = receive( socket, mode ) -- receive data in "mode" | |
654 if not err or ( err == "timeout" or err == "wantread" ) then -- received something | |
655 local data = data or part or "" | |
656 local count = #data * STAT_UNIT | |
657 rstat = rstat + count | |
658 receivestat = receivestat + count | |
659 out_put( "server.lua: read data '", data, "', error: ", err ) | |
660 return dispatch( handler, data, err ) | |
661 else -- connections was closed or fatal error | |
662 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) | |
663 handler.close( ) | |
664 disconnect( handler, err ) | |
665 writequeue = nil | |
666 handler = nil | |
667 return false | |
668 end | |
669 end | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
670 |
64 | 671 handler.dispatchdata = function( ) -- this function writes data to handlers |
672 local buffer = table_concat( writequeue, "", 1, eol ) | |
673 local succ, err, byte = send( socket, buffer ) | |
674 local count = ( succ or 0 ) * STAT_UNIT | |
675 sstat = sstat + count | |
676 sendstat = sendstat + count | |
677 out_put( "server.lua: sended '", buffer, "', bytes: ", succ, ", error: ", err, ", part: ", byte, ", to: ", ip, ":", clientport ) | |
678 if succ then -- sending succesful | |
679 --writequeue = { } | |
680 eol = nil | |
681 writelen = removesocket( writelist, socket, writelen ) -- delete socket from writelist | |
682 return true | |
683 elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write | |
684 buffer = string_sub( buffer, byte + 1, -1 ) -- new buffer | |
685 writequeue[ 1 ] = buffer -- insert new buffer in queue | |
686 eol = 1 | |
687 return true | |
688 else -- connection was closed during sending or fatal error | |
689 out_put( "server.lua: client ", ip, ":", clientport, " error: ", err ) | |
690 handler.close( ) | |
691 disconnect( handler, err ) | |
692 writequeue = nil | |
693 handler = nil | |
694 return false | |
695 end | |
696 end | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
697 |
64 | 698 -- // COMPAT // -- |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
699 |
64 | 700 handler.getIp = handler.ip |
701 handler.getPort = handler.clientport | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
702 |
64 | 703 socketlist[ socket ] = handler |
704 readlen = readlen + 1 | |
705 readlist[ readlen ] = socket | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
706 |
64 | 707 return handler, socket |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
708 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
709 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
710 addtimer = function( listener ) |
64 | 711 timelistener[ #timelistener + 1 ] = listener |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
712 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
713 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
714 firetimer = function( listener ) |
64 | 715 for i, listener in ipairs( timelistener ) do |
716 listener( ) | |
717 end | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
718 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
719 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
720 addserver = function( listeners, port, addr, mode, sslctx ) -- this function provides a way for other scripts to reg a server |
64 | 721 local err |
722 if type( listeners ) ~= "table" then | |
723 err = "invalid listener table" | |
724 else | |
725 for name, func in pairs( listeners ) do | |
726 if type( func ) ~= "function" then | |
98
3a2d327c4856
server.lua should degrade gracefully when LuaSec not present
Matthew Wild <mwild1@gmail.com>
parents:
74
diff
changeset
|
727 --err = "invalid listener function" |
64 | 728 break |
729 end | |
730 end | |
731 end | |
732 if not type( port ) == "number" or not ( port >= 0 and port <= 65535 ) then | |
733 err = "invalid port" | |
734 elseif listener[ port ] then | |
735 err= "listeners on port '" .. port .. "' already exist" | |
736 elseif sslctx and not luasec then | |
737 err = "luasec not found" | |
738 end | |
739 if err then | |
740 out_error( "server.lua: ", err ) | |
741 return nil, err | |
742 end | |
743 addr = addr or "*" | |
744 local server, err = socket_bind( addr, port ) | |
745 if err then | |
746 out_error( "server.lua: ", err ) | |
747 return nil, err | |
748 end | |
749 local handler, err = wrapserver( listeners, server, addr, port, mode, sslctx ) -- wrap new server socket | |
750 if not handler then | |
751 server:close( ) | |
752 return nil, err | |
753 end | |
754 server:settimeout( 0 ) | |
755 readlen = readlen + 1 | |
756 readlist[ readlen ] = server | |
757 listener[ port ] = listeners | |
758 socketlist[ server ] = handler | |
759 out_put( "server.lua: new server listener on ", addr, ":", port ) | |
760 return true | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
761 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
762 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
763 removesocket = function( tbl, socket, len ) -- this function removes sockets from a list |
64 | 764 for i, target in ipairs( tbl ) do |
765 if target == socket then | |
766 len = len - 1 | |
767 table_remove( tbl, i ) | |
768 return len | |
769 end | |
770 end | |
771 return len | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
772 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
773 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
774 closeall = function( ) |
64 | 775 for sock, handler in pairs( socketlist ) do |
776 handler.shutdown( ) | |
777 handler.close( ) | |
778 socketlist[ sock ] = nil | |
779 end | |
780 writelist, readlist, socketlist = { }, { }, { } | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
781 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
782 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
783 closesocket = function( socket ) |
64 | 784 writelen = removesocket( writelist, socket, writelen ) |
785 readlen = removesocket( readlist, socket, readlen ) | |
786 socketlist[ socket ] = nil | |
787 socket:close( ) | |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
788 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
789 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
790 loop = function( ) -- this is the main loop of the program |
64 | 791 --signal_set( "hub", "run" ) |
792 repeat | |
66 | 793 --[[print(readlen, writelen) |
794 for _, s in ipairs(readlist) do print("R:", tostring(s)) end | |
795 for _, s in ipairs(writelist) do print("W:", tostring(s)) end | |
796 out_put("select()"..os.time())]] | |
64 | 797 local read, write, err = socket_select( readlist, writelist, 1 ) -- 1 sec timeout, nice for timers |
798 for i, socket in ipairs( write ) do -- send data waiting in writequeues | |
799 local handler = socketlist[ socket ] | |
800 if handler then | |
801 handler.dispatchdata( ) | |
802 else | |
803 closesocket( socket ) | |
804 out_put "server.lua: found no handler and closed socket (writelist)" -- this should not happen | |
805 end | |
806 end | |
807 for i, socket in ipairs( read ) do -- receive data | |
808 local handler = socketlist[ socket ] | |
809 if handler then | |
810 handler.receivedata( ) | |
811 else | |
812 closesocket( socket ) | |
813 out_put "server.lua: found no handler and closed socket (readlist)" -- this can happen | |
814 end | |
815 end | |
816 firetimer( ) | |
65
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
817 until false |
9c471840acb9
TLS: Handshake works, no data after that
Matthew Wild <mwild1@gmail.com>
parents:
64
diff
changeset
|
818 return |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
819 end |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
820 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
821 ----------------------------------// BEGIN //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
822 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
823 ----------------------------------// PUBLIC INTERFACE //-- |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
824 |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
825 return { |
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
826 |
64 | 827 add = addserver, |
828 loop = loop, | |
829 stats = stats, | |
830 closeall = closeall, | |
831 addtimer = addtimer, | |
127 | 832 wraptlsclient = wraptlsclient, |
1
b8787e859fd2
Switched to new connection framework, courtesy of the luadch project
matthew
parents:
diff
changeset
|
833 } |