diff options
author | zhenwei pi <pizhenwei@bytedance.com> | 2022-07-27 10:08:32 +0800 |
---|---|---|
committer | zhenwei pi <pizhenwei@bytedance.com> | 2022-08-22 15:01:40 +0800 |
commit | bff7ecc7864716c14fbb399f19acaee364975b29 (patch) | |
tree | 7f342f044ee6e39769b55e1a1754abb4ffc39dac /src/replication.c | |
parent | b9d77288243aeab306b99ff72a71d8490a91e0a8 (diff) | |
download | redis-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/replication.c')
-rw-r--r-- | src/replication.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/replication.c b/src/replication.c index 58ed10833..3ae130252 100644 --- a/src/replication.c +++ b/src/replication.c @@ -33,6 +33,7 @@ #include "cluster.h" #include "bio.h" #include "functions.h" +#include "connection.h" #include <memory.h> #include <sys/time.h> @@ -66,11 +67,11 @@ char *replicationGetSlaveName(client *c) { ip[0] = '\0'; buf[0] = '\0'; if (c->slave_addr || - connPeerToString(c->conn,ip,sizeof(ip),NULL) != -1) + connAddrPeerName(c->conn,ip,sizeof(ip),NULL) != -1) { char *addr = c->slave_addr ? c->slave_addr : ip; if (c->slave_listening_port) - anetFormatAddr(buf,sizeof(buf),addr,c->slave_listening_port); + formatAddr(buf,sizeof(buf),addr,c->slave_listening_port); else snprintf(buf,sizeof(buf),"%s:<unknown-replica-port>",addr); } else { @@ -3156,7 +3157,7 @@ void roleCommand(client *c) { char ip[NET_IP_STR_LEN], *slaveaddr = slave->slave_addr; if (!slaveaddr) { - if (connPeerToString(slave->conn,ip,sizeof(ip),NULL) == -1) + if (connAddrPeerName(slave->conn,ip,sizeof(ip),NULL) == -1) continue; slaveaddr = ip; } @@ -3817,7 +3818,7 @@ static client *findReplica(char *host, int port) { char ip[NET_IP_STR_LEN], *replicaip = replica->slave_addr; if (!replicaip) { - if (connPeerToString(replica->conn, ip, sizeof(ip), NULL) == -1) + if (connAddrPeerName(replica->conn, ip, sizeof(ip), NULL) == -1) continue; replicaip = ip; } @@ -4048,7 +4049,7 @@ void updateFailoverStatus(void) { char ip[NET_IP_STR_LEN], *replicaaddr = replica->slave_addr; if (!replicaaddr) { - if (connPeerToString(replica->conn,ip,sizeof(ip),NULL) == -1) + if (connAddrPeerName(replica->conn,ip,sizeof(ip),NULL) == -1) continue; replicaaddr = ip; } |