summaryrefslogtreecommitdiff
path: root/src/tls.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/tls.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/tls.c')
-rw-r--r--src/tls.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/tls.c b/src/tls.c
index 019f5a9d8..442824dcd 100644
--- a/src/tls.c
+++ b/src/tls.c
@@ -718,6 +718,10 @@ static void tlsEventHandler(struct aeEventLoop *el, int fd, void *clientData, in
tlsHandleEvent(conn, mask);
}
+static int connTLSAddr(connection *conn, char *ip, size_t ip_len, int *port, int remote) {
+ return anetFdToString(conn->fd, ip, ip_len, port, remote);
+}
+
static void connTLSClose(connection *conn_) {
tls_connection *conn = (tls_connection *) conn_;
@@ -1064,6 +1068,7 @@ ConnectionType CT_TLS = {
/* ae & accept & listen & error & address handler */
.ae_handler = tlsEventHandler,
+ .addr = connTLSAddr,
/* create/close connection */
.close = connTLSClose,