]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Improved hash function for peer addresses.
authorStephan Bosch <stephan@rename-it.nl>
Tue, 22 Sep 2015 18:15:45 +0000 (21:15 +0300)
committerStephan Bosch <stephan@rename-it.nl>
Tue, 22 Sep 2015 18:15:45 +0000 (21:15 +0300)
src/lib-http/http-client-peer.c

index 3513c44434074968402fdc2de9b029198e392c6e..9310f9eda6a2352b2e09e54e2ce284f18b71fd98 100644 (file)
@@ -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