+Sat 06 Apr 2019 02:36:17 PM CEST
+ Introducing GNUNET_memcmp() and GNUNET_is_zero() for better typing
+ when comparing memory areas. -CG
+
Fri 05 Apr 2019 11:38:53 PM CEST
Use paths of sysctl, ip, ifconfig and ip(6)tables from configure
if they work. (#5352). -CG
static int
alice_or_betty (const struct GNUNET_PeerIdentity *other)
{
- if (0 > GNUNET_CRYPTO_cmp_peer_identity (&my_full_id,
+ if (0 > GNUNET_memcmp (&my_full_id,
other))
return GNUNET_YES;
- else if (0 < GNUNET_CRYPTO_cmp_peer_identity (&my_full_id,
+ else if (0 < GNUNET_memcmp (&my_full_id,
other))
return GNUNET_NO;
else
int cmp;
uint32_t highbit;
- cmp = GNUNET_CRYPTO_cmp_peer_identity (&my_full_id,
+ cmp = GNUNET_memcmp (&my_full_id,
GCP_get_id (GCT_get_destination (t)));
if (0 < cmp)
highbit = HIGH_BIT;
peer_init_handler (void *cls,
const struct GNUNET_PeerIdentity *my_identity)
{
- if (0 != GNUNET_CRYPTO_cmp_peer_identity (&GSF_my_id,
+ if (0 != GNUNET_memcmp (&GSF_my_id,
my_identity))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
struct GSF_ConnectedPeer *cp;
if (0 ==
- GNUNET_CRYPTO_cmp_peer_identity (&GSF_my_id,
+ GNUNET_memcmp (&GSF_my_id,
peer))
return NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
* Given two peers, both may initiate channels over the same tunnel.
* The @e cn must be greater or equal to 0x80000000 (high-bit set)
* for tunnels initiated with the peer that has the larger peer
- * identity as compared using #GNUNET_CRYPTO_cmp_peer_identity().
+ * identity as compared using #GNUNET_memcmp().
*/
uint32_t cn GNUNET_PACKED;
};
*/
#define GNUNET_new(type) (type *) GNUNET_malloc (sizeof (type))
+
+/**
+ * Compare memory in @a a and @a b, where both must be of
+ * the same pointer type.
+ */
+#define GNUNET_memcmp(a,b) ({ \
+ typeof(b) _a = (a); \
+ typeof(a) _b = (b); \
+ memcmp(_a, \
+ _b, \
+ sizeof (*a)); })
+
+
+/**
+ * Check that memory in @a a is all zeros. @a a must be a pointer.
+ *
+ * @param a pointer to a struct which should be tested for the
+ * entire memory being zero'ed out.
+ */
+#define GNUNET_is_zero(a) ({ \
+ typeof(*a) _z = { 0 }; \
+ memcmp(a, \
+ &_z, \
+ sizeof (_z)); })
+
+
/**
* Call memcpy() but check for @a n being 0 first. In the latter
* case, it is now safe to pass NULL for @a src or @a dst.
struct GNUNET_PeerIdentity *dst);
-/**
- * Compare two Peer Identities.
- *
- * @param first first peer identity
- * @param second second peer identity
- * @return bigger than 0 if first > second,
- * 0 if they are the same
- * smaller than 0 if second > first
- */
-int
-GNUNET_CRYPTO_cmp_peer_identity (const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second);
-
-
/**
* Internal structure used to cache pre-calculated values for DLOG calculation.
*/
*/
struct GNUNET_CRYPTO_EccDlogContext *
GNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max,
- unsigned int mem);
+ unsigned int mem);
/**
for ( i = 0 ; i < *list_size ; i++ )
{
- if (0 == GNUNET_CRYPTO_cmp_peer_identity (&tmp[i], peer))
+ if (0 == GNUNET_memcmp (&tmp[i], peer))
{
if (i < *list_size -1)
{ /* Not at the last entry -- shift peers left */
"Going to remove send channel to peer %s\n",
GNUNET_i2s (peer));
#if ENABLE_MALICIOUS
- if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer,
+ if (0 != GNUNET_memcmp (&attacked_peer,
peer))
(void) destroy_sending_channel (get_peer_ctx (sub->peer_map,
peer));
else if (2 == mal_type)
{ /* Try to partition network */
- if (0 == GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer))
+ if (0 == GNUNET_memcmp (&attacked_peer, peer))
{
send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
}
sampler_elem->num_peers++;
- if (0 == GNUNET_CRYPTO_cmp_peer_identity (new_ID, &(sampler_elem->peer_id)))
+ if (0 == GNUNET_memcmp (new_ID, &(sampler_elem->peer_id)))
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n",
GNUNET_i2s (&(sampler_elem->peer_id)));
for (i = 0; i < sampler->sampler_size; i++)
{
- if (0 == GNUNET_CRYPTO_cmp_peer_identity(id,
+ if (0 == GNUNET_memcmp(id,
&(sampler->sampler_elements[i]->peer_id)) )
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n");
count = 0;
for ( i = 0 ; i < sampler->sampler_size ; i++ )
{
- if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (&sampler->sampler_elements[i]->peer_id, id)
+ if ( 0 == GNUNET_memcmp (&sampler->sampler_elements[i]->peer_id, id)
&& EMPTY != sampler->sampler_elements[i]->is_empty)
count++;
}
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 <http://www.gnu.org/licenses/>.
}
-/**
- * Compare two Peer Identities.
- *
- * @param first first peer identity
- * @param second second peer identity
- * @return bigger than 0 if first > second,
- * 0 if they are the same
- * smaller than 0 if second > first
- */
-int
-GNUNET_CRYPTO_cmp_peer_identity (const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second)
-{
- return memcmp (first, second, sizeof (struct GNUNET_PeerIdentity));
-}
-
-
/**
* Convert the data specified in the given purpose argument to an
* S-expression suitable for signature operations.
/* SEE #5398 */
#if 1
struct GNUNET_HashCode hc;
-
+
GNUNET_CRYPTO_hash (purpose,
ntohl (purpose->size),
&hc);
rc);
return NULL;
}
-#endif
+#endif
return data;
}
{
unsigned int i;
unsigned int j;
- struct in6_addr zero;
if (NULL == list)
return GNUNET_NO;
- memset (&zero,
- 0,
- sizeof (struct in6_addr));
i = 0;
NEXT:
- while (0 != memcmp (&zero,
- &list[i].network,
- sizeof (struct in6_addr)))
+ while (0 != GNUNET_is_zero (&list[i].network))
{
for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
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 <http://www.gnu.org/licenses/>.
static void
generatePeerIdList ()
{
- int i;
-
- for (i = 0; i < NUMBER_OF_PEERS; i++)
+ for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
{
gcry_randomize (&pidArr[i],
sizeof (struct GNUNET_PeerIdentity),
GCRY_STRONG_RANDOM);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
+ "Peer %u: %s\n",
+ i,
+ GNUNET_i2s (&pidArr[i]));
}
}
static int
check ()
{
- int i;
GNUNET_PEER_Id pid;
struct GNUNET_PeerIdentity res;
- struct GNUNET_PeerIdentity zero;
GNUNET_PEER_Id ids[] = { 1, 2, 3 };
GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
/* Insert Peers into PeerEntry table and hashmap */
- for (i = 0; i < NUMBER_OF_PEERS; i++)
+ for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
{
pid = GNUNET_PEER_intern (&pidArr[i]);
if (pid != (i + 1))
}
/* Referencing the first 3 peers once again */
- for (i = 0; i < 3; i++)
+ for (unsigned int i = 0; i < 3; i++)
{
pid = GNUNET_PEER_intern (&pidArr[i]);
if (pid != (i + 1))
GNUNET_PEER_decrement_rcs (ids, 3);
/* re-referencing the first 3 peers using the change_rc function */
- for (i = 1; i <= 3; i++)
+ for (unsigned int i = 1; i <= 3; i++)
GNUNET_PEER_change_rc (i, 1);
/* Removing the second Peer from the PeerEntry hash map */
GNUNET_PEER_change_rc (2, -2);
/* convert the pid of the first PeerEntry into that of the third */
- GNUNET_PEER_resolve (1, &res);
- GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof (res)));
+ GNUNET_PEER_resolve (1,
+ &res);
+ GNUNET_assert (0 ==
+ GNUNET_memcmp (&res,
+ &pidArr[0]));
/*
* Attempt to convert pid = 0 (which is reserved)
* into a peer identity object, the peer identity memory
* is expected to be set to zero
*/
- memset (&zero, 0, sizeof (struct GNUNET_PeerIdentity));
GNUNET_log_skip (1, GNUNET_YES);
GNUNET_PEER_resolve (0, &res);
- GNUNET_assert (0 == memcmp (&res, &zero, sizeof (res)));
+ GNUNET_assert (0 ==
+ GNUNET_is_zero (&res));
/* Removing peer entries 1 and 3 from table using the list decrement function */
/* If count = 0, nothing should be done whatsoever */
int
main ()
{
- unsigned int i;
-
- GNUNET_log_setup ("test-peer", "ERROR", NULL);
- for (i = 0; i < 1; i++)
+ GNUNET_log_setup ("test-peer",
+ "ERROR",
+ NULL);
+ for (unsigned int i = 0; i < 1; i++)
{
generatePeerIdList ();
if (0 != check ())