aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-28 17:39:25 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-28 17:39:25 +0000
commite32a95423e3e54f983df02e88e5f0d2e81cc6d4f (patch)
treea4bd2bafbd1608b4c5e20c6493f351678e08107b /src
parent914b0c76cdf75a89469052a734ae88b7b29893fa (diff)
downloadgnunet-e32a95423e3e54f983df02e88e5f0d2e81cc6d4f.tar.gz
gnunet-e32a95423e3e54f983df02e88e5f0d2e81cc6d4f.zip
cache signature upon first generation to avoid useless re-signing of the same data
Diffstat (limited to 'src')
-rw-r--r--src/nse/gnunet-service-nse.c28
-rw-r--r--src/nse/nse_api.c2
2 files changed, 23 insertions, 7 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 6e866f82c..57bfcde2f 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -828,6 +828,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
828 sizeof (uint64_t)]; 828 sizeof (uint64_t)];
829 GNUNET_HashCode result; 829 GNUNET_HashCode result;
830 unsigned int i; 830 unsigned int i;
831 const struct GNUNET_CRYPTO_RsaSignature *sig_cache;
831 832
832 proof_task = GNUNET_SCHEDULER_NO_TASK; 833 proof_task = GNUNET_SCHEDULER_NO_TASK;
833 memcpy (&buf[sizeof (uint64_t)], &my_public_key, 834 memcpy (&buf[sizeof (uint64_t)], &my_public_key,
@@ -845,19 +846,34 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof of work found: %llu!\n", 846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Proof of work found: %llu!\n",
846 (unsigned long long) GNUNET_ntohll (counter)); 847 (unsigned long long) GNUNET_ntohll (counter));
847#endif 848#endif
849 sig_cache = NULL;
848 for (i = 0; i < HISTORY_SIZE; i++) 850 for (i = 0; i < HISTORY_SIZE; i++)
849 if (ntohl (size_estimate_messages[i].hop_count) == 0) 851 if (ntohl (size_estimate_messages[i].hop_count) == 0)
850 { 852 {
851 size_estimate_messages[i].proof_of_work = my_proof; 853 size_estimate_messages[i].proof_of_work = my_proof;
852 if (nse_work_required > 0) 854 if (nse_work_required > 0)
853 GNUNET_assert (GNUNET_OK == 855 {
854 GNUNET_CRYPTO_rsa_sign (my_private_key, 856 if (sig_cache == NULL)
855 &size_estimate_messages 857 {
856 [i].purpose, 858 GNUNET_assert (GNUNET_OK ==
857 &size_estimate_messages 859 GNUNET_CRYPTO_rsa_sign (my_private_key,
858 [i].signature)); 860 &size_estimate_messages
861 [i].purpose,
862 &size_estimate_messages
863 [i].signature));
864 sig_cache = &size_estimate_messages[i].signature;
865 }
866 else
867 {
868 /* use cached signature */
869 size_estimate_messages[i].signature = *sig_cache;
870 }
871 }
859 else 872 else
873 {
874 /* no signature required */
860 memset (&size_estimate_messages[i].signature, 0, sizeof (struct GNUNET_CRYPTO_RsaSignature)); 875 memset (&size_estimate_messages[i].signature, 0, sizeof (struct GNUNET_CRYPTO_RsaSignature));
876 }
861 } 877 }
862 write_proof (); 878 write_proof ();
863 return; 879 return;
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index db5e9d117..e32c08e4b 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -105,7 +105,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
105 105
106 if (msg == NULL) 106 if (msg == NULL)
107 { 107 {
108 /* Error, timeout, death */ 108 /* Error, timeout, death */
109 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); 109 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
110 h->client = NULL; 110 h->client = NULL;
111 h->reconnect_task = 111 h->reconnect_task =