aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_peer.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-06 14:37:07 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-06 14:37:07 +0200
commitc57caa206c761424b73e900978edff0a1b8fca50 (patch)
tree66641306c9a1d196dfe9f82c863bada50fb86187 /src/util/test_peer.c
parentc0d08bbdeed4523cf89bf55b64ce2c16476c3e26 (diff)
downloadgnunet-c57caa206c761424b73e900978edff0a1b8fca50.tar.gz
gnunet-c57caa206c761424b73e900978edff0a1b8fca50.zip
introduce GNUNET_memcmp() and GNUNET_is_zero()
Diffstat (limited to 'src/util/test_peer.c')
-rw-r--r--src/util/test_peer.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 9fbedb15c..248836b4c 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -38,15 +38,15 @@ static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS];
38static void 38static void
39generatePeerIdList () 39generatePeerIdList ()
40{ 40{
41 int i; 41 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
42
43 for (i = 0; i < NUMBER_OF_PEERS; i++)
44 { 42 {
45 gcry_randomize (&pidArr[i], 43 gcry_randomize (&pidArr[i],
46 sizeof (struct GNUNET_PeerIdentity), 44 sizeof (struct GNUNET_PeerIdentity),
47 GCRY_STRONG_RANDOM); 45 GCRY_STRONG_RANDOM);
48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
49 "Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); 47 "Peer %u: %s\n",
48 i,
49 GNUNET_i2s (&pidArr[i]));
50 } 50 }
51} 51}
52 52
@@ -54,15 +54,13 @@ generatePeerIdList ()
54static int 54static int
55check () 55check ()
56{ 56{
57 int i;
58 GNUNET_PEER_Id pid; 57 GNUNET_PEER_Id pid;
59 struct GNUNET_PeerIdentity res; 58 struct GNUNET_PeerIdentity res;
60 struct GNUNET_PeerIdentity zero;
61 GNUNET_PEER_Id ids[] = { 1, 2, 3 }; 59 GNUNET_PEER_Id ids[] = { 1, 2, 3 };
62 60
63 GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); 61 GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
64 /* Insert Peers into PeerEntry table and hashmap */ 62 /* Insert Peers into PeerEntry table and hashmap */
65 for (i = 0; i < NUMBER_OF_PEERS; i++) 63 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
66 { 64 {
67 pid = GNUNET_PEER_intern (&pidArr[i]); 65 pid = GNUNET_PEER_intern (&pidArr[i]);
68 if (pid != (i + 1)) 66 if (pid != (i + 1))
@@ -73,7 +71,7 @@ check ()
73 } 71 }
74 72
75 /* Referencing the first 3 peers once again */ 73 /* Referencing the first 3 peers once again */
76 for (i = 0; i < 3; i++) 74 for (unsigned int i = 0; i < 3; i++)
77 { 75 {
78 pid = GNUNET_PEER_intern (&pidArr[i]); 76 pid = GNUNET_PEER_intern (&pidArr[i]);
79 if (pid != (i + 1)) 77 if (pid != (i + 1))
@@ -87,25 +85,28 @@ check ()
87 GNUNET_PEER_decrement_rcs (ids, 3); 85 GNUNET_PEER_decrement_rcs (ids, 3);
88 86
89 /* re-referencing the first 3 peers using the change_rc function */ 87 /* re-referencing the first 3 peers using the change_rc function */
90 for (i = 1; i <= 3; i++) 88 for (unsigned int i = 1; i <= 3; i++)
91 GNUNET_PEER_change_rc (i, 1); 89 GNUNET_PEER_change_rc (i, 1);
92 90
93 /* Removing the second Peer from the PeerEntry hash map */ 91 /* Removing the second Peer from the PeerEntry hash map */
94 GNUNET_PEER_change_rc (2, -2); 92 GNUNET_PEER_change_rc (2, -2);
95 93
96 /* convert the pid of the first PeerEntry into that of the third */ 94 /* convert the pid of the first PeerEntry into that of the third */
97 GNUNET_PEER_resolve (1, &res); 95 GNUNET_PEER_resolve (1,
98 GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof (res))); 96 &res);
97 GNUNET_assert (0 ==
98 GNUNET_memcmp (&res,
99 &pidArr[0]));
99 100
100 /* 101 /*
101 * Attempt to convert pid = 0 (which is reserved) 102 * Attempt to convert pid = 0 (which is reserved)
102 * into a peer identity object, the peer identity memory 103 * into a peer identity object, the peer identity memory
103 * is expected to be set to zero 104 * is expected to be set to zero
104 */ 105 */
105 memset (&zero, 0, sizeof (struct GNUNET_PeerIdentity));
106 GNUNET_log_skip (1, GNUNET_YES); 106 GNUNET_log_skip (1, GNUNET_YES);
107 GNUNET_PEER_resolve (0, &res); 107 GNUNET_PEER_resolve (0, &res);
108 GNUNET_assert (0 == memcmp (&res, &zero, sizeof (res))); 108 GNUNET_assert (0 ==
109 GNUNET_is_zero (&res));
109 110
110 /* Removing peer entries 1 and 3 from table using the list decrement function */ 111 /* Removing peer entries 1 and 3 from table using the list decrement function */
111 /* If count = 0, nothing should be done whatsoever */ 112 /* If count = 0, nothing should be done whatsoever */
@@ -122,10 +123,10 @@ check ()
122int 123int
123main () 124main ()
124{ 125{
125 unsigned int i; 126 GNUNET_log_setup ("test-peer",
126 127 "ERROR",
127 GNUNET_log_setup ("test-peer", "ERROR", NULL); 128 NULL);
128 for (i = 0; i < 1; i++) 129 for (unsigned int i = 0; i < 1; i++)
129 { 130 {
130 generatePeerIdList (); 131 generatePeerIdList ();
131 if (0 != check ()) 132 if (0 != check ())