summaryrefslogtreecommitdiff
path: root/src/cluster.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-07-27 10:08:32 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:01:40 +0800
commitbff7ecc7864716c14fbb399f19acaee364975b29 (patch)
tree7f342f044ee6e39769b55e1a1754abb4ffc39dac /src/cluster.c
parentb9d77288243aeab306b99ff72a71d8490a91e0a8 (diff)
downloadredis-bff7ecc7864716c14fbb399f19acaee364975b29.tar.gz
Introduce connAddr
Originally, connPeerToString is designed to get the address info from socket only(for both TCP & TLS), and the API 'connPeerToString' is oriented to operate a FD like: int connPeerToString(connection *conn, char *ip, size_t ip_len, int *port) { return anetFdToString(conn ? conn->fd : -1, ip, ip_len, port, FD_TO_PEER_NAME); } Introduce connAddr and implement .addr method for socket and TLS, thus the API 'connAddr' and 'connFormatAddr' become oriented to a connection like: static inline int connAddr(connection *conn, char *ip, size_t ip_len, int *port, int remote) { if (conn && conn->type->addr) { return conn->type->addr(conn, ip, ip_len, port, remote); } return -1; } Also remove 'FD_TO_PEER_NAME' & 'FD_TO_SOCK_NAME', use a boolean type 'remote' to get local/remote address of a connection. With these changes, it's possible to support the other connection types which does not use socket(Ex, RDMA). Thanks to Oran for suggestions! Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/cluster.c')
-rw-r--r--src/cluster.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/cluster.c b/src/cluster.c
index c739a3892..a7d6f6205 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -1769,7 +1769,7 @@ int nodeIp2String(char *buf, clusterLink *link, char *announced_ip) {
buf[NET_IP_STR_LEN-1] = '\0'; /* We are not sure the input is sane. */
return C_OK;
} else {
- if (connPeerToString(link->conn, buf, NET_IP_STR_LEN, NULL) == C_ERR) {
+ if (connAddrPeerName(link->conn, buf, NET_IP_STR_LEN, NULL) == C_ERR) {
serverLog(LL_NOTICE, "Error converting peer IP to string: %s",
link->conn ? connGetLastError(link->conn) : "no link");
return C_ERR;
@@ -2273,7 +2273,7 @@ int clusterProcessPacket(clusterLink *link) {
{
char ip[NET_IP_STR_LEN];
- if (connSockName(link->conn,ip,sizeof(ip),NULL) != -1 &&
+ if (connAddrSockName(link->conn,ip,sizeof(ip),NULL) != -1 &&
strcmp(ip,myself->ip))
{
memcpy(myself->ip,ip,NET_IP_STR_LEN);