From bff7ecc7864716c14fbb399f19acaee364975b29 Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Wed, 27 Jul 2022 10:08:32 +0800 Subject: 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 --- src/cluster.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cluster.c') 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); -- cgit v1.2.1