From: Stephan Bosch Date: Tue, 22 Sep 2015 18:15:45 +0000 (+0300) Subject: lib-http: client: Improved hash function for peer addresses. X-Git-Tag: 2.2.19.rc1~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b572cf527dc0d9d9c7344041e50aef16f419571;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client: Improved hash function for peer addresses. --- diff --git a/src/lib-http/http-client-peer.c b/src/lib-http/http-client-peer.c index 3513c44434..9310f9eda6 100644 --- a/src/lib-http/http-client-peer.c +++ b/src/lib-http/http-client-peer.c @@ -43,21 +43,25 @@ http_client_peer_debug(struct http_client_peer *peer, unsigned int http_client_peer_addr_hash (const struct http_client_peer_addr *peer) { + unsigned int hash = (unsigned int)peer->type; + switch (peer->type) { - case HTTP_CLIENT_PEER_ADDR_RAW: - return net_ip_hash(&peer->a.tcp.ip) + peer->a.tcp.port + 1; - case HTTP_CLIENT_PEER_ADDR_HTTP: - return net_ip_hash(&peer->a.tcp.ip) + peer->a.tcp.port; case HTTP_CLIENT_PEER_ADDR_HTTPS: case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL: - return net_ip_hash(&peer->a.tcp.ip) + peer->a.tcp.port + - (peer->a.tcp.https_name == NULL ? - 0 : str_hash(peer->a.tcp.https_name)); + if (peer->a.tcp.https_name != NULL) + hash += str_hash(peer->a.tcp.https_name); + /* fall through */ + case HTTP_CLIENT_PEER_ADDR_RAW: + case HTTP_CLIENT_PEER_ADDR_HTTP: + hash += net_ip_hash(&peer->a.tcp.ip); + hash += peer->a.tcp.port; + break; case HTTP_CLIENT_PEER_ADDR_UNIX: - return str_hash(peer->a.un.path); + hash += str_hash(peer->a.un.path); + break; } - i_unreached(); - return 0; + + return hash; } int http_client_peer_addr_cmp