r3444 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Nov 25 17:04:47 CET 2008


Author: phk
Date: 2008-11-25 17:04:47 +0100 (Tue, 25 Nov 2008)
New Revision: 3444

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Add code to calculate a SHA256 over the hash string if param hash_sha256
is set.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-11-25 14:09:39 UTC (rev 3443)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-11-25 16:04:47 UTC (rev 3444)
@@ -93,6 +93,8 @@
 struct vrt_backend;
 struct cli_proto;
 struct ban;
+struct SHA256Context;
+
 struct lock { void *priv; };		// Opaque
 
 /*--------------------------------------------------------------------*/
@@ -202,6 +204,8 @@
 
 	unsigned char		*wlb, *wlp, *wle;
 	unsigned		wlr;
+
+	struct SHA256Context	*sha256ctx;
 };
 
 /* Work Request for worker thread ------------------------------------*/

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-11-25 14:09:39 UTC (rev 3443)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-11-25 16:04:47 UTC (rev 3444)
@@ -66,6 +66,7 @@
 #include "cache.h"
 #include "stevedore.h"
 #include "hash_slinger.h"
+#include "vsha256.h"
 
 static const struct hash_slinger *hash;
 
@@ -219,6 +220,8 @@
 	if (u)
 		p += sizeof(const char *) - u;
 	sp->hashptr = (void*)p;
+	if (params->hash_sha256)
+		SHA256_Init(sp->wrk->sha256ctx);
 }
 
 void
@@ -241,6 +244,10 @@
 	sp->hashptr[sp->ihashptr + 1] = str + l;
 	sp->ihashptr += 2;
 	sp->lhashptr += l + 1;
+	if (params->hash_sha256) {
+		SHA256_Update(sp->wrk->sha256ctx, str, l);
+		SHA256_Update(sp->wrk->sha256ctx, "#", 1);
+	}
 }
 
 struct object *
@@ -250,6 +257,7 @@
 	struct http *h;
 	struct objhead *oh;
 	struct object *o, *busy_o, *grace_o;
+	unsigned char sha256[32];
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
@@ -257,6 +265,10 @@
 	AN(hash);
 	w = sp->wrk;
 	h = sp->http;
+	if (params->hash_sha256) {
+		SHA256_Final(sha256, sp->wrk->sha256ctx);
+		/* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */
+	}
 
 	HSH_Prealloc(sp);
 	if (sp->objhead != NULL) {

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2008-11-25 14:09:39 UTC (rev 3443)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2008-11-25 16:04:47 UTC (rev 3444)
@@ -72,6 +72,7 @@
 #include "cache.h"
 #include "stevedore.h"
 #include "hash_slinger.h"
+#include "vsha256.h"
 
 VTAILQ_HEAD(workerhead, worker);
 
@@ -269,6 +270,7 @@
 	struct worker *w, ww;
 	struct wq *qp;
 	unsigned char wlog[params->shm_workspace];
+	struct SHA256Context sha256;
 
 	THR_SetName("cache-worker");
 	w = &ww;
@@ -278,6 +280,7 @@
 	w->lastused = NAN;
 	w->wlb = w->wlp = wlog;
 	w->wle = wlog + sizeof wlog;
+	w->sha256ctx = &sha256;
 	AZ(pthread_cond_init(&w->cond, NULL));
 
 	VSL(SLT_WorkThread, 0, "%p start", w);



More information about the varnish-commit mailing list