aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/test_peerinfo_api_friend_only.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-24 11:54:36 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-24 11:54:36 +0000
commiteafc8188ef6584f77dc4dbc6827210f384986e1a (patch)
tree501f87ddd224b0cbd5aaf9008b57005b129cac24 /src/peerinfo/test_peerinfo_api_friend_only.c
parent2e95a6961bf57170b215ab28e50dbf2376d46747 (diff)
downloadgnunet-eafc8188ef6584f77dc4dbc6827210f384986e1a.tar.gz
gnunet-eafc8188ef6584f77dc4dbc6827210f384986e1a.zip
update peerinfo API to use MQ
Diffstat (limited to 'src/peerinfo/test_peerinfo_api_friend_only.c')
-rw-r--r--src/peerinfo/test_peerinfo_api_friend_only.c78
1 files changed, 46 insertions, 32 deletions
diff --git a/src/peerinfo/test_peerinfo_api_friend_only.c b/src/peerinfo/test_peerinfo_api_friend_only.c
index 1275e4668..8086d8d43 100644
--- a/src/peerinfo/test_peerinfo_api_friend_only.c
+++ b/src/peerinfo/test_peerinfo_api_friend_only.c
@@ -32,18 +32,23 @@
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33#include "gnunet_peerinfo_service.h" 33#include "gnunet_peerinfo_service.h"
34#include "gnunet_testing_lib.h" 34#include "gnunet_testing_lib.h"
35#include "peerinfo.h" 35
36 36
37static struct GNUNET_PEERINFO_IteratorContext *ic; 37static struct GNUNET_PEERINFO_IteratorContext *ic;
38 38
39static struct GNUNET_PEERINFO_Handle *h; 39static struct GNUNET_PEERINFO_Handle *h;
40 40
41static struct GNUNET_PeerIdentity pid;
42
41static unsigned int retries; 43static unsigned int retries;
42 44
43static int global_ret; 45static int global_ret;
44 46
47
45static ssize_t 48static ssize_t
46address_generator (void *cls, size_t max, void *buf) 49address_generator (void *cls,
50 size_t max,
51 void *buf)
47{ 52{
48 size_t *agc = cls; 53 size_t *agc = cls;
49 ssize_t ret; 54 ssize_t ret;
@@ -51,19 +56,20 @@ address_generator (void *cls, size_t max, void *buf)
51 56
52 if (0 == *agc) 57 if (0 == *agc)
53 return GNUNET_SYSERR; /* Done */ 58 return GNUNET_SYSERR; /* Done */
54 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 59 memset (&address.peer,
60 0,
61 sizeof (struct GNUNET_PeerIdentity));
55 address.address = "Address"; 62 address.address = "Address";
56 address.transport_name = "peerinfotest"; 63 address.transport_name = "peerinfotest";
57 address.address_length = *agc; 64 address.address_length = *agc;
58 ret = 65 ret = GNUNET_HELLO_add_address (&address,
59 GNUNET_HELLO_add_address (&address, 66 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
60 GNUNET_TIME_relative_to_absolute 67 buf,
61 (GNUNET_TIME_UNIT_HOURS), buf, max); 68 max);
62 (*agc)--; 69 (*agc)--;
63 return ret; 70 return ret;
64} 71}
65 72
66struct GNUNET_PeerIdentity pid;
67 73
68static void 74static void
69add_peer () 75add_peer ()
@@ -73,24 +79,32 @@ add_peer ()
73 79
74 agc = 2; 80 agc = 2;
75 memset (&pid, 32, sizeof (pid)); 81 memset (&pid, 32, sizeof (pid));
76 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, GNUNET_YES); 82 h2 = GNUNET_HELLO_create (&pid.public_key,
77 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); 83 &address_generator,
84 &agc,
85 GNUNET_YES);
86 GNUNET_PEERINFO_add_peer (h,
87 h2,
88 NULL,
89 NULL);
78 GNUNET_free (h2); 90 GNUNET_free (h2);
79 91
80} 92}
81 93
82 94
83static void 95static void
84process (void *cls, const struct GNUNET_PeerIdentity *peer, 96process (void *cls,
85 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 97 const struct GNUNET_PeerIdentity *peer,
98 const struct GNUNET_HELLO_Message *hello,
99 const char *err_msg)
86{ 100{
87 if (err_msg != NULL) 101 if (NULL != err_msg)
88 { 102 {
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 103 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
90 _("Error in communication with PEERINFO service\n")); 104 "Error in communication with PEERINFO service: %s\n",
105 err_msg);
91 } 106 }
92 107 if (NULL == peer)
93 if (peer == NULL)
94 { 108 {
95 ic = NULL; 109 ic = NULL;
96 if ((3 == global_ret) && (retries < 50)) 110 if ((3 == global_ret) && (retries < 50))
@@ -98,29 +112,26 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
98 /* try again */ 112 /* try again */
99 retries++; 113 retries++;
100 add_peer (); 114 add_peer ();
101 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, 115 ic = GNUNET_PEERINFO_iterate (h,
102 GNUNET_TIME_relative_multiply 116 GNUNET_NO,
103 (GNUNET_TIME_UNIT_SECONDS, 15), &process, 117 NULL,
118 &process,
104 cls); 119 cls);
105 return; 120 return;
106 } 121 }
107 GNUNET_assert (peer == NULL); 122 GNUNET_assert (peer == NULL);
108 GNUNET_assert (2 == global_ret);
109 GNUNET_PEERINFO_disconnect (h); 123 GNUNET_PEERINFO_disconnect (h);
110 h = NULL; 124 h = NULL;
111 global_ret = 0; 125 global_ret = 0;
112 return; 126 return;
113 } 127 }
114 128
115 if (hello == NULL) 129 if ( (NULL != hello) &&
116 { 130 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) )
117 GNUNET_assert (3 == global_ret);
118 global_ret = 2;
119 }
120 else
121 { 131 {
122 fprintf (stderr, "Received %s HELLO\n", 132 fprintf (stderr,
123 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public"); 133 "Received friend-only HELLO\n");
134 global_ret = 1;
124 GNUNET_PEERINFO_disconnect (h); 135 GNUNET_PEERINFO_disconnect (h);
125 h = NULL; 136 h = NULL;
126 return; 137 return;
@@ -136,14 +147,17 @@ run (void *cls,
136 h = GNUNET_PEERINFO_connect (cfg); 147 h = GNUNET_PEERINFO_connect (cfg);
137 GNUNET_assert (NULL != h); 148 GNUNET_assert (NULL != h);
138 add_peer (); 149 add_peer ();
139 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid, 150 ic = GNUNET_PEERINFO_iterate (h,
140 GNUNET_TIME_relative_multiply 151 GNUNET_NO,
141 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); 152 &pid,
153 &process,
154 NULL);
142} 155}
143 156
144 157
145int 158int
146main (int argc, char *argv[]) 159main (int argc,
160 char *argv[])
147{ 161{
148 global_ret = 3; 162 global_ret = 3;
149 if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", 163 if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",