From ba33155b4f60b8f8049c4f77e3b7b40e29ae63e2 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 3 May 2019 16:19:17 +0200 Subject: reindentation --- src/core/Makefile.am | 2 +- src/core/gnunet-service-core_typemap.c | 49 +++--- src/curl/curl.c | 267 +++++++++++++-------------------- 3 files changed, 132 insertions(+), 186 deletions(-) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2723151c5..70ec91fbc 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -58,7 +58,7 @@ gnunet_core_LDADD = \ if HAVE_TESTING TESTING_TESTS = \ - test_core_api_send_to_self + test_core_api_send_to_self endif check_PROGRAMS = \ diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c index b73267544..9dd3c71c8 100644 --- a/src/core/gnunet-service-core_typemap.c +++ b/src/core/gnunet-service-core_typemap.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -80,12 +80,9 @@ rehash_typemap () * @param hc where to store the hash code */ void -GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm, - struct GNUNET_HashCode *hc) +GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc) { - GNUNET_CRYPTO_hash (tm, - sizeof (struct GSC_TypeMap), - hc); + GNUNET_CRYPTO_hash (tm, sizeof (struct GSC_TypeMap), hc); } @@ -100,12 +97,12 @@ GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc) { if (GNUNET_NO == hash_current) { - GSC_TYPEMAP_hash (&my_type_map, - &my_tm_hash); + GSC_TYPEMAP_hash (&my_type_map, &my_tm_hash); hash_current = GNUNET_YES; } return (0 == memcmp (hc, &my_tm_hash, sizeof (struct GNUNET_HashCode))) - ? GNUNET_YES : GNUNET_NO; + ? GNUNET_YES + : GNUNET_NO; } @@ -130,9 +127,12 @@ GSC_TYPEMAP_compute_type_map_message () #endif hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); tmp = (char *) &hdr[1]; - if ((Z_OK != - compress2 ((Bytef *) tmp, &dlen, (const Bytef *) &my_type_map, - sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map))) + if ((Z_OK != compress2 ((Bytef *) tmp, + &dlen, + (const Bytef *) &my_type_map, + sizeof (my_type_map), + 9)) || + (dlen >= sizeof (my_type_map))) { /* compression failed, use uncompressed map */ dlen = sizeof (my_type_map); @@ -166,8 +166,10 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg) switch (ntohs (msg->type)) { case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: - GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"), - 1, GNUNET_NO); + GNUNET_STATISTICS_update (GSC_stats, + gettext_noop ("# type maps received"), + 1, + GNUNET_NO); if (size != sizeof (struct GSC_TypeMap)) { GNUNET_break_op (0); @@ -183,9 +185,11 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg) GNUNET_NO); ret = GNUNET_new (struct GSC_TypeMap); dlen = sizeof (struct GSC_TypeMap); - if ((Z_OK != - uncompress ((Bytef *) ret, &dlen, (const Bytef *) &msg[1], - (uLong) size)) || (dlen != sizeof (struct GSC_TypeMap))) + if ((Z_OK != uncompress ((Bytef *) ret, + &dlen, + (const Bytef *) &msg[1], + (uLong) size)) || + (dlen != sizeof (struct GSC_TypeMap))) { GNUNET_break_op (0); GNUNET_free (ret); @@ -224,8 +228,7 @@ broadcast_my_type_map () * @param tlen number of entries in @a types */ void -GSC_TYPEMAP_add (const uint16_t *types, - unsigned int tlen) +GSC_TYPEMAP_add (const uint16_t *types, unsigned int tlen) { unsigned int i; int changed; @@ -241,8 +244,7 @@ GSC_TYPEMAP_add (const uint16_t *types, } if (GNUNET_YES == changed) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Typemap changed, broadcasting!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Typemap changed, broadcasting!\n"); rehash_typemap (); broadcast_my_type_map (); } @@ -256,8 +258,7 @@ GSC_TYPEMAP_add (const uint16_t *types, * @param tlen length of the @a types array */ void -GSC_TYPEMAP_remove (const uint16_t *types, - unsigned int tlen) +GSC_TYPEMAP_remove (const uint16_t *types, unsigned int tlen) { int changed; @@ -295,7 +296,7 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, if (NULL == tmap) return GNUNET_NO; if (0 == tcnt) - return GNUNET_YES; /* matches all */ + return GNUNET_YES; /* matches all */ for (unsigned int i = 0; i < tcnt; i++) if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32)))) return GNUNET_YES; diff --git a/src/curl/curl.c b/src/curl/curl.c index 1c352f195..e13c1478f 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c @@ -39,18 +39,24 @@ * @param function which function failed to run * @param code what was the curl error code */ -#define CURL_STRERROR(type, function, code) \ - GNUNET_log (type, \ - "Curl function `%s' has failed at `%s:%d' with error: %s\n", \ - function, __FILE__, __LINE__, curl_easy_strerror (code)); +#define CURL_STRERROR(type, function, code) \ + GNUNET_log (type, \ + "Curl function `%s' has failed at `%s:%d' with error: %s\n", \ + function, \ + __FILE__, \ + __LINE__, \ + curl_easy_strerror (code)); /** * Print JSON parsing related error information */ -#define JSON_WARN(error) \ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ - "JSON parsing failed at %s:%u: %s (%s)\n", \ - __FILE__, __LINE__, error.text, error.source) +#define JSON_WARN(error) \ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ + "JSON parsing failed at %s:%u: %s (%s)\n", \ + __FILE__, \ + __LINE__, \ + error.text, \ + error.source) /** @@ -99,7 +105,6 @@ struct GNUNET_CURL_Job * Buffer for response received from CURL. */ struct GNUNET_CURL_DownloadBuffer db; - }; @@ -156,8 +161,7 @@ struct GNUNET_CURL_Context * @return library context */ struct GNUNET_CURL_Context * -GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, - void *cb_cls) +GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls) { struct GNUNET_CURL_Context *ctx; CURLM *multi; @@ -165,8 +169,7 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, if (curl_fail) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Curl was not initialised properly\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Curl was not initialised properly\n"); return NULL; } if (NULL == (multi = curl_multi_init ())) @@ -186,9 +189,9 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, ctx->cb_cls = cb_cls; ctx->multi = multi; ctx->share = share; - GNUNET_assert (NULL != (ctx->json_header = - curl_slist_append (NULL, - "Content-Type: application/json"))); + GNUNET_assert ( + NULL != (ctx->json_header = + curl_slist_append (NULL, "Content-Type: application/json"))); return ctx; } @@ -207,10 +210,7 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, * @return number of bytes processed from @a bufptr */ static size_t -download_cb (char *bufptr, - size_t size, - size_t nitems, - void *cls) +download_cb (char *bufptr, size_t size, size_t nitems, void *cls) { struct GNUNET_CURL_DownloadBuffer *db = cls; size_t msize; @@ -222,13 +222,12 @@ download_cb (char *bufptr, return 0; } msize = size * nitems; - if ( (msize + db->buf_size) >= GNUNET_MAX_MALLOC_CHECKED) + if ((msize + db->buf_size) >= GNUNET_MAX_MALLOC_CHECKED) { db->eno = ENOMEM; return 0; /* signals an error to curl */ } - db->buf = GNUNET_realloc (db->buf, - db->buf_size + msize); + db->buf = GNUNET_realloc (db->buf, db->buf_size + msize); buf = db->buf + db->buf_size; GNUNET_memcpy (buf, bufptr, msize); db->buf_size += msize; @@ -262,10 +261,7 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, struct GNUNET_CURL_Job *job; if (GNUNET_YES == add_json) - if (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_HTTPHEADER, - ctx->json_header)) + if (CURLE_OK != curl_easy_setopt (eh, CURLOPT_HTTPHEADER, ctx->json_header)) { GNUNET_break (0); curl_easy_cleanup (eh); @@ -273,25 +269,12 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, } job = GNUNET_new (struct GNUNET_CURL_Job); - if ( (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_PRIVATE, - job)) || - (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_WRITEFUNCTION, - &download_cb)) || - (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_WRITEDATA, - &job->db)) || - (CURLE_OK != - curl_easy_setopt (eh, - CURLOPT_SHARE, - ctx->share)) || - (CURLM_OK != - curl_multi_add_handle (ctx->multi, - eh)) ) + if ((CURLE_OK != curl_easy_setopt (eh, CURLOPT_PRIVATE, job)) || + (CURLE_OK != + curl_easy_setopt (eh, CURLOPT_WRITEFUNCTION, &download_cb)) || + (CURLE_OK != curl_easy_setopt (eh, CURLOPT_WRITEDATA, &job->db)) || + (CURLE_OK != curl_easy_setopt (eh, CURLOPT_SHARE, ctx->share)) || + (CURLM_OK != curl_multi_add_handle (ctx->multi, eh))) { GNUNET_break (0); GNUNET_free (job); @@ -303,9 +286,7 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, job->ctx = ctx; job->jcc = jcc; job->jcc_cls = jcc_cls; - GNUNET_CONTAINER_DLL_insert (ctx->jobs_head, - ctx->jobs_tail, - job); + GNUNET_CONTAINER_DLL_insert (ctx->jobs_head, ctx->jobs_tail, job); ctx->cb (ctx->cb_cls); return job; } @@ -322,12 +303,9 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) { struct GNUNET_CURL_Context *ctx = job->ctx; - GNUNET_CONTAINER_DLL_remove (ctx->jobs_head, - ctx->jobs_tail, - job); + GNUNET_CONTAINER_DLL_remove (ctx->jobs_head, ctx->jobs_tail, job); GNUNET_break (CURLM_OK == - curl_multi_remove_handle (ctx->multi, - job->easy_handle)); + curl_multi_remove_handle (ctx->multi, job->easy_handle)); curl_easy_cleanup (job->easy_handle); GNUNET_free_non_null (job->db.buf); GNUNET_free (job); @@ -366,20 +344,13 @@ download_get_result (struct GNUNET_CURL_DownloadBuffer *db, (int) db->buf_size, (char *) db->buf); - if ( (CURLE_OK != - curl_easy_getinfo (eh, - CURLINFO_CONTENT_TYPE, - &ct)) || - (NULL == ct) || - (0 != strcasecmp (ct, - "application/json")) ) + if ((CURLE_OK != curl_easy_getinfo (eh, CURLINFO_CONTENT_TYPE, &ct)) || + (NULL == ct) || (0 != strcasecmp (ct, "application/json"))) { /* No content type or explicitly not JSON, refuse to parse (but keep response code) */ if (CURLE_OK != - curl_easy_getinfo (eh, - CURLINFO_RESPONSE_CODE, - response_code)) + curl_easy_getinfo (eh, CURLINFO_RESPONSE_CODE, response_code)) { /* unexpected error... */ GNUNET_break (0); @@ -409,9 +380,7 @@ download_get_result (struct GNUNET_CURL_DownloadBuffer *db, if (NULL != json) { if (CURLE_OK != - curl_easy_getinfo (eh, - CURLINFO_RESPONSE_CODE, - response_code)) + curl_easy_getinfo (eh, CURLINFO_RESPONSE_CODE, response_code)) { /* unexpected error... */ GNUNET_break (0); @@ -430,11 +399,9 @@ download_get_result (struct GNUNET_CURL_DownloadBuffer *db, * @return #GNUNET_OK if no errors occurred, #GNUNET_SYSERR otherwise. */ int -GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, - const char *header) +GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, const char *header) { - ctx->json_header = curl_slist_append (ctx->json_header, - header); + ctx->json_header = curl_slist_append (ctx->json_header, header); if (NULL == ctx->json_header) return GNUNET_SYSERR; @@ -462,96 +429,83 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, long response_code; void *response; - (void) curl_multi_perform (ctx->multi, - &n_running); - while (NULL != (cmsg = curl_multi_info_read (ctx->multi, - &n_completed))) + (void) curl_multi_perform (ctx->multi, &n_running); + while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed))) { /* Only documented return value is CURLMSG_DONE */ GNUNET_break (CURLMSG_DONE == cmsg->msg); - GNUNET_assert (CURLE_OK == - curl_easy_getinfo (cmsg->easy_handle, - CURLINFO_PRIVATE, - (char **) &job)); + GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, + CURLINFO_PRIVATE, + (char **) &job)); GNUNET_assert (job->ctx == ctx); - response_code = 0 ; - response = rp (&job->db, - job->easy_handle, - &response_code); + response_code = 0; + response = rp (&job->db, job->easy_handle, &response_code); #if ENABLE_BENCHMARK - { - char *url = NULL; - double total_as_double = 0; - struct GNUNET_TIME_Relative total; - struct UrlRequestData *urd; - /* Some care required, as curl is using data types (long vs curl_off_t vs + { + char *url = NULL; + double total_as_double = 0; + struct GNUNET_TIME_Relative total; + struct UrlRequestData *urd; + /* Some care required, as curl is using data types (long vs curl_off_t vs * double) inconsistently to store byte count. */ - curl_off_t size_curl = 0; - long size_long = 0; - uint64_t bytes_sent = 0; - uint64_t bytes_received = 0; - - GNUNET_break (CURLE_OK == - curl_easy_getinfo (cmsg->easy_handle, - CURLINFO_TOTAL_TIME, - &total_as_double)); - total.rel_value_us = total_as_double * 1000 * 1000; - - GNUNET_break (CURLE_OK == - curl_easy_getinfo (cmsg->easy_handle, - CURLINFO_EFFECTIVE_URL, - &url)); - - /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total + curl_off_t size_curl = 0; + long size_long = 0; + uint64_t bytes_sent = 0; + uint64_t bytes_received = 0; + + GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, + CURLINFO_TOTAL_TIME, + &total_as_double)); + total.rel_value_us = total_as_double * 1000 * 1000; + + GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, + CURLINFO_EFFECTIVE_URL, + &url)); + + /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total number of bytes received, not clear from curl docs. */ - GNUNET_break (CURLE_OK == - curl_easy_getinfo (cmsg->easy_handle, - CURLINFO_HEADER_SIZE, - &size_long)); - bytes_received += size_long; + GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, + CURLINFO_HEADER_SIZE, + &size_long)); + bytes_received += size_long; - GNUNET_break (CURLE_OK == - curl_easy_getinfo (cmsg->easy_handle, - CURLINFO_SIZE_DOWNLOAD_T, - &size_curl)); - bytes_received += size_curl; + GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, + CURLINFO_SIZE_DOWNLOAD_T, + &size_curl)); + bytes_received += size_curl; - /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes + /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes sent, again docs are not completely clear. */ - GNUNET_break (CURLE_OK == - curl_easy_getinfo (cmsg->easy_handle, - CURLINFO_REQUEST_SIZE, - &size_long)); - bytes_sent += size_long; + GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, + CURLINFO_REQUEST_SIZE, + &size_long)); + bytes_sent += size_long; - /* We obtain this value to check an invariant, but never use it otherwise. */ - GNUNET_break (CURLE_OK == - curl_easy_getinfo (cmsg->easy_handle, - CURLINFO_SIZE_UPLOAD_T, - &size_curl)); + /* We obtain this value to check an invariant, but never use it otherwise. */ + GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, + CURLINFO_SIZE_UPLOAD_T, + &size_curl)); - /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should + /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should be an invariant. As verified with curl -w "foo%{size_request} -XPOST --data "ABC" $URL the CURLINFO_REQUEST_SIZE should be the whole size of the request including headers and body. */ - GNUNET_break (size_curl <= size_long); - - urd = get_url_benchmark_data (url, (unsigned int) response_code); - urd->count++; - urd->time = GNUNET_TIME_relative_add (urd->time, total); - urd->time_max = GNUNET_TIME_relative_max (total, urd->time_max); - urd->bytes_sent += bytes_sent; - urd->bytes_received += bytes_received; - } + GNUNET_break (size_curl <= size_long); + + urd = get_url_benchmark_data (url, (unsigned int) response_code); + urd->count++; + urd->time = GNUNET_TIME_relative_add (urd->time, total); + urd->time_max = GNUNET_TIME_relative_max (total, urd->time_max); + urd->bytes_sent += bytes_sent; + urd->bytes_received += bytes_received; + } #endif - job->jcc (job->jcc_cls, - response_code, - response); + job->jcc (job->jcc_cls, response_code, response); rc (response); GNUNET_CURL_job_cancel (job); } @@ -566,7 +520,7 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, void GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx) { - + GNUNET_CURL_perform2 (ctx, download_get_result, (GNUNET_CURL_ResponseCleaner) &json_decref); @@ -613,25 +567,20 @@ GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx, int m; m = -1; - GNUNET_assert (CURLM_OK == - curl_multi_fdset (ctx->multi, - read_fd_set, - write_fd_set, - except_fd_set, - &m)); + GNUNET_assert (CURLM_OK == curl_multi_fdset (ctx->multi, + read_fd_set, + write_fd_set, + except_fd_set, + &m)); to = *timeout; *max_fd = GNUNET_MAX (m, *max_fd); - GNUNET_assert (CURLM_OK == - curl_multi_timeout (ctx->multi, - &to)); + GNUNET_assert (CURLM_OK == curl_multi_timeout (ctx->multi, &to)); /* Only if what we got back from curl is smaller than what we already had (-1 == infinity!), then update timeout */ - if ( (to < *timeout) && - (-1 != to) ) + if ((to < *timeout) && (-1 != to)) *timeout = to; - if ( (-1 == (*timeout)) && - (NULL != ctx->jobs_head) ) + if ((-1 == (*timeout)) && (NULL != ctx->jobs_head)) *timeout = to; } @@ -658,17 +607,14 @@ GNUNET_CURL_fini (struct GNUNET_CURL_Context *ctx) /** * Initial global setup logic, specifically runs the Curl setup. */ -__attribute__ ((constructor)) -void +__attribute__ ((constructor)) void GNUNET_CURL_constructor__ (void) { CURLcode ret; if (CURLE_OK != (ret = curl_global_init (CURL_GLOBAL_DEFAULT))) { - CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR, - "curl_global_init", - ret); + CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR, "curl_global_init", ret); curl_fail = 1; } } @@ -677,8 +623,7 @@ GNUNET_CURL_constructor__ (void) /** * Cleans up after us, specifically runs the Curl cleanup. */ -__attribute__ ((destructor)) -void +__attribute__ ((destructor)) void GNUNET_CURL_destructor__ (void) { if (curl_fail) -- cgit v1.2.3