aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-08-24 15:35:28 +0200
committerJulius Bünger <buenger@mytum.de>2018-08-26 17:35:20 +0200
commitb1edf308b38823bacda4e0600377ce633fe89434 (patch)
tree2e5f2d0a7afb0bd088220147ebb77bc2ada78796
parentdc86c377a63e79ab2d17ce644ea060d1ce0c6b0c (diff)
downloadgnunet-b1edf308b38823bacda4e0600377ce633fe89434.tar.gz
gnunet-b1edf308b38823bacda4e0600377ce633fe89434.zip
Change cosmetics of sampler element implementation
-rw-r--r--src/rps/gnunet-service-rps_sampler_elem.c88
-rw-r--r--src/rps/gnunet-service-rps_sampler_elem.h18
2 files changed, 51 insertions, 55 deletions
diff --git a/src/rps/gnunet-service-rps_sampler_elem.c b/src/rps/gnunet-service-rps_sampler_elem.c
index 7569801a6..a1a46b2d7 100644
--- a/src/rps/gnunet-service-rps_sampler_elem.c
+++ b/src/rps/gnunet-service-rps_sampler_elem.c
@@ -33,45 +33,41 @@
33#define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler_elem",__VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler_elem",__VA_ARGS__)
34 34
35 35
36// TODO check for overflows
37
38/*********************************************************************** 36/***********************************************************************
39 * WARNING: This section needs to be reviewed regarding the use of 37 * WARNING: This section needs to be reviewed regarding the use of
40 * functions providing (pseudo)randomness! 38 * functions providing (pseudo)randomness!
41***********************************************************************/ 39***********************************************************************/
42 40
43// TODO care about invalid input of the caller (size 0 or less...)
44
45 41
46/** 42/**
47 * Reinitialise a previously initialised sampler element. 43 * Reinitialise a previously initialised sampler element.
48 * 44 *
49 * @param sampler pointer to the memory that keeps the value. 45 * @param sampler_el The sampler element to (re-) initialise
50 */ 46 */
51void 47void
52RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_el) 48RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem)
53{ 49{
54 sampler_el->is_empty = EMPTY; 50 sampler_elem->is_empty = EMPTY;
55 51
56 // I guess I don't need to call GNUNET_CRYPTO_hmac_derive_key()... 52 // I guess I don't need to call GNUNET_CRYPTO_hmac_derive_key()...
57 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_STRONG, 53 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_STRONG,
58 &(sampler_el->auth_key.key), 54 &(sampler_elem->auth_key.key),
59 GNUNET_CRYPTO_HASH_LENGTH); 55 GNUNET_CRYPTO_HASH_LENGTH);
60 56
61 #ifdef TO_FILE 57 #ifdef TO_FILE
62 /* Create a file(-name) to store internals to */ 58 /* Create a file(-name) to store internals to */
63 char *name_buf; 59 char *name_buf;
64 name_buf = auth_key_to_string (sampler_el->auth_key); 60 name_buf = auth_key_to_string (sampler_elem->auth_key);
65 61
66 sampler_el->file_name = create_file (name_buf); 62 sampler_elem->file_name = create_file (name_buf);
67 GNUNET_free (name_buf); 63 GNUNET_free (name_buf);
68 #endif /* TO_FILE */ 64 #endif /* TO_FILE */
69 65
70 sampler_el->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; 66 sampler_elem->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS;
71 67
72 sampler_el->birth = GNUNET_TIME_absolute_get (); 68 sampler_elem->birth = GNUNET_TIME_absolute_get ();
73 sampler_el->num_peers = 0; 69 sampler_elem->num_peers = 0;
74 sampler_el->num_change = 0; 70 sampler_elem->num_change = 0;
75} 71}
76 72
77 73
@@ -115,89 +111,89 @@ RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem)
115 111
116 112
117/** 113/**
118 * Input an PeerID into the given sampler element. 114 * Update a sampler element with a PeerID
119 * 115 *
120 * @param sampler the sampler the @a s_elem belongs to. 116 * @param sampler_elem The sampler element to update
121 * Needed to know the 117 * @param new_ID The PeerID to update with
122 */ 118 */
123void 119void
124RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, 120RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem,
125 const struct GNUNET_PeerIdentity *other) 121 const struct GNUNET_PeerIdentity *new_ID)
126{ 122{
127 struct GNUNET_HashCode other_hash; 123 struct GNUNET_HashCode other_hash;
128 124
129 s_elem->num_peers++; 125 sampler_elem->num_peers++;
130 126
131 #ifdef TO_FILE 127 #ifdef TO_FILE
132 to_file (s_elem->file_name, 128 to_file (sampler_elem->file_name,
133 "Got id %s", 129 "Got id %s",
134 GNUNET_i2s_full (other)); 130 GNUNET_i2s_full (new_ID));
135 #endif /* TO_FILE */ 131 #endif /* TO_FILE */
136 132
137 if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id))) 133 if (0 == GNUNET_CRYPTO_cmp_peer_identity (new_ID, &(sampler_elem->peer_id)))
138 { 134 {
139 LOG (GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n", 135 LOG (GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n",
140 GNUNET_i2s (&(s_elem->peer_id))); 136 GNUNET_i2s (&(sampler_elem->peer_id)));
141 } 137 }
142 else 138 else
143 { 139 {
144 GNUNET_CRYPTO_hmac(&s_elem->auth_key, 140 GNUNET_CRYPTO_hmac(&sampler_elem->auth_key,
145 other, 141 new_ID,
146 sizeof(struct GNUNET_PeerIdentity), 142 sizeof(struct GNUNET_PeerIdentity),
147 &other_hash); 143 &other_hash);
148 144
149 if (EMPTY == s_elem->is_empty) 145 if (EMPTY == sampler_elem->is_empty)
150 { 146 {
151 LOG (GNUNET_ERROR_TYPE_DEBUG, 147 LOG (GNUNET_ERROR_TYPE_DEBUG,
152 "Got PeerID %s; Simply accepting (was empty previously).\n", 148 "Got PeerID %s; Simply accepting (was empty previously).\n",
153 GNUNET_i2s(other)); 149 GNUNET_i2s(new_ID));
154 s_elem->peer_id = *other; 150 sampler_elem->peer_id = *new_ID;
155 s_elem->peer_id_hash = other_hash; 151 sampler_elem->peer_id_hash = other_hash;
156 152
157 s_elem->num_change++; 153 sampler_elem->num_change++;
158 } 154 }
159 else if (0 > GNUNET_CRYPTO_hash_cmp (&other_hash, &s_elem->peer_id_hash)) 155 else if (0 > GNUNET_CRYPTO_hash_cmp (&other_hash, &sampler_elem->peer_id_hash))
160 { 156 {
161 LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n", 157 LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n",
162 GNUNET_i2s (&s_elem->peer_id)); 158 GNUNET_i2s (&sampler_elem->peer_id));
163 s_elem->peer_id = *other; 159 sampler_elem->peer_id = *new_ID;
164 s_elem->peer_id_hash = other_hash; 160 sampler_elem->peer_id_hash = other_hash;
165 161
166 s_elem->num_change++; 162 sampler_elem->num_change++;
167 } 163 }
168 else 164 else
169 { 165 {
170 LOG (GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n", 166 LOG (GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n",
171 GNUNET_i2s (&s_elem->peer_id)); 167 GNUNET_i2s (&sampler_elem->peer_id));
172 } 168 }
173 } 169 }
174 s_elem->is_empty = NOT_EMPTY; 170 sampler_elem->is_empty = NOT_EMPTY;
175 171
176 #ifdef TO_FILE 172 #ifdef TO_FILE
177 to_file (s_elem->file_name, 173 to_file (sampler_elem->file_name,
178 "Now holding %s", 174 "Now holding %s",
179 GNUNET_i2s_full (&s_elem->peer_id)); 175 GNUNET_i2s_full (&sampler_elem->peer_id));
180 #endif /* TO_FILE */ 176 #endif /* TO_FILE */
181} 177}
182 178
183/** 179/**
184 * Initialise the min-wise independent function of the given sampler element. 180 * Set the min-wise independent function of the given sampler element.
185 * 181 *
186 * @param s_elem the sampler element 182 * @param sampler_elem the sampler element
187 * @param auth_key the key to use 183 * @param auth_key the key to use
188 */ 184 */
189void 185void
190RPS_sampler_elem_set (struct RPS_SamplerElement *s_elem, 186RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem,
191 struct GNUNET_CRYPTO_AuthKey auth_key) 187 struct GNUNET_CRYPTO_AuthKey auth_key)
192{ 188{
193 s_elem->auth_key = auth_key; 189 sampler_elem->auth_key = auth_key;
194 190
195 #ifdef TO_FILE 191 #ifdef TO_FILE
196 /* Create a file(-name) to store internals to */ 192 /* Create a file(-name) to store internals to */
197 char *name_buf; 193 char *name_buf;
198 name_buf = auth_key_to_string (s_elem->auth_key); 194 name_buf = auth_key_to_string (sampler_elem->auth_key);
199 195
200 s_elem->file_name = create_file (name_buf); 196 sampler_elem->file_name = create_file (name_buf);
201 GNUNET_free (name_buf); 197 GNUNET_free (name_buf);
202 #endif /* TO_FILE */ 198 #endif /* TO_FILE */
203} 199}
diff --git a/src/rps/gnunet-service-rps_sampler_elem.h b/src/rps/gnunet-service-rps_sampler_elem.h
index 1dbdcbadd..7598a627b 100644
--- a/src/rps/gnunet-service-rps_sampler_elem.h
+++ b/src/rps/gnunet-service-rps_sampler_elem.h
@@ -99,10 +99,10 @@ struct RPS_SamplerElement
99/** 99/**
100 * Reinitialise a previously initialised sampler element. 100 * Reinitialise a previously initialised sampler element.
101 * 101 *
102 * @param sampler pointer to the memory that keeps the value. 102 * @param sampler_el The sampler element to (re-) initialise
103 */ 103 */
104void 104void
105RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_el); 105RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem);
106 106
107 107
108/** 108/**
@@ -127,23 +127,23 @@ RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem);
127 127
128 128
129/** 129/**
130 * Input an PeerID into the given sampler element. 130 * Update a sampler element with a PeerID
131 * 131 *
132 * @param sampler the sampler the @a s_elem belongs to. 132 * @param sampler_elem The sampler element to update
133 * Needed to know the 133 * @param new_ID The PeerID to update with
134 */ 134 */
135void 135void
136RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem, 136RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem,
137 const struct GNUNET_PeerIdentity *new_ID); 137 const struct GNUNET_PeerIdentity *new_ID);
138 138
139/** 139/**
140 * Initialise the min-wise independent function of the given sampler element. 140 * Set the min-wise independent function of the given sampler element.
141 * 141 *
142 * @param s_elem the sampler element 142 * @param sampler_elem the sampler element
143 * @param auth_key the key to use 143 * @param auth_key the key to use
144 */ 144 */
145void 145void
146RPS_sampler_elem_set (struct RPS_SamplerElement *s_elem, 146RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem,
147 struct GNUNET_CRYPTO_AuthKey auth_key); 147 struct GNUNET_CRYPTO_AuthKey auth_key);
148 148
149 149