Software /
code /
prosody
Comparison
net/server_epoll.lua @ 11063:30d3f6f85eb8 0.11
net.server: Backport client parts of SNI support from trunk (#409)
Partial backports of the following commits from trunk:
6c804b6b2ca2 net.http: Pass server name along for SNI (fixes #1408)
75d2874502c3 net.server_select: SNI support (#409)
9a905888b96c net.server_event: Add SNI support (#409)
adc0672b700e net.server_epoll: Add support for SNI (#409)
d4390c427a66 net.server: Handle server name (SNI) as extra argument
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 17 Aug 2020 23:01:14 +0200 |
parent | 10681:e531273341d3 |
child | 11068:988ddd57e851 |
child | 11262:2c559953ad41 |
comparison
equal
deleted
inserted
replaced
11061:45e1c467a3a7 | 11063:30d3f6f85eb8 |
---|---|
481 self:destroy(); | 481 self:destroy(); |
482 return conn, err; | 482 return conn, err; |
483 end | 483 end |
484 conn:settimeout(0); | 484 conn:settimeout(0); |
485 self.conn = conn; | 485 self.conn = conn; |
486 if conn.sni and self.servername then | |
487 conn:sni(self.servername); | |
488 end | |
486 self:on("starttls"); | 489 self:on("starttls"); |
487 self.ondrain = nil; | 490 self.ondrain = nil; |
488 self.onwritable = interface.tlshandskake; | 491 self.onwritable = interface.tlshandskake; |
489 self.onreadable = interface.tlshandskake; | 492 self.onreadable = interface.tlshandskake; |
490 return self:init(); | 493 return self:init(); |
510 self:on("disconnect", err); | 513 self:on("disconnect", err); |
511 self:destroy(); | 514 self:destroy(); |
512 end | 515 end |
513 end | 516 end |
514 | 517 |
515 local function wrapsocket(client, server, read_size, listeners, tls_ctx) -- luasocket object -> interface object | 518 local function wrapsocket(client, server, read_size, listeners, tls_ctx, extra) -- luasocket object -> interface object |
516 client:settimeout(0); | 519 client:settimeout(0); |
517 local conn = setmetatable({ | 520 local conn = setmetatable({ |
518 conn = client; | 521 conn = client; |
519 _server = server; | 522 _server = server; |
520 created = gettime(); | 523 created = gettime(); |
521 listeners = listeners; | 524 listeners = listeners; |
522 read_size = read_size or (server and server.read_size); | 525 read_size = read_size or (server and server.read_size); |
523 writebuffer = {}; | 526 writebuffer = {}; |
524 tls_ctx = tls_ctx or (server and server.tls_ctx); | 527 tls_ctx = tls_ctx or (server and server.tls_ctx); |
525 tls_direct = server and server.tls_direct; | 528 tls_direct = server and server.tls_direct; |
529 extra = extra; | |
526 }, interface_mt); | 530 }, interface_mt); |
531 | |
532 if extra then | |
533 if extra.servername then | |
534 conn.servername = extra.servername; | |
535 end | |
536 end | |
527 | 537 |
528 conn:updatenames(); | 538 conn:updatenames(); |
529 return conn; | 539 return conn; |
530 end | 540 end |
531 | 541 |
615 server:add(true, false); | 625 server:add(true, false); |
616 return server; | 626 return server; |
617 end | 627 end |
618 | 628 |
619 -- COMPAT | 629 -- COMPAT |
620 local function wrapclient(conn, addr, port, listeners, read_size, tls_ctx) | 630 local function wrapclient(conn, addr, port, listeners, read_size, tls_ctx, extra) |
621 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx); | 631 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx, extra); |
622 if not client.peername then | 632 if not client.peername then |
623 client.peername, client.peerport = addr, port; | 633 client.peername, client.peerport = addr, port; |
624 end | 634 end |
625 local ok, err = client:init(); | 635 local ok, err = client:init(); |
626 if not ok then return ok, err; end | 636 if not ok then return ok, err; end |
629 end | 639 end |
630 return client; | 640 return client; |
631 end | 641 end |
632 | 642 |
633 -- New outgoing TCP connection | 643 -- New outgoing TCP connection |
634 local function addclient(addr, port, listeners, read_size, tls_ctx, typ) | 644 local function addclient(addr, port, listeners, read_size, tls_ctx, typ, extra) |
635 local create; | 645 local create; |
636 if not typ then | 646 if not typ then |
637 local n = inet_pton(addr); | 647 local n = inet_pton(addr); |
638 if not n then return nil, "invalid-ip"; end | 648 if not n then return nil, "invalid-ip"; end |
639 if #n == 16 then | 649 if #n == 16 then |
651 local conn, err = create(); | 661 local conn, err = create(); |
652 local ok, err = conn:settimeout(0); | 662 local ok, err = conn:settimeout(0); |
653 if not ok then return ok, err; end | 663 if not ok then return ok, err; end |
654 local ok, err = conn:setpeername(addr, port); | 664 local ok, err = conn:setpeername(addr, port); |
655 if not ok and err ~= "timeout" then return ok, err; end | 665 if not ok and err ~= "timeout" then return ok, err; end |
656 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx) | 666 local client = wrapsocket(conn, nil, read_size, listeners, tls_ctx, extra) |
657 local ok, err = client:init(); | 667 local ok, err = client:init(); |
658 if not ok then return ok, err; end | 668 if not ok then return ok, err; end |
659 if tls_ctx then | 669 if tls_ctx then |
660 client:starttls(tls_ctx); | 670 client:starttls(tls_ctx); |
661 end | 671 end |