summaryrefslogtreecommitdiff
path: root/src/cluster.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-07-27 10:46:31 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:11:44 +0800
commit1234e3a5628260658adfe9065cb58ec5c1cb5ebe (patch)
tree98275a38f8d2938d7438c422371c758f28645d9a /src/cluster.c
parentc4c02f80365e5f7a82efa6a4d4f247503f54a5d8 (diff)
downloadredis-1234e3a5628260658adfe9065cb58ec5c1cb5ebe.tar.gz
Fully abstract connection type
Abstract common interface of connection type, so Redis can hide the implementation and uplayer only calls connection API without macro. uplayer | connection layer / \ socket TLS Currently, for both socket and TLS, all the methods of connection type are declared as static functions. It's possible to build TLS(even socket) as a shared library, and Redis loads it dynamically in the next step. Also add helper function connTypeOfCluster() and connTypeOfReplication() to simplify the code: link->conn = server.tls_cluster ? connCreateTLS() : connCreateSocket(); -> link->conn = connCreate(connTypeOfCluster()); Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/cluster.c')
-rw-r--r--src/cluster.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/cluster.c b/src/cluster.c
index a7d6f6205..b60b79153 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -119,6 +119,14 @@ dictType clusterNodesBlackListDictType = {
NULL /* allow to expand */
};
+static int connTypeOfCluster() {
+ if (server.tls_cluster) {
+ return CONN_TYPE_TLS;
+ }
+
+ return CONN_TYPE_SOCKET;
+}
+
/* -----------------------------------------------------------------------------
* Initialization
* -------------------------------------------------------------------------- */
@@ -865,6 +873,7 @@ void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
int cport, cfd;
int max = MAX_CLUSTER_ACCEPTS_PER_CALL;
char cip[NET_IP_STR_LEN];
+ int require_auth = TLS_CLIENT_AUTH_YES;
UNUSED(el);
UNUSED(mask);
UNUSED(privdata);
@@ -882,8 +891,7 @@ void clusterAcceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
return;
}
- connection *conn = server.tls_cluster ?
- connCreateAcceptedTLS(cfd, TLS_CLIENT_AUTH_YES) : connCreateAcceptedSocket(cfd);
+ connection *conn = connCreateAccepted(connTypeOfCluster(), cfd, &require_auth);
/* Make sure connection is not in an error state */
if (connGetState(conn) != CONN_STATE_ACCEPTING) {
@@ -3969,7 +3977,7 @@ static int clusterNodeCronHandleReconnect(clusterNode *node, mstime_t handshake_
if (node->link == NULL) {
clusterLink *link = createClusterLink(node);
- link->conn = server.tls_cluster ? connCreateTLS() : connCreateSocket();
+ link->conn = connCreate(connTypeOfCluster());
connSetPrivateData(link->conn, link);
if (connConnect(link->conn, node->ip, node->cport, server.bind_source_addr,
clusterLinkConnectHandler) == -1) {
@@ -6175,8 +6183,8 @@ migrateCachedSocket* migrateGetSocket(client *c, robj *host, robj *port, long ti
dictDelete(server.migrate_cached_sockets,dictGetKey(de));
}
- /* Create the socket */
- conn = server.tls_cluster ? connCreateTLS() : connCreateSocket();
+ /* Create the connection */
+ conn = connCreate(connTypeOfCluster());
if (connBlockingConnect(conn, host->ptr, atoi(port->ptr), timeout)
!= C_OK) {
addReplyError(c,"-IOERR error or timeout connecting to the client");