Comparison

net/server_epoll.lua @ 9306:35c128b42509

net.server_epoll: Factor Direct TLS handling out of connection initialization Eventually it should be possible to create a socket that has a TLS context but that does not automatically start TLS on connect.
author Kim Alvefur <zash@zash.se>
date Thu, 13 Sep 2018 17:28:50 +0200
parent 9301:2f9687c09e6e
child 9309:33d500c25d76
comparison
equal deleted inserted replaced
9305:f14c81fd44a4 9306:35c128b42509
452 log("debug", "TLS handshake on %s complete", self); 452 log("debug", "TLS handshake on %s complete", self);
453 self.onwritable = nil; 453 self.onwritable = nil;
454 self.onreadable = nil; 454 self.onreadable = nil;
455 self._tls = true; 455 self._tls = true;
456 self:on("status", "ssl-handshake-complete"); 456 self:on("status", "ssl-handshake-complete");
457 self.init = nil; -- Restore default method
457 self:init(); 458 self:init();
458 elseif err == "wantread" then 459 elseif err == "wantread" then
459 log("debug", "TLS handshake on %s to wait until readable", self); 460 log("debug", "TLS handshake on %s to wait until readable", self);
460 self:setflags(true, false); 461 self:setflags(true, false);
461 self:setreadtimeout(cfg.handshake_timeout); 462 self:setreadtimeout(cfg.handshake_timeout);
486 conn.peername, conn.peerport = client:getpeername(); 487 conn.peername, conn.peerport = client:getpeername();
487 end 488 end
488 if client.getsockname then 489 if client.getsockname then
489 conn.sockname, conn.sockport = client:getsockname(); 490 conn.sockname, conn.sockport = client:getsockname();
490 end 491 end
492 if tls_ctx then
493 conn.init = interface.starttls;
494 end
491 return conn; 495 return conn;
492 end 496 end
493 497
494 -- A server interface has new incoming connections waiting 498 -- A server interface has new incoming connections waiting
495 -- This replaces the onreadable callback 499 -- This replaces the onreadable callback
505 client:init(); 509 client:init();
506 end 510 end
507 511
508 -- Initialization 512 -- Initialization
509 function interface:init() 513 function interface:init()
510 if self.tls_ctx and not self._tls then 514 self:setwritetimeout();
511 return self:starttls(); 515 return self:setflags(true, true);
512 else
513 self:setwritetimeout();
514 return self:setflags(true, true);
515 end
516 end 516 end
517 517
518 function interface:pause() 518 function interface:pause()
519 return self:setflags(false); 519 return self:setflags(false);
520 end 520 end