mmap() ToS/PP and pre-compute compressed replies (fixes #6199)

This commit is contained in:
Christian Grothoff 2020-07-21 21:27:08 +02:00
parent d9e871b523
commit 6d52922c22
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 57 additions and 44 deletions

View File

@ -38,7 +38,8 @@ struct Terms
const char *mime_type; const char *mime_type;
/** /**
* The terms (NOT 0-terminated!). * The terms (NOT 0-terminated!), mmap()'ed. Do not free,
* use munmap() instead.
*/ */
void *terms; void *terms;
@ -47,10 +48,23 @@ struct Terms
*/ */
char *language; char *language;
/**
* deflated @e terms, to return if client supports deflate compression.
* malloc()'ed. NULL if @e terms does not compress.
*/
void *compressed_terms;
/** /**
* Number of bytes in @e terms. * Number of bytes in @e terms.
*/ */
size_t terms_size; size_t terms_size;
/**
* Number of bytes in @e compressed_terms.
*/
size_t compressed_terms_size;
}; };
@ -290,16 +304,9 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
if (MHD_YES == if (MHD_YES ==
TALER_MHD_can_compress (conn)) TALER_MHD_can_compress (conn))
{ {
void *buf = GNUNET_memdup (t->terms, resp = MHD_create_response_from_buffer (t->compressed_terms_size,
t->terms_size); t->compressed_terms,
size_t buf_size = t->terms_size; MHD_RESPMEM_PERSISTENT);
if (TALER_MHD_body_compress (&buf,
&buf_size))
{
resp = MHD_create_response_from_buffer (buf_size,
buf,
MHD_RESPMEM_MUST_FREE);
if (MHD_NO == if (MHD_NO ==
MHD_add_response_header (resp, MHD_add_response_header (resp,
MHD_HTTP_HEADER_CONTENT_ENCODING, MHD_HTTP_HEADER_CONTENT_ENCODING,
@ -310,11 +317,6 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
resp = NULL; resp = NULL;
} }
} }
else
{
GNUNET_free (buf);
}
}
if (NULL == resp) if (NULL == resp)
{ {
/* could not generate compressed response, return uncompressed */ /* could not generate compressed response, return uncompressed */
@ -458,31 +460,22 @@ load_terms (struct TALER_MHD_Legal *legal,
return; return;
} }
{ {
char *buf; void *buf;
size_t bsize; size_t bsize;
ssize_t ret;
bsize = (size_t) st.st_size; bsize = (size_t) st.st_size;
buf = GNUNET_malloc_large (bsize); buf = mmap (NULL,
if (NULL == buf) bsize,
{ PROT_READ,
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, MAP_SHARED,
"malloc"); fd,
GNUNET_break (0 == close (fd)); 0);
GNUNET_free (fn); if (MAP_FAILED == buf)
return;
}
ret = read (fd,
buf,
bsize);
if ( (ret < 0) ||
(bsize != ((size_t) ret)) )
{ {
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
"read", "mmap",
fn); fn);
GNUNET_break (0 == close (fd)); GNUNET_break (0 == close (fd));
GNUNET_free (buf);
GNUNET_free (fn); GNUNET_free (fn);
return; return;
} }
@ -498,6 +491,18 @@ load_terms (struct TALER_MHD_Legal *legal,
.terms_size = bsize .terms_size = bsize
}; };
buf = GNUNET_memdup (t.terms,
t.terms_size);
if (TALER_MHD_body_compress (&buf,
&bsize))
{
t.compressed_terms = buf;
t.compressed_terms_size = bsize;
}
else
{
GNUNET_free (buf);
}
GNUNET_array_append (legal->terms, GNUNET_array_append (legal->terms,
legal->terms_len, legal->terms_len,
t); t);
@ -554,8 +559,7 @@ load_language (struct TALER_MHD_Legal *legal,
* *
* @param cfg configuration to use * @param cfg configuration to use
* @param section section to load values from * @param section section to load values from
* @param diroption name of the option with the * @param diroption name of the option with the path to the legal documents
* path to the legal documents
* @param tagoption name of the files to use * @param tagoption name of the files to use
* for the legal documents and the Etag * for the legal documents and the Etag
* @return NULL on error * @return NULL on error
@ -639,7 +643,10 @@ TALER_MHD_legal_free (struct TALER_MHD_Legal *legal)
struct Terms *t = &legal->terms[i]; struct Terms *t = &legal->terms[i];
GNUNET_free (t->language); GNUNET_free (t->language);
GNUNET_free (t->terms); GNUNET_free (t->compressed_terms);
if (0 != munmap (t->terms, t->terms_size))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"munmap");
} }
GNUNET_array_grow (legal->terms, GNUNET_array_grow (legal->terms,
legal->terms_len, legal->terms_len,

View File

@ -19,6 +19,12 @@ PORT = 8083
[exchange] [exchange]
TERMS_ETAG = 0
PRIVACY_ETAG = 0
TERMS_DIR = /home/grothoff/share/taler-exchange/tos/
PRIVACY_DIR = /home/grothoff/share/taler-exchange/pp/
# how long is one signkey valid? # how long is one signkey valid?
signkey_duration = 4 weeks signkey_duration = 4 weeks