Comparison

net/server_epoll.lua @ 7598:335b5ce06062

net.server_epoll: TLS handshake timeout
author Kim Alvefur <zash@zash.se>
date Thu, 18 Aug 2016 17:07:14 +0200
parent 7597:cd34aa6b1632
child 7599:afbda0bd9cfc
comparison
equal deleted inserted replaced
7597:cd34aa6b1632 7598:335b5ce06062
28 read_timeout = 900; 28 read_timeout = 900;
29 write_timeout = 7; 29 write_timeout = 7;
30 tcp_backlog = 128; 30 tcp_backlog = 128;
31 accept_retry_interval = 10; 31 accept_retry_interval = 10;
32 read_retry_delay = 1e-06; 32 read_retry_delay = 1e-06;
33 handshake_timeout = 60;
33 }; 34 };
34 35
35 local fds = createtable(10, 0); -- FD -> conn 36 local fds = createtable(10, 0); -- FD -> conn
36 local timers = {}; 37 local timers = {};
37 38
383 self.conn = conn; 384 self.conn = conn;
384 self._starttls = nil; 385 self._starttls = nil;
385 self.onwriteable = interface.tlshandskake; 386 self.onwriteable = interface.tlshandskake;
386 self.onreadable = interface.tlshandskake; 387 self.onreadable = interface.tlshandskake;
387 self:setflags(true, true); 388 self:setflags(true, true);
389 self:setwritetimeout(cfg.handshake_timeout);
388 end 390 end
389 end 391 end
390 392
391 function interface:tlshandskake() 393 function interface:tlshandskake()
394 self:setwritetimeout(false);
395 self:setreadtimeout(false);
392 local ok, err = self.conn:dohandshake(); 396 local ok, err = self.conn:dohandshake();
393 if ok then 397 if ok then
394 log("debug", "TLS handshake on %s complete", tostring(self)); 398 log("debug", "TLS handshake on %s complete", tostring(self));
395 self.onwriteable = nil; 399 self.onwriteable = nil;
396 self.onreadable = nil; 400 self.onreadable = nil;
404 self:on("status", "ssl-handshake-complete"); 408 self:on("status", "ssl-handshake-complete");
405 end 409 end
406 elseif err == "wantread" then 410 elseif err == "wantread" then
407 log("debug", "TLS handshake on %s to wait until readable", tostring(self)); 411 log("debug", "TLS handshake on %s to wait until readable", tostring(self));
408 self:setflags(true, false); 412 self:setflags(true, false);
409 self:setwritetimeout(false);
410 self:setreadtimeout(cfg.handshake_timeout); 413 self:setreadtimeout(cfg.handshake_timeout);
411 elseif err == "wantwrite" then 414 elseif err == "wantwrite" then
412 log("debug", "TLS handshake on %s to wait until writable", tostring(self)); 415 log("debug", "TLS handshake on %s to wait until writable", tostring(self));
413 self:setflags(false, true); 416 self:setflags(false, true);
414 self:setreadtimeout(false);
415 self:setwritetimeout(cfg.handshake_timeout); 417 self:setwritetimeout(cfg.handshake_timeout);
416 else 418 else
417 log("debug", "TLS handshake error on %s: %s", tostring(self), err); 419 log("debug", "TLS handshake error on %s: %s", tostring(self), err);
418 self:on("disconnect", err); 420 self:on("disconnect", err);
419 self:destroy(); 421 self:destroy();