r3955 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Thu Mar 19 11:00:39 CET 2009
Author: phk
Date: 2009-03-19 11:00:39 +0100 (Thu, 19 Mar 2009)
New Revision: 3955
Modified:
trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
Log:
Replace crc32 with sha256, the cost here is epsilon
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-03-18 13:53:21 UTC (rev 3954)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-03-19 10:00:39 UTC (rev 3955)
@@ -45,6 +45,7 @@
#include "shmlog.h"
#include "cache.h"
#include "vrt.h"
+#include "vsha256.h"
#include "cache_backend.h"
#include "cli_priv.h"
@@ -171,6 +172,8 @@
{
struct backend *b;
uint32_t u;
+ struct SHA256Context ctx;
+ uint8_t hash[SHA256_LEN];
AN(vb->ident);
assert(vb->ipv4_sockaddr != NULL || vb->ipv6_sockaddr != NULL);
@@ -178,12 +181,18 @@
ASSERT_CLI();
/* calculate a hash of (ident + ipv4_sockaddr + ipv6_sockaddr) */
- u = crc32(~0U, vb->ident, strlen(vb->ident));
+ SHA256_Init(&ctx);
+ SHA256_Update(&ctx, vb->ident, strlen(vb->ident));
if (vb->ipv4_sockaddr != NULL)
- u = crc32(u, vb->ipv4_sockaddr + 1, vb->ipv4_sockaddr[0]);
+ SHA256_Update(&ctx,
+ vb->ipv4_sockaddr + 1, vb->ipv4_sockaddr[0]);
if (vb->ipv6_sockaddr != NULL)
- u = crc32(u, vb->ipv6_sockaddr + 1, vb->ipv6_sockaddr[0]);
+ SHA256_Update(&ctx,
+ vb->ipv6_sockaddr + 1, vb->ipv6_sockaddr[0]);
+ SHA256_Final(hash, &ctx);
+ memcpy(&u, hash, sizeof u);
+
/* Run through the list and see if we already have this backend */
VTAILQ_FOREACH(b, &backends, list) {
CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
More information about the varnish-commit
mailing list