From e35eca8790c9669cb4f9cd71a2796b53f0f67bf2 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 25 Nov 2008 16:04:47 +0000 Subject: [PATCH] Add code to calculate a SHA256 over the hash string if param hash_sha256 is set. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3444 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 4 ++++ varnish-cache/bin/varnishd/cache_hash.c | 12 ++++++++++++ varnish-cache/bin/varnishd/cache_pool.c | 3 +++ 3 files changed, 19 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 67586722..58f50063 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -93,6 +93,8 @@ struct esi_bit; struct vrt_backend; struct cli_proto; struct ban; +struct SHA256Context; + struct lock { void *priv; }; // Opaque /*--------------------------------------------------------------------*/ @@ -202,6 +204,8 @@ struct worker { unsigned char *wlb, *wlp, *wle; unsigned wlr; + + struct SHA256Context *sha256ctx; }; /* Work Request for worker thread ------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index d299bfd7..a6d66ab4 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -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 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount) 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 @@ HSH_AddString(struct sess *sp, const char *str) 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 @@ HSH_Lookup(struct sess *sp) 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 @@ HSH_Lookup(struct sess *sp) 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) { diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 040d4cf8..3fe9a6e5 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -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 @@ wrk_thread(void *priv) 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 @@ wrk_thread(void *priv) 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); -- 2.39.5