2012-06-05 18:26:04 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-06-05 18:26:04 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef SHRPX_WORKER_H
|
|
|
|
#define SHRPX_WORKER_H
|
|
|
|
|
|
|
|
#include "shrpx.h"
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
#include <mutex>
|
2015-03-10 15:11:22 +01:00
|
|
|
#include <vector>
|
2016-01-15 15:04:58 +01:00
|
|
|
#include <random>
|
2016-02-06 15:07:00 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <deque>
|
2014-12-27 18:59:06 +01:00
|
|
|
#include <thread>
|
2019-01-21 16:01:17 +01:00
|
|
|
#include <queue>
|
2014-12-27 18:59:06 +01:00
|
|
|
#ifndef NOTHREADS
|
2018-06-09 09:21:30 +02:00
|
|
|
# include <future>
|
2014-12-27 18:59:06 +01:00
|
|
|
#endif // NOTHREADS
|
|
|
|
|
2012-06-05 18:26:04 +02:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
#include <ev.h>
|
|
|
|
|
|
|
|
#include "shrpx_config.h"
|
|
|
|
#include "shrpx_downstream_connection_pool.h"
|
2015-04-07 15:13:01 +02:00
|
|
|
#include "memchunk.h"
|
2017-04-01 08:07:32 +02:00
|
|
|
#include "shrpx_tls.h"
|
2016-09-04 16:30:24 +02:00
|
|
|
#include "shrpx_live_check.h"
|
|
|
|
#include "shrpx_connect_blocker.h"
|
2016-12-04 15:43:41 +01:00
|
|
|
#include "shrpx_dns_tracker.h"
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
# include "shrpx_quic_connection_handler.h"
|
2021-08-23 14:40:24 +02:00
|
|
|
# include "shrpx_quic.h"
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2016-10-02 09:18:35 +02:00
|
|
|
#include "allocator.h"
|
2015-04-07 15:13:01 +02:00
|
|
|
|
|
|
|
using namespace nghttp2;
|
2012-07-14 16:24:03 +02:00
|
|
|
|
2012-06-05 18:26:04 +02:00
|
|
|
namespace shrpx {
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
class Http2Session;
|
|
|
|
class ConnectBlocker;
|
2015-07-25 15:22:17 +02:00
|
|
|
class MemcachedDispatcher;
|
2016-02-07 09:51:53 +01:00
|
|
|
struct UpstreamAddr;
|
2016-06-03 18:02:57 +02:00
|
|
|
class ConnectionHandler;
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2021-08-15 09:57:39 +02:00
|
|
|
class QUICListener;
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-09-03 17:54:41 +02:00
|
|
|
#ifdef HAVE_MRUBY
|
2015-09-01 17:19:32 +02:00
|
|
|
namespace mruby {
|
|
|
|
|
|
|
|
class MRubyContext;
|
|
|
|
|
|
|
|
} // namespace mruby
|
2015-09-03 17:54:41 +02:00
|
|
|
#endif // HAVE_MRUBY
|
2015-09-01 17:19:32 +02:00
|
|
|
|
2017-04-01 08:07:32 +02:00
|
|
|
namespace tls {
|
2015-02-02 14:47:12 +01:00
|
|
|
class CertLookupTree;
|
2017-04-01 08:07:32 +02:00
|
|
|
} // namespace tls
|
2015-01-12 16:18:27 +01:00
|
|
|
|
2019-01-19 03:12:05 +01:00
|
|
|
struct WeightGroup;
|
|
|
|
|
2016-02-27 15:24:14 +01:00
|
|
|
struct DownstreamAddr {
|
|
|
|
Address addr;
|
|
|
|
// backend address. If |host_unix| is true, this is UNIX domain
|
|
|
|
// socket path.
|
2016-10-02 09:18:35 +02:00
|
|
|
StringRef host;
|
|
|
|
StringRef hostport;
|
2016-02-27 15:24:14 +01:00
|
|
|
// backend port. 0 if |host_unix| is true.
|
|
|
|
uint16_t port;
|
|
|
|
// true if |host| contains UNIX domain socket path.
|
|
|
|
bool host_unix;
|
|
|
|
|
2016-04-29 07:42:18 +02:00
|
|
|
// sni field to send remote server if TLS is enabled.
|
2016-10-02 09:18:35 +02:00
|
|
|
StringRef sni;
|
2016-04-29 07:42:18 +02:00
|
|
|
|
2016-02-27 15:24:14 +01:00
|
|
|
std::unique_ptr<ConnectBlocker> connect_blocker;
|
2016-04-07 18:04:16 +02:00
|
|
|
std::unique_ptr<LiveCheck> live_check;
|
2016-06-09 15:35:59 +02:00
|
|
|
// Connection pool for this particular address if session affinity
|
|
|
|
// is enabled
|
|
|
|
std::unique_ptr<DownstreamConnectionPool> dconn_pool;
|
2016-04-09 14:58:08 +02:00
|
|
|
size_t fall;
|
|
|
|
size_t rise;
|
2016-02-27 15:24:14 +01:00
|
|
|
// Client side TLS session cache
|
2017-04-01 08:07:32 +02:00
|
|
|
tls::TLSSessionCache tls_session_cache;
|
2019-01-19 03:12:05 +01:00
|
|
|
// List of Http2Session which is not fully utilized (i.e., the
|
|
|
|
// server advertised maximum concurrency is not reached). We will
|
|
|
|
// coalesce as much stream as possible in one Http2Session to fully
|
|
|
|
// utilize TCP connection.
|
2016-04-02 16:11:03 +02:00
|
|
|
DList<Http2Session> http2_extra_freelist;
|
2019-01-19 03:12:05 +01:00
|
|
|
WeightGroup *wg;
|
2016-04-02 16:11:03 +02:00
|
|
|
// total number of streams created in HTTP/2 connections for this
|
|
|
|
// address.
|
|
|
|
size_t num_dconn;
|
2019-01-19 03:12:05 +01:00
|
|
|
// the sequence number of this address to randomize the order access
|
|
|
|
// threads.
|
|
|
|
size_t seq;
|
2016-05-24 16:36:43 +02:00
|
|
|
// Application protocol used in this backend
|
2018-10-16 15:17:37 +02:00
|
|
|
Proto proto;
|
2019-01-19 03:12:05 +01:00
|
|
|
// cycle is used to prioritize this address. Lower value takes
|
|
|
|
// higher priority.
|
|
|
|
uint32_t cycle;
|
|
|
|
// penalty which is applied to the next cycle calculation.
|
|
|
|
uint32_t pending_penalty;
|
|
|
|
// Weight of this address inside a weight group. Its range is [1,
|
|
|
|
// 256], inclusive.
|
|
|
|
uint32_t weight;
|
|
|
|
// name of group which this address belongs to.
|
|
|
|
StringRef group;
|
|
|
|
// Weight of the weight group which this address belongs to. Its
|
|
|
|
// range is [1, 256], inclusive.
|
|
|
|
uint32_t group_weight;
|
2016-05-24 16:36:43 +02:00
|
|
|
// true if TLS is used in this backend
|
|
|
|
bool tls;
|
2016-12-04 15:43:41 +01:00
|
|
|
// true if dynamic DNS is enabled
|
|
|
|
bool dns;
|
2018-01-08 10:08:01 +01:00
|
|
|
// true if :scheme pseudo header field should be upgraded to secure
|
|
|
|
// variant (e.g., "https") when forwarding request to a backend
|
|
|
|
// connected by TLS connection.
|
|
|
|
bool upgrade_scheme;
|
2019-01-19 03:12:05 +01:00
|
|
|
// true if this address is queued.
|
|
|
|
bool queued;
|
2016-05-24 16:36:43 +02:00
|
|
|
};
|
|
|
|
|
2019-01-19 03:12:05 +01:00
|
|
|
constexpr uint32_t MAX_DOWNSTREAM_ADDR_WEIGHT = 256;
|
|
|
|
|
2019-01-21 16:01:17 +01:00
|
|
|
struct DownstreamAddrEntry {
|
|
|
|
DownstreamAddr *addr;
|
|
|
|
size_t seq;
|
|
|
|
uint32_t cycle;
|
|
|
|
};
|
2019-01-19 03:12:05 +01:00
|
|
|
|
2019-01-21 16:01:17 +01:00
|
|
|
struct DownstreamAddrEntryGreater {
|
|
|
|
bool operator()(const DownstreamAddrEntry &lhs,
|
|
|
|
const DownstreamAddrEntry &rhs) const {
|
|
|
|
auto d = lhs.cycle - rhs.cycle;
|
2019-01-19 03:12:05 +01:00
|
|
|
if (d == 0) {
|
2019-01-21 16:01:17 +01:00
|
|
|
return rhs.seq < lhs.seq;
|
2019-01-19 03:12:05 +01:00
|
|
|
}
|
2021-07-14 16:26:33 +02:00
|
|
|
return d <= 2 * MAX_DOWNSTREAM_ADDR_WEIGHT - 1;
|
2019-01-19 03:12:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WeightGroup {
|
2019-01-21 16:01:17 +01:00
|
|
|
std::priority_queue<DownstreamAddrEntry, std::vector<DownstreamAddrEntry>,
|
|
|
|
DownstreamAddrEntryGreater>
|
|
|
|
pq;
|
2019-01-19 03:12:05 +01:00
|
|
|
size_t seq;
|
2016-05-25 16:07:04 +02:00
|
|
|
uint32_t weight;
|
2019-01-19 03:12:05 +01:00
|
|
|
uint32_t cycle;
|
|
|
|
uint32_t pending_penalty;
|
|
|
|
// true if this object is queued.
|
|
|
|
bool queued;
|
2016-02-27 15:24:14 +01:00
|
|
|
};
|
|
|
|
|
2019-01-21 16:01:17 +01:00
|
|
|
struct WeightGroupEntry {
|
|
|
|
WeightGroup *wg;
|
|
|
|
size_t seq;
|
|
|
|
uint32_t cycle;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WeightGroupEntryGreater {
|
|
|
|
bool operator()(const WeightGroupEntry &lhs,
|
|
|
|
const WeightGroupEntry &rhs) const {
|
|
|
|
auto d = lhs.cycle - rhs.cycle;
|
|
|
|
if (d == 0) {
|
|
|
|
return rhs.seq < lhs.seq;
|
|
|
|
}
|
2021-07-14 16:26:33 +02:00
|
|
|
return d <= 2 * MAX_DOWNSTREAM_ADDR_WEIGHT - 1;
|
2019-01-21 16:01:17 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-22 15:51:00 +01:00
|
|
|
struct SharedDownstreamAddr {
|
2016-09-04 16:30:24 +02:00
|
|
|
SharedDownstreamAddr()
|
2016-10-02 09:18:35 +02:00
|
|
|
: balloc(1024, 1024),
|
2018-10-16 15:25:42 +02:00
|
|
|
affinity{SessionAffinity::NONE},
|
2019-09-21 06:45:20 +02:00
|
|
|
redirect_if_not_tls{false},
|
2021-09-05 17:12:04 +02:00
|
|
|
dnf{false},
|
2019-09-21 06:45:20 +02:00
|
|
|
timeout{} {}
|
2016-10-02 09:18:35 +02:00
|
|
|
|
|
|
|
SharedDownstreamAddr(const SharedDownstreamAddr &) = delete;
|
|
|
|
SharedDownstreamAddr(SharedDownstreamAddr &&) = delete;
|
|
|
|
SharedDownstreamAddr &operator=(const SharedDownstreamAddr &) = delete;
|
|
|
|
SharedDownstreamAddr &operator=(SharedDownstreamAddr &&) = delete;
|
|
|
|
|
|
|
|
BlockAllocator balloc;
|
2016-02-27 15:24:14 +01:00
|
|
|
std::vector<DownstreamAddr> addrs;
|
2019-01-19 03:12:05 +01:00
|
|
|
std::vector<WeightGroup> wgs;
|
2019-01-21 16:01:17 +01:00
|
|
|
std::priority_queue<WeightGroupEntry, std::vector<WeightGroupEntry>,
|
|
|
|
WeightGroupEntryGreater>
|
|
|
|
pq;
|
2016-07-06 15:31:28 +02:00
|
|
|
// Bunch of session affinity hash. Only used if affinity ==
|
2018-10-16 15:25:42 +02:00
|
|
|
// SessionAffinity::IP.
|
2016-07-06 15:31:28 +02:00
|
|
|
std::vector<AffinityHash> affinity_hash;
|
2019-09-16 15:25:06 +02:00
|
|
|
#ifdef HAVE_MRUBY
|
|
|
|
std::shared_ptr<mruby::MRubyContext> mruby_ctx;
|
|
|
|
#endif // HAVE_MRUBY
|
2017-10-25 17:45:22 +02:00
|
|
|
// Configuration for session affinity
|
|
|
|
AffinityConfig affinity;
|
2016-06-09 15:35:59 +02:00
|
|
|
// Session affinity
|
2017-02-18 10:23:06 +01:00
|
|
|
// true if this group requires that client connection must be TLS,
|
|
|
|
// and the request must be redirected to https URI.
|
|
|
|
bool redirect_if_not_tls;
|
2021-08-13 14:20:08 +02:00
|
|
|
// true if a request should not be forwarded to a backend.
|
|
|
|
bool dnf;
|
2018-09-30 05:23:34 +02:00
|
|
|
// Timeouts for backend connection.
|
|
|
|
struct {
|
|
|
|
ev_tstamp read;
|
|
|
|
ev_tstamp write;
|
|
|
|
} timeout;
|
2016-02-27 15:24:14 +01:00
|
|
|
};
|
2014-06-26 15:55:22 +02:00
|
|
|
|
2016-03-22 15:51:00 +01:00
|
|
|
struct DownstreamAddrGroup {
|
2018-08-21 14:11:07 +02:00
|
|
|
DownstreamAddrGroup();
|
|
|
|
~DownstreamAddrGroup();
|
2016-09-04 16:30:24 +02:00
|
|
|
|
2016-10-02 09:18:35 +02:00
|
|
|
DownstreamAddrGroup(const DownstreamAddrGroup &) = delete;
|
|
|
|
DownstreamAddrGroup(DownstreamAddrGroup &&) = delete;
|
|
|
|
DownstreamAddrGroup &operator=(const DownstreamAddrGroup &) = delete;
|
|
|
|
DownstreamAddrGroup &operator=(DownstreamAddrGroup &&) = delete;
|
|
|
|
|
2016-03-22 15:51:00 +01:00
|
|
|
ImmutableString pattern;
|
|
|
|
std::shared_ptr<SharedDownstreamAddr> shared_addr;
|
2016-06-04 05:16:31 +02:00
|
|
|
// true if this group is no longer used for new request. If this is
|
|
|
|
// true, the connection made using one of address in shared_addr
|
|
|
|
// must not be pooled.
|
|
|
|
bool retired;
|
2016-03-22 15:51:00 +01:00
|
|
|
};
|
|
|
|
|
2016-02-27 15:24:14 +01:00
|
|
|
struct WorkerStat {
|
2014-06-26 15:55:22 +02:00
|
|
|
size_t num_connections;
|
2021-09-05 11:01:27 +02:00
|
|
|
size_t num_close_waits;
|
2014-06-26 15:55:22 +02:00
|
|
|
};
|
|
|
|
|
2021-08-23 14:40:24 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
struct QUICPacket {
|
|
|
|
QUICPacket(size_t upstream_addr_index, const Address &remote_addr,
|
|
|
|
const Address &local_addr, const uint8_t *data, size_t datalen)
|
|
|
|
: upstream_addr_index{upstream_addr_index},
|
|
|
|
remote_addr{remote_addr},
|
|
|
|
local_addr{local_addr},
|
|
|
|
data{data, data + datalen} {}
|
2021-08-29 03:18:59 +02:00
|
|
|
QUICPacket() {}
|
2021-08-23 14:40:24 +02:00
|
|
|
size_t upstream_addr_index;
|
|
|
|
Address remote_addr;
|
|
|
|
Address local_addr;
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
};
|
|
|
|
#endif // ENABLE_HTTP3
|
|
|
|
|
2018-10-17 07:18:07 +02:00
|
|
|
enum class WorkerEventType {
|
2014-12-27 18:59:06 +01:00
|
|
|
NEW_CONNECTION = 0x01,
|
|
|
|
REOPEN_LOG = 0x02,
|
|
|
|
GRACEFUL_SHUTDOWN = 0x03,
|
2016-06-03 18:02:57 +02:00
|
|
|
REPLACE_DOWNSTREAM = 0x04,
|
2021-08-23 14:40:24 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
QUIC_PKT_FORWARD = 0x05,
|
|
|
|
#endif // ENABLE_HTTP3
|
2014-12-27 18:59:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct WorkerEvent {
|
|
|
|
WorkerEventType type;
|
2015-01-08 13:15:45 +01:00
|
|
|
struct {
|
|
|
|
sockaddr_union client_addr;
|
|
|
|
size_t client_addrlen;
|
|
|
|
int client_fd;
|
2016-02-07 09:51:53 +01:00
|
|
|
const UpstreamAddr *faddr;
|
2014-12-27 18:59:06 +01:00
|
|
|
};
|
2015-01-08 13:15:45 +01:00
|
|
|
std::shared_ptr<TicketKeys> ticket_keys;
|
2016-06-03 18:02:57 +02:00
|
|
|
std::shared_ptr<DownstreamConfig> downstreamconf;
|
2021-08-23 14:40:24 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
std::unique_ptr<QUICPacket> quic_pkt;
|
|
|
|
#endif // ENABLE_HTTP3
|
2014-12-27 18:59:06 +01:00
|
|
|
};
|
|
|
|
|
2012-06-05 18:26:04 +02:00
|
|
|
class Worker {
|
|
|
|
public:
|
2015-02-11 11:18:41 +01:00
|
|
|
Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx,
|
2016-02-11 14:56:45 +01:00
|
|
|
SSL_CTX *tls_session_cache_memcached_ssl_ctx,
|
2021-08-21 12:00:43 +02:00
|
|
|
tls::CertLookupTree *cert_tree,
|
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
SSL_CTX *quic_sv_ssl_ctx, tls::CertLookupTree *quic_cert_tree,
|
2021-08-23 14:40:24 +02:00
|
|
|
const uint8_t *cid_prefix, size_t cid_prefixlen,
|
2021-08-24 14:13:05 +02:00
|
|
|
# ifdef HAVE_LIBBPF
|
|
|
|
size_t index,
|
|
|
|
# endif // HAVE_LIBBPF
|
|
|
|
#endif // ENABLE_HTTP3
|
2016-06-03 18:02:57 +02:00
|
|
|
const std::shared_ptr<TicketKeys> &ticket_keys,
|
|
|
|
ConnectionHandler *conn_handler,
|
2017-03-26 14:14:34 +02:00
|
|
|
std::shared_ptr<DownstreamConfig> downstreamconf);
|
2012-06-05 18:26:04 +02:00
|
|
|
~Worker();
|
2015-02-11 11:18:41 +01:00
|
|
|
void run_async();
|
2014-12-27 18:59:06 +01:00
|
|
|
void wait();
|
|
|
|
void process_events();
|
2021-08-23 14:40:24 +02:00
|
|
|
void send(WorkerEvent event);
|
2014-11-27 15:39:04 +01:00
|
|
|
|
2017-04-01 08:07:32 +02:00
|
|
|
tls::CertLookupTree *get_cert_lookup_tree() const;
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2021-08-16 08:11:18 +02:00
|
|
|
tls::CertLookupTree *get_quic_cert_lookup_tree() const;
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2015-07-23 16:13:29 +02:00
|
|
|
|
|
|
|
// These 2 functions make a lock m_ to get/set ticket keys
|
|
|
|
// atomically.
|
|
|
|
std::shared_ptr<TicketKeys> get_ticket_keys();
|
2015-02-11 11:18:41 +01:00
|
|
|
void set_ticket_keys(std::shared_ptr<TicketKeys> ticket_keys);
|
2015-07-23 16:13:29 +02:00
|
|
|
|
2015-02-11 11:18:41 +01:00
|
|
|
WorkerStat *get_worker_stat();
|
|
|
|
struct ev_loop *get_loop() const;
|
|
|
|
SSL_CTX *get_sv_ssl_ctx() const;
|
2015-03-10 13:54:29 +01:00
|
|
|
SSL_CTX *get_cl_ssl_ctx() const;
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2021-08-16 08:11:18 +02:00
|
|
|
SSL_CTX *get_quic_sv_ssl_ctx() const;
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2015-02-11 11:18:41 +01:00
|
|
|
|
2015-02-25 14:53:23 +01:00
|
|
|
void set_graceful_shutdown(bool f);
|
|
|
|
bool get_graceful_shutdown() const;
|
|
|
|
|
2015-04-07 15:13:01 +02:00
|
|
|
MemchunkPool *get_mcpool();
|
2015-04-08 06:43:57 +02:00
|
|
|
void schedule_clear_mcpool();
|
2015-04-07 15:13:01 +02:00
|
|
|
|
2015-07-25 15:22:17 +02:00
|
|
|
MemcachedDispatcher *get_session_cache_memcached_dispatcher();
|
|
|
|
|
2016-01-15 15:04:58 +01:00
|
|
|
std::mt19937 &get_randgen();
|
|
|
|
|
2015-09-03 17:54:41 +02:00
|
|
|
#ifdef HAVE_MRUBY
|
2015-09-01 17:19:32 +02:00
|
|
|
int create_mruby_context();
|
|
|
|
|
|
|
|
mruby::MRubyContext *get_mruby_context() const;
|
2015-09-03 17:54:41 +02:00
|
|
|
#endif // HAVE_MRUBY
|
2015-09-01 17:19:32 +02:00
|
|
|
|
2016-06-02 18:20:49 +02:00
|
|
|
std::vector<std::shared_ptr<DownstreamAddrGroup>> &
|
|
|
|
get_downstream_addr_groups();
|
2016-02-21 06:53:06 +01:00
|
|
|
|
2016-02-21 07:27:19 +01:00
|
|
|
ConnectBlocker *get_connect_blocker() const;
|
|
|
|
|
2016-06-03 12:13:02 +02:00
|
|
|
const DownstreamConfig *get_downstream_config() const;
|
|
|
|
|
2016-06-03 18:02:57 +02:00
|
|
|
void
|
|
|
|
replace_downstream_config(std::shared_ptr<DownstreamConfig> downstreamconf);
|
|
|
|
|
|
|
|
ConnectionHandler *get_connection_handler() const;
|
2016-06-02 18:20:49 +02:00
|
|
|
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2021-08-16 08:11:18 +02:00
|
|
|
QUICConnectionHandler *get_quic_connection_handler();
|
|
|
|
|
2021-08-15 05:22:10 +02:00
|
|
|
int setup_quic_server_socket();
|
2021-08-23 14:40:24 +02:00
|
|
|
|
|
|
|
const uint8_t *get_cid_prefix() const;
|
2021-08-24 14:13:05 +02:00
|
|
|
|
|
|
|
# ifdef HAVE_LIBBPF
|
|
|
|
bool should_attach_bpf() const;
|
|
|
|
|
|
|
|
bool should_update_bpf_map() const;
|
|
|
|
|
|
|
|
uint32_t compute_sk_index() const;
|
|
|
|
# endif // HAVE_LIBBPF
|
|
|
|
|
|
|
|
int create_quic_server_socket(UpstreamAddr &addr);
|
2021-08-29 03:18:59 +02:00
|
|
|
|
|
|
|
// Returns a pointer to UpstreamAddr which matches |local_addr|.
|
|
|
|
const UpstreamAddr *find_quic_upstream_addr(const Address &local_addr);
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
|
|
|
|
|
|
|
DNSTracker *get_dns_tracker();
|
2021-08-15 05:22:10 +02:00
|
|
|
|
2012-06-05 18:26:04 +02:00
|
|
|
private:
|
2014-12-27 18:59:06 +01:00
|
|
|
#ifndef NOTHREADS
|
|
|
|
std::future<void> fut_;
|
|
|
|
#endif // NOTHREADS
|
2021-08-24 14:13:05 +02:00
|
|
|
#if defined(ENABLE_HTTP3) && defined(HAVE_LIBBPF)
|
|
|
|
// Unique index of this worker.
|
|
|
|
size_t index_;
|
|
|
|
#endif // ENABLE_HTTP3 && HAVE_LIBBPF
|
2014-12-27 18:59:06 +01:00
|
|
|
std::mutex m_;
|
2016-06-25 04:50:33 +02:00
|
|
|
std::deque<WorkerEvent> q_;
|
2016-01-15 15:04:58 +01:00
|
|
|
std::mt19937 randgen_;
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_async w_;
|
2015-04-08 06:43:57 +02:00
|
|
|
ev_timer mcpool_clear_timer_;
|
2016-06-25 04:50:33 +02:00
|
|
|
ev_timer proc_wev_timer_;
|
2015-04-07 15:13:01 +02:00
|
|
|
MemchunkPool mcpool_;
|
2015-02-11 11:18:41 +01:00
|
|
|
WorkerStat worker_stat_;
|
2016-12-04 15:43:41 +01:00
|
|
|
DNSTracker dns_tracker_;
|
2016-02-07 08:52:40 +01:00
|
|
|
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2021-08-23 14:40:24 +02:00
|
|
|
std::array<uint8_t, SHRPX_QUIC_CID_PREFIXLEN> cid_prefix_;
|
2021-08-15 05:22:10 +02:00
|
|
|
std::vector<UpstreamAddr> quic_upstream_addrs_;
|
2021-08-15 09:57:39 +02:00
|
|
|
std::vector<std::unique_ptr<QUICListener>> quic_listeners_;
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2021-08-15 05:22:10 +02:00
|
|
|
|
2016-06-03 12:13:02 +02:00
|
|
|
std::shared_ptr<DownstreamConfig> downstreamconf_;
|
2015-07-25 15:22:17 +02:00
|
|
|
std::unique_ptr<MemcachedDispatcher> session_cache_memcached_dispatcher_;
|
2015-09-03 17:54:41 +02:00
|
|
|
#ifdef HAVE_MRUBY
|
2015-09-01 17:19:32 +02:00
|
|
|
std::unique_ptr<mruby::MRubyContext> mruby_ctx_;
|
2015-09-03 17:54:41 +02:00
|
|
|
#endif // HAVE_MRUBY
|
2014-12-27 18:59:06 +01:00
|
|
|
struct ev_loop *loop_;
|
2015-02-11 11:18:41 +01:00
|
|
|
|
|
|
|
// Following fields are shared across threads if
|
|
|
|
// get_config()->tls_ctx_per_worker == true.
|
2013-02-07 13:13:36 +01:00
|
|
|
SSL_CTX *sv_ssl_ctx_;
|
|
|
|
SSL_CTX *cl_ssl_ctx_;
|
2017-04-01 08:07:32 +02:00
|
|
|
tls::CertLookupTree *cert_tree_;
|
2016-06-03 18:02:57 +02:00
|
|
|
ConnectionHandler *conn_handler_;
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2021-08-16 08:11:18 +02:00
|
|
|
SSL_CTX *quic_sv_ssl_ctx_;
|
|
|
|
tls::CertLookupTree *quic_cert_tree_;
|
|
|
|
|
|
|
|
QUICConnectionHandler quic_conn_handler_;
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2015-02-11 11:18:41 +01:00
|
|
|
|
2016-09-20 15:24:12 +02:00
|
|
|
#ifndef HAVE_ATOMIC_STD_SHARED_PTR
|
|
|
|
std::mutex ticket_keys_m_;
|
|
|
|
#endif // !HAVE_ATOMIC_STD_SHARED_PTR
|
2015-02-11 11:18:41 +01:00
|
|
|
std::shared_ptr<TicketKeys> ticket_keys_;
|
2016-06-02 18:20:49 +02:00
|
|
|
std::vector<std::shared_ptr<DownstreamAddrGroup>> downstream_addr_groups_;
|
2016-02-21 07:27:19 +01:00
|
|
|
// Worker level blocker for downstream connection. For example,
|
|
|
|
// this is used when file decriptor is exhausted.
|
|
|
|
std::unique_ptr<ConnectBlocker> connect_blocker_;
|
2015-02-25 14:53:23 +01:00
|
|
|
|
|
|
|
bool graceful_shutdown_;
|
2012-06-05 18:26:04 +02:00
|
|
|
};
|
|
|
|
|
2016-02-27 15:24:14 +01:00
|
|
|
// Selects group based on request's |hostport| and |path|. |hostport|
|
|
|
|
// is the value taken from :authority or host header field, and may
|
|
|
|
// contain port. The |path| may contain query part. We require the
|
|
|
|
// catch-all pattern in place, so this function always selects one
|
|
|
|
// group. The catch-all group index is given in |catch_all|. All
|
|
|
|
// patterns are given in |groups|.
|
|
|
|
size_t match_downstream_addr_group(
|
2016-06-11 11:21:37 +02:00
|
|
|
const RouterConfig &routerconfig, const StringRef &hostport,
|
|
|
|
const StringRef &path,
|
2016-06-02 18:20:49 +02:00
|
|
|
const std::vector<std::shared_ptr<DownstreamAddrGroup>> &groups,
|
2016-06-11 11:41:43 +02:00
|
|
|
size_t catch_all, BlockAllocator &balloc);
|
2016-02-27 15:24:14 +01:00
|
|
|
|
2016-12-04 15:43:41 +01:00
|
|
|
// Calls this function if connecting to backend failed. |raddr| is
|
|
|
|
// the actual address used to connect to backend, and it could be
|
|
|
|
// nullptr. This function may schedule live check.
|
|
|
|
void downstream_failure(DownstreamAddr *addr, const Address *raddr);
|
2016-04-07 18:04:16 +02:00
|
|
|
|
2021-08-23 14:40:24 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
// Creates unpredictable SHRPX_QUIC_CID_PREFIXLEN bytes sequence which
|
|
|
|
// is used as a prefix of QUIC Connection ID. This function returns
|
2021-09-21 15:46:32 +02:00
|
|
|
// -1 on failure. |server_id| must be 2 bytes long.
|
|
|
|
int create_cid_prefix(uint8_t *cid_prefix, const uint8_t *server_id);
|
2021-08-23 14:40:24 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
|
|
|
|
2012-06-05 18:26:04 +02:00
|
|
|
} // namespace shrpx
|
|
|
|
|
|
|
|
#endif // SHRPX_WORKER_H
|