Mercurial > dovecot > core-2.2
changeset 19186:b4a1e4d085e2
lib-http: client: Improved hash function for peer addresses.
author | Stephan Bosch <stephan@rename-it.nl> |
---|---|
date | Tue, 22 Sep 2015 21:15:45 +0300 |
parents | 8166cb1a32ba |
children | 1b1dbfaf7daa |
files | src/lib-http/http-client-peer.c |
diffstat | 1 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/http-client-peer.c Tue Sep 22 16:40:58 2015 +0300 +++ b/src/lib-http/http-client-peer.c Tue Sep 22 21:15:45 2015 +0300 @@ -43,21 +43,25 @@ 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