Comparison

net/server_epoll.lua @ 7592:10d2f008321d

net.server_epoll: Additional logging of connects and TLS
author Kim Alvefur <zash@zash.se>
date Thu, 18 Aug 2016 16:33:12 +0200
parent 7591:138f16eb39fb
child 7593:0266434d7df1
comparison
equal deleted inserted replaced
7591:138f16eb39fb 7592:10d2f008321d
335 function interface:close() 335 function interface:close()
336 if self._wantwrite then 336 if self._wantwrite then
337 log("debug", "Close %s after writing", tostring(self)); 337 log("debug", "Close %s after writing", tostring(self));
338 self._toclose = true; 338 self._toclose = true;
339 else 339 else
340 log("debug", "Close %s", tostring(self)); 340 log("debug", "Close %s now", tostring(self));
341 self.close = noop; 341 self.close = noop;
342 self:on("disconnect"); 342 self:on("disconnect");
343 self:destroy(); 343 self:destroy();
344 end 344 end
345 end 345 end
357 end 357 end
358 358
359 function interface:starttls(ctx) 359 function interface:starttls(ctx)
360 if ctx then self.tls = ctx; end 360 if ctx then self.tls = ctx; end
361 if self.writebuffer and self.writebuffer[1] then 361 if self.writebuffer and self.writebuffer[1] then
362 log("debug", "Start TLS on %s after write", tostring(self));
362 self._starttls = true; 363 self._starttls = true;
363 else 364 else
365 log("debug", "Start TLS on %s now", tostring(self));
364 self:setflags(false, false); 366 self:setflags(false, false);
365 local conn, err = luasec.wrap(self.conn, ctx or self.tls); 367 local conn, err = luasec.wrap(self.conn, ctx or self.tls);
366 if not conn then 368 if not conn then
367 self:on("disconnect", err); 369 self:on("disconnect", err);
368 self:destroy(); 370 self:destroy();
377 end 379 end
378 380
379 function interface:tlshandskake() 381 function interface:tlshandskake()
380 local ok, err = self.conn:dohandshake(); 382 local ok, err = self.conn:dohandshake();
381 if ok then 383 if ok then
384 log("debug", "TLS handshake on %s complete", tostring(self));
382 self.onwriteable = nil; 385 self.onwriteable = nil;
383 self.onreadable = nil; 386 self.onreadable = nil;
384 self:setflags(true, true); 387 self:setflags(true, true);
385 local old = self._tls; 388 local old = self._tls;
386 self._tls = true; 389 self._tls = true;
389 self:on("connect"); 392 self:on("connect");
390 else 393 else
391 self:on("status", "ssl-handshake-complete"); 394 self:on("status", "ssl-handshake-complete");
392 end 395 end
393 elseif err == "wantread" then 396 elseif err == "wantread" then
397 log("debug", "TLS handshake on %s to wait until readable", tostring(self));
394 self:setflags(true, false); 398 self:setflags(true, false);
395 self:setwritetimeout(false); 399 self:setwritetimeout(false);
396 self:setreadtimeout(cfg.handshake_timeout); 400 self:setreadtimeout(cfg.handshake_timeout);
397 elseif err == "wantwrite" then 401 elseif err == "wantwrite" then
402 log("debug", "TLS handshake on %s to wait until writable", tostring(self));
398 self:setflags(false, true); 403 self:setflags(false, true);
399 self:setreadtimeout(false); 404 self:setreadtimeout(false);
400 self:setwritetimeout(cfg.handshake_timeout); 405 self:setwritetimeout(cfg.handshake_timeout);
401 else 406 else
407 log("debug", "TLS handshake error on %s: %s", tostring(self), err);
402 self:on("disconnect", err); 408 self:on("disconnect", err);
403 self:destroy(); 409 self:destroy();
404 end 410 end
405 end 411 end
406 412
434 log("debug", "Error accepting new client: %s, server will be paused for %ds", err, cfg.accept_retry_interval); 440 log("debug", "Error accepting new client: %s, server will be paused for %ds", err, cfg.accept_retry_interval);
435 self:pausefor(cfg.accept_retry_interval); 441 self:pausefor(cfg.accept_retry_interval);
436 return; 442 return;
437 end 443 end
438 local client = wrapsocket(conn, self, nil, self.listeners, self.tls); 444 local client = wrapsocket(conn, self, nil, self.listeners, self.tls);
445 log("debug", "New connection %s", tostring(client));
439 if self.tls then 446 if self.tls then
440 client._tls = false; 447 client._tls = false;
441 client:starttls(); 448 client:starttls();
442 else 449 else
443 client:setflags(false, true); 450 client:setflags(false, true);