aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/arm/test_exponential_backoff.c3
-rw-r--r--src/cadet/cadet.conf.in2
-rw-r--r--src/cadet/cadet_api.c20
-rw-r--r--src/cadet/gnunet-cadet.c2
-rw-r--r--src/core/test_core_api_reliability.c4
-rw-r--r--src/core/test_core_quota_compliance.c5
-rw-r--r--src/datacache/plugin_datacache_sqlite.c5
-rw-r--r--src/gns/gns_api.c7
-rw-r--r--src/gns/gnunet-dns2gns.c1
-rw-r--r--src/gns/gnunet-gns.c10
-rw-r--r--src/gns/nss/nss_gns.c269
-rw-r--r--src/gns/nss/nss_gns_query.c25
-rw-r--r--src/gns/nss/nss_gns_query.h30
-rw-r--r--src/gns/plugin_rest_gns.c11
-rw-r--r--src/gnsrecord/plugin_gnsrecord_dns.c4
-rw-r--r--src/identity-provider/identity-token.conf2
-rw-r--r--src/identity-provider/jwt.c189
-rw-r--r--src/identity-provider/jwt.h9
-rw-r--r--src/identity-provider/test_idp.conf33
-rwxr-xr-xsrc/identity-provider/test_idp.sh31
-rwxr-xr-xsrc/identity-provider/test_idp_attribute.sh40
-rwxr-xr-xsrc/identity-provider/test_idp_consume.sh43
-rwxr-xr-xsrc/identity-provider/test_idp_issue.sh42
-rwxr-xr-xsrc/identity-provider/test_idp_revoke.sh65
-rw-r--r--src/identity/gnunet-service-identity.c49
-rw-r--r--src/identity/identity_api_lookup.c8
-rw-r--r--src/identity/plugin_rest_identity.c7
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/gnunet_abe_lib.h2
-rw-r--r--src/include/gnunet_common.h4
-rw-r--r--src/include/gnunet_crypto_lib.h26
-rw-r--r--src/include/gnunet_dnsparser_lib.h53
-rw-r--r--src/include/gnunet_gnsrecord_lib.h10
-rw-r--r--src/include/gnunet_protocols.h30
-rw-r--r--src/include/gnunet_reclaim_attribute_lib.h (renamed from src/include/gnunet_identity_attribute_lib.h)64
-rw-r--r--src/include/gnunet_reclaim_attribute_plugin.h (renamed from src/include/gnunet_identity_attribute_plugin.h)24
-rw-r--r--src/include/gnunet_reclaim_plugin.h (renamed from src/include/gnunet_identity_provider_plugin.h)28
-rw-r--r--src/include/gnunet_reclaim_service.h (renamed from src/include/gnunet_identity_provider_service.h)116
-rw-r--r--src/include/gnunet_signatures.h6
-rw-r--r--src/include/gnunet_strings_lib.h8
-rw-r--r--src/multicast/gnunet-service-multicast.c18
-rw-r--r--src/multicast/test_multicast_multipeer.c2
-rw-r--r--src/namestore/gnunet-zoneimport.c15
-rw-r--r--src/namestore/plugin_namestore_flat.c65
-rw-r--r--src/psyc/Makefile.am4
-rw-r--r--src/reclaim-attribute/Makefile.am (renamed from src/identity-attribute/Makefile.am)20
-rw-r--r--src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c (renamed from src/identity-attribute/plugin_identity_attribute_gnuid.c)22
-rw-r--r--src/reclaim-attribute/reclaim_attribute.c (renamed from src/identity-attribute/identity_attribute.c)110
-rw-r--r--src/reclaim-attribute/reclaim_attribute.h (renamed from src/identity-attribute/identity_attribute.h)10
-rw-r--r--src/reclaim/.gitignore (renamed from src/identity-provider/.gitignore)0
-rw-r--r--src/reclaim/Makefile.am (renamed from src/identity-provider/Makefile.am)95
-rw-r--r--src/reclaim/gnunet-reclaim.c (renamed from src/identity-provider/gnunet-idp.c)269
-rw-r--r--src/reclaim/gnunet-service-reclaim.c (renamed from src/identity-provider/gnunet-service-identity-provider.c)206
-rw-r--r--src/reclaim/jwt.c1
-rw-r--r--src/reclaim/oidc_helper.c440
-rw-r--r--src/reclaim/oidc_helper.h109
-rw-r--r--src/reclaim/plugin_gnsrecord_reclaim.c (renamed from src/identity-provider/plugin_gnsrecord_identity_provider.c)12
-rw-r--r--src/reclaim/plugin_reclaim_sqlite.c (renamed from src/identity-provider/plugin_identity_provider_sqlite.c)72
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c (renamed from src/identity-provider/plugin_rest_openid_connect.c)787
-rw-r--r--src/reclaim/plugin_rest_reclaim.c (renamed from src/identity-provider/plugin_rest_identity_provider.c)118
-rw-r--r--src/reclaim/reclaim.conf (renamed from src/identity-provider/identity-provider.conf)15
-rw-r--r--src/reclaim/reclaim.h (renamed from src/identity-provider/identity_provider.h)24
-rw-r--r--src/reclaim/reclaim_api.c (renamed from src/identity-provider/identity_provider_api.c)345
-rwxr-xr-xsrc/reclaim/test_reclaim.sh31
-rwxr-xr-xsrc/reclaim/test_reclaim_attribute.sh40
-rwxr-xr-xsrc/reclaim/test_reclaim_consume.sh43
-rw-r--r--src/reclaim/test_reclaim_defaults.conf (renamed from src/identity-provider/test_idp_defaults.conf)0
-rwxr-xr-xsrc/reclaim/test_reclaim_issue.sh42
-rwxr-xr-xsrc/reclaim/test_reclaim_revoke.sh65
-rw-r--r--src/rest/Makefile.am12
-rw-r--r--src/rest/plugin_rest_copying.c231
-rw-r--r--src/rps/gnunet-rps-profiler.c284
-rw-r--r--src/rps/gnunet-service-rps.c676
-rw-r--r--src/rps/gnunet-service-rps_custommap.c2
-rw-r--r--src/rps/rps-test_util.c80
-rw-r--r--src/set/gnunet-service-set_intersection.c19
-rw-r--r--src/set/gnunet-service-set_union.c39
-rw-r--r--src/transport/test_quota_compliance.c4
-rw-r--r--src/transport/test_transport_api_reliability.c4
-rw-r--r--src/util/.gitignore4
-rw-r--r--src/util/Makefile.am16
-rw-r--r--src/util/client.c13
-rw-r--r--src/util/crypto_hash.c26
-rw-r--r--src/util/dnsparser.c125
-rw-r--r--src/util/gnunet-service-resolver.c1173
-rw-r--r--src/util/gnunet-timeout-w32.c191
-rw-r--r--src/util/gnunet-timeout.c128
-rw-r--r--src/util/resolver.h4
-rw-r--r--src/util/resolver_api.c26
-rw-r--r--src/util/scheduler.c189
-rw-r--r--src/util/strings.c39
92 files changed, 4464 insertions, 3096 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 00f30adc3..4ded81891 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,11 +19,13 @@ if HAVE_EXPERIMENTAL
19 social 19 social
20# dv (FTBFS) 20# dv (FTBFS)
21if HAVE_ABE 21if HAVE_ABE
22if HAVE_JSON
22 EXP_DIR += \ 23 EXP_DIR += \
23 abe \ 24 abe \
24 credential \ 25 credential \
25 identity-attribute \ 26 reclaim-attribute \
26 identity-provider 27 reclaim
28endif
27endif 29endif
28if HAVE_JSON 30if HAVE_JSON
29 EXP_DIR += \ 31 EXP_DIR += \
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c
index 4a7d51bc7..f15bca2db 100644
--- a/src/arm/test_exponential_backoff.c
+++ b/src/arm/test_exponential_backoff.c
@@ -343,7 +343,10 @@ init ()
343 cfg = GNUNET_CONFIGURATION_create (); 343 cfg = GNUNET_CONFIGURATION_create ();
344 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, 344 if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg,
345 "test_arm_api_data.conf")) 345 "test_arm_api_data.conf"))
346 {
347 GNUNET_CONFIGURATION_destroy (cfg);
346 return GNUNET_SYSERR; 348 return GNUNET_SYSERR;
349 }
347 if (NULL == getcwd (pwd, PATH_MAX)) 350 if (NULL == getcwd (pwd, PATH_MAX))
348 return GNUNET_SYSERR; 351 return GNUNET_SYSERR;
349 GNUNET_assert (0 < GNUNET_asprintf (&binary, 352 GNUNET_assert (0 < GNUNET_asprintf (&binary,
diff --git a/src/cadet/cadet.conf.in b/src/cadet/cadet.conf.in
index 2f4c6a6db..d1ddcb96f 100644
--- a/src/cadet/cadet.conf.in
+++ b/src/cadet/cadet.conf.in
@@ -8,7 +8,7 @@ BINARY = gnunet-service-cadet
8ACCEPT_FROM = 127.0.0.1; 8ACCEPT_FROM = 127.0.0.1;
9ACCEPT_FROM6 = ::1; 9ACCEPT_FROM6 = ::1;
10UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-cadet.sock 10UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-cadet.sock
11UNIX_MATCH_UID = YES 11UNIX_MATCH_UID = NO
12UNIX_MATCH_GID = YES 12UNIX_MATCH_GID = YES
13 13
14 14
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 980b9abbf..e2ca461a5 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -841,6 +841,7 @@ handle_mq_error (void *cls,
841 h); 841 h);
842 GNUNET_MQ_destroy (h->mq); 842 GNUNET_MQ_destroy (h->mq);
843 h->mq = NULL; 843 h->mq = NULL;
844 GNUNET_assert (NULL == h->reconnect_task);
844 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time, 845 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
845 &reconnect_cbk, 846 &reconnect_cbk,
846 h); 847 h);
@@ -1253,18 +1254,21 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
1253void 1254void
1254GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) 1255GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
1255{ 1256{
1256 struct GNUNET_CADET_PortMessage *msg;
1257 struct GNUNET_MQ_Envelope *env;
1258
1259 GNUNET_assert (GNUNET_YES == 1257 GNUNET_assert (GNUNET_YES ==
1260 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, 1258 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports,
1261 &p->id, 1259 &p->id,
1262 p)); 1260 p));
1263 env = GNUNET_MQ_msg (msg, 1261 if (NULL != p->cadet->mq)
1264 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE); 1262 {
1265 msg->port = p->id; 1263 struct GNUNET_CADET_PortMessage *msg;
1266 GNUNET_MQ_send (p->cadet->mq, 1264 struct GNUNET_MQ_Envelope *env;
1267 env); 1265
1266 env = GNUNET_MQ_msg (msg,
1267 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE);
1268 msg->port = p->id;
1269 GNUNET_MQ_send (p->cadet->mq,
1270 env);
1271 }
1268 GNUNET_free_non_null (p->handlers); 1272 GNUNET_free_non_null (p->handlers);
1269 GNUNET_free (p); 1273 GNUNET_free (p);
1270} 1274}
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index d629df9b2..13b04b885 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -231,7 +231,7 @@ shutdown_task (void *cls)
231 } 231 }
232} 232}
233 233
234void * 234void
235mq_cb(void *cls) 235mq_cb(void *cls)
236{ 236{
237 listen_stdio (); 237 listen_stdio ();
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 4cc5b4bcd..c7c71f1f1 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.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*/
@@ -143,6 +143,8 @@ do_shutdown (void *cls)
143 unsigned long long delta; 143 unsigned long long delta;
144 144
145 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 145 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
146 if (0 == delta)
147 delta = 1;
146 FPRINTF (stderr, 148 FPRINTF (stderr,
147 "\nThroughput was %llu kb/s\n", 149 "\nThroughput was %llu kb/s\n",
148 total_bytes * 1000000LL / 1024 / delta); 150 total_bytes * 1000000LL / 1024 / delta);
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index a15105556..caff045f0 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.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*/
@@ -227,7 +227,8 @@ measurement_stop (void *cls)
227 running = GNUNET_NO; 227 running = GNUNET_NO;
228 228
229 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 229 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
230 230 if (0 == delta)
231 delta = 1;
231 throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */ 232 throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */
232 throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */ 233 throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */
233 234
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 4684e514c..dc4236a8b 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.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*/
@@ -749,7 +749,8 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
749 " value BLOB NOT NULL," 749 " value BLOB NOT NULL,"
750 " path BLOB DEFAULT '')"); 750 " path BLOB DEFAULT '')");
751 SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds091 (key,type,expire)"); 751 SQLITE3_EXEC (dbh, "CREATE INDEX idx_hashidx ON ds091 (key,type,expire)");
752 SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire ON ds091 (prox,expire)"); 752 SQLITE3_EXEC (dbh, "CREATE INDEX idx_prox_expire ON ds091 (prox,expire)");
753 SQLITE3_EXEC (dbh, "CREATE INDEX idx_expire_only ON ds091 (expire)");
753 plugin = GNUNET_new (struct Plugin); 754 plugin = GNUNET_new (struct Plugin);
754 plugin->env = env; 755 plugin->env = env;
755 plugin->dbh = dbh; 756 plugin->dbh = dbh;
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 0ec9209da..3b658da92 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.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*/
@@ -232,7 +232,6 @@ reconnect (struct GNUNET_GNS_Handle *handle)
232 handle), 232 handle),
233 GNUNET_MQ_handler_end () 233 GNUNET_MQ_handler_end ()
234 }; 234 };
235 struct GNUNET_GNS_LookupRequest *lh;
236 235
237 GNUNET_assert (NULL == handle->mq); 236 GNUNET_assert (NULL == handle->mq);
238 LOG (GNUNET_ERROR_TYPE_DEBUG, 237 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -244,7 +243,9 @@ reconnect (struct GNUNET_GNS_Handle *handle)
244 handle); 243 handle);
245 if (NULL == handle->mq) 244 if (NULL == handle->mq)
246 return; 245 return;
247 for (lh = handle->lookup_head; NULL != lh; lh = lh->next) 246 for (struct GNUNET_GNS_LookupRequest *lh = handle->lookup_head;
247 NULL != lh;
248 lh = lh->next)
248 GNUNET_MQ_send_copy (handle->mq, 249 GNUNET_MQ_send_copy (handle->mq,
249 lh->env); 250 lh->env);
250} 251}
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index e6e53d405..8d39e8c53 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -269,6 +269,7 @@ dns_result_processor (void *cls,
269 } 269 }
270 request->packet = GNUNET_DNSPARSER_parse ((char*)dns, 270 request->packet = GNUNET_DNSPARSER_parse ((char*)dns,
271 r); 271 r);
272 GNUNET_DNSSTUB_resolve_cancel (request->dns_lookup);
272 send_response (request); 273 send_response (request);
273} 274}
274 275
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 149c8a7bb..463348ed3 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.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*/
@@ -65,8 +65,9 @@ static struct GNUNET_GNS_LookupWithTldRequest *lr;
65/** 65/**
66 * Global return value. 66 * Global return value.
67 * 0 on success (default), 67 * 0 on success (default),
68 * 1 on internal failures, 2 on launch failure, 68 * 1 on internal failures
69 * 3 if the name is not a GNS-supported TLD, 69 * 2 on launch failure,
70 * 4 if the name is not a GNS-supported TLD,
70 */ 71 */
71static int global_ret; 72static int global_ret;
72 73
@@ -114,7 +115,7 @@ process_lookup_result (void *cls,
114 lr = NULL; 115 lr = NULL;
115 if (GNUNET_NO == was_gns) 116 if (GNUNET_NO == was_gns)
116 { 117 {
117 global_ret = 3; 118 global_ret = 4; /* not for GNS */
118 GNUNET_SCHEDULER_shutdown (); 119 GNUNET_SCHEDULER_shutdown ();
119 return; 120 return;
120 } 121 }
@@ -183,7 +184,6 @@ run (void *cls,
183 global_ret = 2; 184 global_ret = 2;
184 return; 185 return;
185 } 186 }
186
187 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 187 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
188 NULL); 188 NULL);
189 189
diff --git a/src/gns/nss/nss_gns.c b/src/gns/nss/nss_gns.c
index 9c9233d35..58aab47fd 100644
--- a/src/gns/nss/nss_gns.c
+++ b/src/gns/nss/nss_gns.c
@@ -54,121 +54,126 @@
54 * @return a nss_status code 54 * @return a nss_status code
55 */ 55 */
56enum nss_status 56enum nss_status
57_nss_gns_gethostbyname2_r( 57_nss_gns_gethostbyname2_r(const char *name,
58 const char *name, 58 int af,
59 int af, 59 struct hostent *result,
60 struct hostent * result, 60 char *buffer,
61 char *buffer, 61 size_t buflen,
62 size_t buflen, 62 int *errnop,
63 int *errnop, 63 int *h_errnop)
64 int *h_errnop) { 64{
65 65 struct userdata u;
66 struct userdata u; 66 enum nss_status status = NSS_STATUS_UNAVAIL;
67 enum nss_status status = NSS_STATUS_UNAVAIL; 67 int i;
68 int i; 68 size_t address_length;
69 size_t address_length, l, idx, astart; 69 size_t l;
70 70 size_t idx;
71 if (af == AF_UNSPEC) 71 size_t astart;
72
73 if (af == AF_UNSPEC)
72#ifdef NSS_IPV6_ONLY 74#ifdef NSS_IPV6_ONLY
73 af = AF_INET6; 75 af = AF_INET6;
74#else 76#else
75 af = AF_INET; 77 af = AF_INET;
76#endif 78#endif
77 79
78#ifdef NSS_IPV4_ONLY 80#ifdef NSS_IPV4_ONLY
79 if (af != AF_INET) 81 if (af != AF_INET)
80#elif NSS_IPV6_ONLY 82#elif NSS_IPV6_ONLY
81 if (af != AF_INET6) 83 if (af != AF_INET6)
82#else 84#else
83 if (af != AF_INET && af != AF_INET6) 85 if ( (af != AF_INET) &&
86 (af != AF_INET6) )
84#endif 87#endif
85 { 88 {
86 *errnop = EINVAL; 89 *errnop = EINVAL;
87 *h_errnop = NO_RECOVERY; 90 *h_errnop = NO_RECOVERY;
88 91
89 goto finish; 92 goto finish;
90 } 93 }
91
92 address_length = af == AF_INET ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t);
93 if (buflen <
94 sizeof(char*)+ /* alias names */
95 strlen(name)+1) { /* official name */
96
97 *errnop = ERANGE;
98 *h_errnop = NO_RECOVERY;
99 status = NSS_STATUS_TRYAGAIN;
100
101 goto finish;
102 }
103
104 u.count = 0;
105 u.data_len = 0;
106
107 i = gns_resolve_name(af, name, &u);
108 if (-3 == i)
109 {
110 status = NSS_STATUS_NOTFOUND;
111 goto finish;
112 }
113 if (-2 == i)
114 {
115 status = NSS_STATUS_UNAVAIL;
116 goto finish;
117 }
118 if ( (-1 == i) ||
119 (u.count == 0) )
120 {
121 *errnop = ETIMEDOUT;
122 *h_errnop = HOST_NOT_FOUND;
123 status = NSS_STATUS_NOTFOUND;
124 goto finish;
125 }
126
127
128 /* Alias names */
129 *((char**) buffer) = NULL;
130 result->h_aliases = (char**) buffer;
131 idx = sizeof(char*);
132
133 /* Official name */
134 strcpy(buffer+idx, name);
135 result->h_name = buffer+idx;
136 idx += strlen(name)+1;
137
138 ALIGN(idx);
139
140 result->h_addrtype = af;
141 result->h_length = address_length;
142
143 /* Check if there's enough space for the addresses */
144 if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1)) {
145 *errnop = ERANGE;
146 *h_errnop = NO_RECOVERY;
147 status = NSS_STATUS_TRYAGAIN;
148 goto finish;
149 }
150 94
95 address_length = (af == AF_INET) ? sizeof(ipv4_address_t) : sizeof(ipv6_address_t);
96 if (buflen <
97 sizeof(char*)+ /* alias names */
98 strlen(name)+1)
99 { /* official name */
100 *errnop = ERANGE;
101 *h_errnop = NO_RECOVERY;
102 status = NSS_STATUS_TRYAGAIN;
103
104 goto finish;
105 }
106 u.count = 0;
107 u.data_len = 0;
108 i = gns_resolve_name (af,
109 name,
110 &u);
111 if (-3 == i)
112 {
113 status = NSS_STATUS_NOTFOUND;
114 goto finish;
115 }
116 if (-2 == i)
117 {
118 status = NSS_STATUS_UNAVAIL;
119 goto finish;
120 }
121 if ( (-1 == i) ||
122 (u.count == 0) )
123 {
124 *errnop = ETIMEDOUT;
125 *h_errnop = HOST_NOT_FOUND;
126 status = NSS_STATUS_NOTFOUND;
127 goto finish;
128 }
129 /* Alias names */
130 *((char**) buffer) = NULL;
131 result->h_aliases = (char**) buffer;
132 idx = sizeof(char*);
133
134 /* Official name */
135 strcpy (buffer+idx,
136 name);
137 result->h_name = buffer+idx;
138 idx += strlen (name)+1;
139
140 ALIGN(idx);
141
142 result->h_addrtype = af;
143 result->h_length = address_length;
144
145 /* Check if there's enough space for the addresses */
146 if (buflen < idx+u.data_len+sizeof(char*)*(u.count+1))
147 {
148 *errnop = ERANGE;
149 *h_errnop = NO_RECOVERY;
150 status = NSS_STATUS_TRYAGAIN;
151 goto finish;
152 }
151 /* Addresses */ 153 /* Addresses */
152 astart = idx; 154 astart = idx;
153 l = u.count*address_length; 155 l = u.count*address_length;
154 if (0 != l) 156 if (0 != l)
155 memcpy(buffer+astart, &u.data, l); 157 memcpy (buffer+astart,
156 /* address_length is a multiple of 32bits, so idx is still aligned 158 &u.data,
157 * correctly */ 159 l);
158 idx += l; 160 /* address_length is a multiple of 32bits, so idx is still aligned
159 161 * correctly */
160 /* Address array address_length is always a multiple of 32bits */ 162 idx += l;
161 for (i = 0; i < u.count; i++) 163
162 ((char**) (buffer+idx))[i] = buffer+astart+address_length*i; 164 /* Address array address_length is always a multiple of 32bits */
163 ((char**) (buffer+idx))[i] = NULL; 165 for (i = 0; i < u.count; i++)
164 result->h_addr_list = (char**) (buffer+idx); 166 ((char**) (buffer+idx))[i] = buffer+astart+address_length*i;
165 167 ((char**) (buffer+idx))[i] = NULL;
166 status = NSS_STATUS_SUCCESS; 168 result->h_addr_list = (char**) (buffer+idx);
169
170 status = NSS_STATUS_SUCCESS;
167 171
168finish: 172finish:
169 return status; 173 return status;
170} 174}
171 175
176
172/** 177/**
173 * The gethostbyname hook executed by nsswitch 178 * The gethostbyname hook executed by nsswitch
174 * 179 *
@@ -176,29 +181,28 @@ finish:
176 * @param result the result hostent 181 * @param result the result hostent
177 * @param buffer the result buffer 182 * @param buffer the result buffer
178 * @param buflen length of the buffer 183 * @param buflen length of the buffer
179 * @param errnop idk 184 * @param errnop[out] the low-level error code to return to the application
180 * @param h_errnop idk 185 * @param h_errnop idk
181 * @return a nss_status code 186 * @return a nss_status code
182 */ 187 */
183enum nss_status 188enum nss_status
184_nss_gns_gethostbyname_r ( 189_nss_gns_gethostbyname_r (const char *name,
185 const char *name, 190 struct hostent *result,
186 struct hostent *result, 191 char *buffer,
187 char *buffer, 192 size_t buflen,
188 size_t buflen, 193 int *errnop,
189 int *errnop, 194 int *h_errnop)
190 int *h_errnop) { 195{
191 196 return _nss_gns_gethostbyname2_r (name,
192 return _nss_gns_gethostbyname2_r( 197 AF_UNSPEC,
193 name, 198 result,
194 AF_UNSPEC, 199 buffer,
195 result, 200 buflen,
196 buffer, 201 errnop,
197 buflen, 202 h_errnop);
198 errnop,
199 h_errnop);
200} 203}
201 204
205
202/** 206/**
203 * The gethostbyaddr hook executed by nsswitch 207 * The gethostbyaddr hook executed by nsswitch
204 * We can't do this so we always return NSS_STATUS_UNAVAIL 208 * We can't do this so we always return NSS_STATUS_UNAVAIL
@@ -209,23 +213,22 @@ _nss_gns_gethostbyname_r (
209 * @param result the result hostent 213 * @param result the result hostent
210 * @param buffer the result buffer 214 * @param buffer the result buffer
211 * @param buflen length of the buffer 215 * @param buflen length of the buffer
212 * @param errnop idk 216 * @param errnop[out] the low-level error code to return to the application
213 * @param h_errnop idk 217 * @param h_errnop idk
214 * @return NSS_STATUS_UNAVAIL 218 * @return NSS_STATUS_UNAVAIL
215 */ 219 */
216enum nss_status 220enum nss_status
217_nss_gns_gethostbyaddr_r( 221_nss_gns_gethostbyaddr_r (const void* addr,
218 const void* addr, 222 int len,
219 int len, 223 int af,
220 int af, 224 struct hostent *result,
221 struct hostent *result, 225 char *buffer,
222 char *buffer, 226 size_t buflen,
223 size_t buflen, 227 int *errnop,
224 int *errnop, 228 int *h_errnop)
225 int *h_errnop) { 229{
226 230 *errnop = EINVAL;
227 *errnop = EINVAL; 231 *h_errnop = NO_RECOVERY;
228 *h_errnop = NO_RECOVERY; 232 //NOTE we allow to leak this into DNS so no NOTFOUND
229 //NOTE we allow to leak this into DNS so no NOTFOUND 233 return NSS_STATUS_UNAVAIL;
230 return NSS_STATUS_UNAVAIL;
231} 234}
diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c
index 094e25ed5..867ead624 100644
--- a/src/gns/nss/nss_gns_query.c
+++ b/src/gns/nss/nss_gns_query.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*/
@@ -48,14 +48,16 @@ gns_resolve_name (int af,
48 { 48 {
49 if (-1 == asprintf (&cmd, 49 if (-1 == asprintf (&cmd,
50 "%s -t AAAA -u %s\n", 50 "%s -t AAAA -u %s\n",
51 "gnunet-gns -r", name)) 51 "gnunet-gns -r",
52 name))
52 return -1; 53 return -1;
53 } 54 }
54 else 55 else
55 { 56 {
56 if (-1 == asprintf (&cmd, 57 if (-1 == asprintf (&cmd,
57 "%s %s\n", 58 "%s %s\n",
58 "gnunet-gns -r -u", name)) 59 "gnunet-gns -r -u",
60 name))
59 return -1; 61 return -1;
60 } 62 }
61 if (NULL == (p = popen (cmd, "r"))) 63 if (NULL == (p = popen (cmd, "r")))
@@ -63,7 +65,9 @@ gns_resolve_name (int af,
63 free (cmd); 65 free (cmd);
64 return -1; 66 return -1;
65 } 67 }
66 while (NULL != fgets (line, sizeof(line), p)) 68 while (NULL != fgets (line,
69 sizeof(line),
70 p))
67 { 71 {
68 if (u->count >= MAX_ENTRIES) 72 if (u->count >= MAX_ENTRIES)
69 break; 73 break;
@@ -72,7 +76,9 @@ gns_resolve_name (int af,
72 line[strlen(line)-1] = '\0'; 76 line[strlen(line)-1] = '\0';
73 if (AF_INET == af) 77 if (AF_INET == af)
74 { 78 {
75 if (inet_pton(af, line, &(u->data.ipv4[u->count]))) 79 if (inet_pton(af,
80 line,
81 &u->data.ipv4[u->count]))
76 { 82 {
77 u->count++; 83 u->count++;
78 u->data_len += sizeof(ipv4_address_t); 84 u->data_len += sizeof(ipv4_address_t);
@@ -86,7 +92,9 @@ gns_resolve_name (int af,
86 } 92 }
87 else if (AF_INET6 == af) 93 else if (AF_INET6 == af)
88 { 94 {
89 if (inet_pton(af, line, &(u->data.ipv6[u->count]))) 95 if (inet_pton(af,
96 line,
97 &u->data.ipv6[u->count]))
90 { 98 {
91 u->count++; 99 u->count++;
92 u->data_len += sizeof(ipv6_address_t); 100 u->data_len += sizeof(ipv6_address_t);
@@ -105,7 +113,10 @@ gns_resolve_name (int af,
105 if (4 == ret) 113 if (4 == ret)
106 return -2; /* not for GNS */ 114 return -2; /* not for GNS */
107 if (3 == ret) 115 if (3 == ret)
108 return -3; /* timeout */ 116 return -3; /* timeout -> not found */
117 if ( (2 == ret) || (1 == ret) )
118 return -2; /* launch failure -> service unavailable */
109 return 0; 119 return 0;
110} 120}
121
111/* end of nss_gns_query.c */ 122/* end of nss_gns_query.c */
diff --git a/src/gns/nss/nss_gns_query.h b/src/gns/nss/nss_gns_query.h
index bb04f9004..48cab4b22 100644
--- a/src/gns/nss/nss_gns_query.h
+++ b/src/gns/nss/nss_gns_query.h
@@ -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*/
@@ -26,25 +26,30 @@
26/* Maximum number of entries to return */ 26/* Maximum number of entries to return */
27#define MAX_ENTRIES 16 27#define MAX_ENTRIES 16
28 28
29typedef struct { 29typedef struct
30 uint32_t address; 30{
31 uint32_t address;
31} ipv4_address_t; 32} ipv4_address_t;
32 33
33typedef struct { 34
34 uint8_t address[16]; 35typedef struct
36{
37 uint8_t address[16];
35} ipv6_address_t; 38} ipv6_address_t;
36 39
37 40
38struct userdata { 41struct userdata
42{
39 int count; 43 int count;
40 int data_len; /* only valid when doing reverse lookup */ 44 int data_len; /* only valid when doing reverse lookup */
41 union { 45 union {
42 ipv4_address_t ipv4[MAX_ENTRIES]; 46 ipv4_address_t ipv4[MAX_ENTRIES];
43 ipv6_address_t ipv6[MAX_ENTRIES]; 47 ipv6_address_t ipv6[MAX_ENTRIES];
44 char *name[MAX_ENTRIES]; 48 char *name[MAX_ENTRIES];
45 } data; 49 } data;
46}; 50};
47 51
52
48/** 53/**
49 * Wrapper function that uses gnunet-gns cli tool to resolve 54 * Wrapper function that uses gnunet-gns cli tool to resolve
50 * an IPv4/6 address. 55 * an IPv4/6 address.
@@ -54,8 +59,9 @@ struct userdata {
54 * @param u the userdata (result struct) 59 * @param u the userdata (result struct)
55 * @return -1 on error else 0 60 * @return -1 on error else 0
56 */ 61 */
57int gns_resolve_name(int af, 62int
58 const char *name, 63gns_resolve_name(int af,
59 struct userdata *userdata); 64 const char *name,
65 struct userdata *userdata);
60 66
61#endif 67#endif
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 2b729db54..e76a5d116 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -281,6 +281,15 @@ gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
281 return record_obj; 281 return record_obj;
282} 282}
283 283
284
285static void
286do_cleanup (void *cls)
287{
288 struct LookupHandle *handle = cls;
289 cleanup_handle (handle);
290}
291
292
284/** 293/**
285 * Function called with the result of a GNS lookup. 294 * Function called with the result of a GNS lookup.
286 * 295 *
@@ -325,7 +334,7 @@ process_lookup_result (void *cls, uint32_t rd_count,
325 resp = GNUNET_REST_create_response (result); 334 resp = GNUNET_REST_create_response (result);
326 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 335 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
327 GNUNET_free (result); 336 GNUNET_free (result);
328 cleanup_handle (handle); 337 GNUNET_SCHEDULER_add_now (&do_cleanup, handle);
329} 338}
330 339
331 340
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c
index 188afcae7..254ae15ea 100644
--- a/src/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/gnsrecord/plugin_gnsrecord_dns.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*/
@@ -463,7 +463,7 @@ dns_string_to_value (void *cls,
463 } 463 }
464 cert_size = GNUNET_STRINGS_base64_decode (certp, 464 cert_size = GNUNET_STRINGS_base64_decode (certp,
465 strlen (certp), 465 strlen (certp),
466 &cert_data); 466 (void **) &cert_data);
467 GNUNET_free (sdup); 467 GNUNET_free (sdup);
468 cert.cert_type = type; 468 cert.cert_type = type;
469 cert.cert_tag = key; 469 cert.cert_tag = key;
diff --git a/src/identity-provider/identity-token.conf b/src/identity-provider/identity-token.conf
deleted file mode 100644
index f29f6cdf3..000000000
--- a/src/identity-provider/identity-token.conf
+++ /dev/null
@@ -1,2 +0,0 @@
1[identity-token]
2BINARY=gnunet-service-identity-token
diff --git a/src/identity-provider/jwt.c b/src/identity-provider/jwt.c
deleted file mode 100644
index 1a984f7b5..000000000
--- a/src/identity-provider/jwt.c
+++ /dev/null
@@ -1,189 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17 */
18
19/**
20 * @file identity-provider/jwt.c
21 * @brief helper library for JSON-Web-Tokens
22 * @author Martin Schanzenbach
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_signatures.h"
27#include "gnunet_identity_attribute_lib.h"
28#include <jansson.h>
29
30
31#define JWT_ALG "alg"
32
33/*TODO is this the correct way to define new algs? */
34#define JWT_ALG_VALUE "urn:org:gnunet:jwt:alg:ecdsa:ed25519"
35
36#define JWT_TYP "typ"
37
38#define JWT_TYP_VALUE "jwt"
39
40//TODO change server address
41#define SERVER_ADDRESS "https://localhost"
42
43static char*
44create_jwt_header(void)
45{
46 json_t *root;
47 char *json_str;
48
49 root = json_object ();
50 json_object_set_new (root, JWT_ALG, json_string (JWT_ALG_VALUE));
51 json_object_set_new (root, JWT_TYP, json_string (JWT_TYP_VALUE));
52
53 json_str = json_dumps (root, JSON_INDENT(1));
54 json_decref (root);
55 return json_str;
56}
57
58/**
59 * Create a JWT from attributes
60 *
61 * @param aud_key the public of the subject
62 * @param attrs the attribute list
63 * @param priv_key the key used to sign the JWT
64 * @return a new base64-encoded JWT string.
65 */
66char*
67jwt_create_from_list (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
68 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
69 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key)
70{
71 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
72 struct GNUNET_CRYPTO_EcdsaPublicKey sub_key;
73 struct GNUNET_CRYPTO_EcdsaSignature signature;
74 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
75 char* audience;
76 char* subject;
77 char* header;
78 char* padding;
79 char* body_str;
80 char* result;
81 char* header_base64;
82 char* body_base64;
83 char* signature_target;
84 char* signature_base64;
85 char* attr_val_str;
86 json_t* body;
87
88 //exp REQUIRED time expired from config
89 //iat REQUIRED time now
90 //auth_time only if max_age
91 //nonce only if nonce
92 // OPTIONAL acr,amr,azp
93 GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &sub_key);
94 /* TODO maybe we should use a local identity here */
95 subject = GNUNET_STRINGS_data_to_string_alloc (&sub_key,
96 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
97 audience = GNUNET_STRINGS_data_to_string_alloc (aud_key,
98 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
99 header = create_jwt_header ();
100 body = json_object ();
101 /* TODO who is the issuer? local IdP or subject ? See self-issued tokens? */
102 //iss REQUIRED case sensitive server uri with https
103 json_object_set_new (body,
104 "iss", json_string (SERVER_ADDRESS));
105 //sub REQUIRED public key identity, not exceed 255 ASCII length
106 json_object_set_new (body,
107 "sub", json_string (subject));
108 /* TODO what should be in here exactly? */
109 //aud REQUIRED public key client_id must be there
110 json_object_set_new (body,
111 "aud", json_string (audience));
112 for (le = attrs->list_head; NULL != le; le = le->next)
113 {
114 /**
115 * TODO here we should have a function that
116 * calls the Attribute plugins to create a
117 * json representation for its value
118 */
119 attr_val_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (le->claim->type,
120 le->claim->data,
121 le->claim->data_size);
122 json_object_set_new (body,
123 le->claim->name,
124 json_string (attr_val_str));
125 GNUNET_free (attr_val_str);
126 }
127 body_str = json_dumps (body, JSON_INDENT(0));
128 json_decref (body);
129
130 GNUNET_STRINGS_base64_encode (header,
131 strlen (header),
132 &header_base64);
133 //Remove GNUNET padding of base64
134 padding = strtok(header_base64, "=");
135 while (NULL != padding)
136 padding = strtok(NULL, "=");
137
138 GNUNET_STRINGS_base64_encode (body_str,
139 strlen (body_str),
140 &body_base64);
141
142 //Remove GNUNET padding of base64
143 padding = strtok(body_base64, "=");
144 while (NULL != padding)
145 padding = strtok(NULL, "=");
146
147 GNUNET_free (subject);
148 GNUNET_free (audience);
149
150 /**
151 * TODO
152 * Creating the JWT signature. This might not be
153 * standards compliant, check.
154 */
155 GNUNET_asprintf (&signature_target, "%s,%s", header_base64, body_base64);
156
157 purpose =
158 GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
159 strlen (signature_target));
160 purpose->size =
161 htonl (strlen (signature_target) + sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
162 purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN);
163 GNUNET_memcpy (&purpose[1], signature_target, strlen (signature_target));
164 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_sign (priv_key,
165 purpose,
166 (struct GNUNET_CRYPTO_EcdsaSignature *)&signature))
167 {
168 GNUNET_free (signature_target);
169 GNUNET_free (body_str);
170 GNUNET_free (body_base64);
171 GNUNET_free (header_base64);
172 GNUNET_free (purpose);
173 return NULL;
174 }
175 GNUNET_STRINGS_base64_encode ((const char*)&signature,
176 sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
177 &signature_base64);
178 GNUNET_asprintf (&result, "%s.%s.%s",
179 header_base64, body_base64, signature_base64);
180
181 GNUNET_free (signature_target);
182 GNUNET_free (header);
183 GNUNET_free (body_str);
184 GNUNET_free (signature_base64);
185 GNUNET_free (body_base64);
186 GNUNET_free (header_base64);
187 GNUNET_free (purpose);
188 return result;
189}
diff --git a/src/identity-provider/jwt.h b/src/identity-provider/jwt.h
deleted file mode 100644
index 072958973..000000000
--- a/src/identity-provider/jwt.h
+++ /dev/null
@@ -1,9 +0,0 @@
1#ifndef JWT_H
2#define JWT_H
3
4char*
5jwt_create_from_list (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
6 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
7 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key);
8
9#endif
diff --git a/src/identity-provider/test_idp.conf b/src/identity-provider/test_idp.conf
deleted file mode 100644
index 3e4df561a..000000000
--- a/src/identity-provider/test_idp.conf
+++ /dev/null
@@ -1,33 +0,0 @@
1@INLINE@ test_idp_defaults.conf
2
3[PATHS]
4GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-idp-peer-1/
5
6[dht]
7START_ON_DEMAND = YES
8
9[rest]
10START_ON_DEMAND = YES
11PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/restlog
12
13[transport]
14PLUGINS =
15
16[identity-provider]
17START_ON_DEMAND = YES
18#PREFIX = valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --log-file=$GNUNET_TMP/idplog
19
20[gns]
21#PREFIX = valgrind --leak-check=full --track-origins=yes
22START_ON_DEMAND = YES
23AUTO_IMPORT_PKEY = YES
24MAX_PARALLEL_BACKGROUND_QUERIES = 10
25DEFAULT_LOOKUP_TIMEOUT = 15 s
26RECORD_PUT_INTERVAL = 1 h
27ZONE_PUBLISH_TIME_WINDOW = 1 h
28DNS_ROOT=PD67SGHF3E0447TU9HADIVU9OM7V4QHTOG0EBU69TFRI2LG63DR0
29
30[identity-rest-plugin]
31address = http://localhost:8000/#/login
32psw = mysupersecretpassword
33expiration_time = 3600
diff --git a/src/identity-provider/test_idp.sh b/src/identity-provider/test_idp.sh
deleted file mode 100755
index 598d1008c..000000000
--- a/src/identity-provider/test_idp.sh
+++ /dev/null
@@ -1,31 +0,0 @@
1#!/bin/bash
2#trap "gnunet-arm -e -c test_idp_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_idp.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_idp.conf
27gnunet-identity -C testego -c test_idp.conf
28valgrind gnunet-idp -e testego -a email -V john@doe.gnu -c test_idp.conf
29gnunet-idp -e testego -a name -V John -c test_idp.conf
30gnunet-idp -e testego -D -c test_idp.conf
31gnunet-arm -e -c test_idp.conf
diff --git a/src/identity-provider/test_idp_attribute.sh b/src/identity-provider/test_idp_attribute.sh
deleted file mode 100755
index 7f0f06dac..000000000
--- a/src/identity-provider/test_idp_attribute.sh
+++ /dev/null
@@ -1,40 +0,0 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_idp.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_idp.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_idp.conf
27#gnunet-arm -i rest -c test_idp.conf
28gnunet-identity -C testego -c test_idp.conf
29gnunet-identity -C rpego -c test_idp.conf
30TEST_KEY=$(gnunet-identity -d -c test_idp.conf | grep testego | awk '{print $3}')
31gnunet-idp -e testego -a email -V john@doe.gnu -c test_idp.conf
32gnunet-idp -e testego -a name -V John -c test_idp.conf > /dev/null 2>&1
33if test $? != 0
34then
35 echo "Failed."
36 exit 1
37fi
38
39#curl localhost:7776/idp/attributes/testego
40gnunet-arm -e -c test_idp.conf
diff --git a/src/identity-provider/test_idp_consume.sh b/src/identity-provider/test_idp_consume.sh
deleted file mode 100755
index 11f6865a4..000000000
--- a/src/identity-provider/test_idp_consume.sh
+++ /dev/null
@@ -1,43 +0,0 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_idp.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_idp.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_idp.conf
27#gnunet-arm -i rest -c test_idp.conf
28gnunet-identity -C testego -c test_idp.conf
29gnunet-identity -C rpego -c test_idp.conf
30SUBJECT_KEY=$(gnunet-identity -d -c test_idp.conf | grep rpego | awk '{print $3}')
31TEST_KEY=$(gnunet-identity -d -c test_idp.conf | grep testego | awk '{print $3}')
32gnunet-idp -e testego -a email -V john@doe.gnu -c test_idp.conf
33gnunet-idp -e testego -a name -V John -c test_idp.conf
34TICKET=$(gnunet-idp -e testego -i "email,name" -r $SUBJECT_KEY -c test_idp.conf | awk '{print $1}')
35gnunet-idp -e rpego -C $TICKET -c test_idp.conf > /dev/null 2>&1
36
37if test $? != 0
38then
39 "Failed."
40 exit 1
41fi
42#curl http://localhost:7776/idp/tickets/testego
43gnunet-arm -e -c test_idp.conf
diff --git a/src/identity-provider/test_idp_issue.sh b/src/identity-provider/test_idp_issue.sh
deleted file mode 100755
index 90487ee73..000000000
--- a/src/identity-provider/test_idp_issue.sh
+++ /dev/null
@@ -1,42 +0,0 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_idp.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_idp.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_idp.conf
27#gnunet-arm -i rest -c test_idp.conf
28gnunet-identity -C testego -c test_idp.conf
29gnunet-identity -C rpego -c test_idp.conf
30SUBJECT_KEY=$(gnunet-identity -d -c test_idp.conf | grep rpego | awk '{print $3}')
31TEST_KEY=$(gnunet-identity -d -c test_idp.conf | grep testego | awk '{print $3}')
32gnunet-idp -e testego -a email -V john@doe.gnu -c test_idp.conf > /dev/null 2>&1
33gnunet-idp -e testego -a name -V John -c test_idp.conf > /dev/null 2>&1
34#gnunet-idp -e testego -D -c test_idp.conf
35gnunet-idp -e testego -i "email,name" -r $SUBJECT_KEY -c test_idp.conf > /dev/null 2>&1
36if test $? != 0
37then
38 echo "Failed."
39 exit 1
40fi
41#curl http://localhost:7776/idp/attributes/testego
42gnunet-arm -e -c test_idp.conf
diff --git a/src/identity-provider/test_idp_revoke.sh b/src/identity-provider/test_idp_revoke.sh
deleted file mode 100755
index 7a3f5d030..000000000
--- a/src/identity-provider/test_idp_revoke.sh
+++ /dev/null
@@ -1,65 +0,0 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_idp.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_idp.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_idp.conf 2&>1 > /dev/null
27gnunet-identity -C alice -c test_idp.conf
28gnunet-identity -C bob -c test_idp.conf
29gnunet-identity -C eve -c test_idp.conf
30ALICE_KEY=$(gnunet-identity -d -c test_idp.conf | grep alice | awk '{print $3}')
31BOB_KEY=$(gnunet-identity -d -c test_idp.conf | grep bob | awk '{print $3}')
32EVE_KEY=$(gnunet-identity -d -c test_idp.conf | grep eve | awk '{print $3}')
33
34gnunet-idp -e alice -E 15s -a email -V john@doe.gnu -c test_idp.conf
35gnunet-idp -e alice -E 15s -a name -V John -c test_idp.conf
36TICKET_BOB=$(gnunet-idp -e alice -i "email,name" -r $BOB_KEY -c test_idp.conf | awk '{print $1}')
37#gnunet-idp -e bob -C $TICKET_BOB -c test_idp.conf
38TICKET_EVE=$(gnunet-idp -e alice -i "email" -r $EVE_KEY -c test_idp.conf | awk '{print $1}')
39
40#echo "Consuming $TICKET"
41#gnunet-idp -e eve -C $TICKET_EVE -c test_idp.conf
42gnunet-idp -e alice -R $TICKET_EVE -c test_idp.conf
43
44#sleep 6
45
46gnunet-idp -e eve -C $TICKET_EVE -c test_idp.conf 2&>1 >/dev/null
47if test $? == 0
48then
49 echo "Eve can still resolve attributes..."
50 gnunet-arm -e -c test_idp.conf
51 exit 1
52fi
53
54gnunet-arm -e -c test_idp.conf
55gnunet-arm -s -c test_idp.conf 2&>1 > /dev/null
56
57gnunet-idp -e bob -C $TICKET_BOB -c test_idp.conf 2&>1 >/dev/null
58if test $? != 0
59then
60 echo "Bob cannot resolve attributes..."
61 gnunet-arm -e -c test_idp.conf
62 exit 1
63fi
64
65gnunet-arm -e -c test_idp.conf
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 6b8e21806..266f5ccc3 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -371,11 +371,12 @@ handle_get_default_message (void *cls,
371 struct GNUNET_MQ_Envelope *env; 371 struct GNUNET_MQ_Envelope *env;
372 struct GNUNET_SERVICE_Client *client = cls; 372 struct GNUNET_SERVICE_Client *client = cls;
373 struct Ego *ego; 373 struct Ego *ego;
374 const char *name; 374 char *name;
375 char *identifier; 375 char *identifier;
376 376
377 377
378 name = (const char *) &gdm[1]; 378 name = GNUNET_strdup ((const char *) &gdm[1]);
379 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name);
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "Received GET_DEFAULT for service `%s' from client\n", 381 "Received GET_DEFAULT for service `%s' from client\n",
381 name); 382 name);
@@ -387,6 +388,7 @@ handle_get_default_message (void *cls,
387 { 388 {
388 send_result_code (client, 1, gettext_noop ("no default known")); 389 send_result_code (client, 1, gettext_noop ("no default known"));
389 GNUNET_SERVICE_client_continue (client); 390 GNUNET_SERVICE_client_continue (client);
391 GNUNET_free (name);
390 return; 392 return;
391 } 393 }
392 for (ego = ego_head; NULL != ego; ego = ego->next) 394 for (ego = ego_head; NULL != ego; ego = ego->next)
@@ -399,6 +401,7 @@ handle_get_default_message (void *cls,
399 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 401 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
400 GNUNET_SERVICE_client_continue (client); 402 GNUNET_SERVICE_client_continue (client);
401 GNUNET_free (identifier); 403 GNUNET_free (identifier);
404 GNUNET_free (name);
402 return; 405 return;
403 } 406 }
404 } 407 }
@@ -406,6 +409,7 @@ handle_get_default_message (void *cls,
406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
407 "Failed to find ego `%s'\n", 410 "Failed to find ego `%s'\n",
408 name); 411 name);
412 GNUNET_free (name);
409 send_result_code (client, 1, 413 send_result_code (client, 1,
410 gettext_noop ("default configured, but ego unknown (internal error)")); 414 gettext_noop ("default configured, but ego unknown (internal error)"));
411 GNUNET_SERVICE_client_continue (client); 415 GNUNET_SERVICE_client_continue (client);
@@ -477,9 +481,11 @@ handle_set_default_message (void *cls,
477{ 481{
478 struct Ego *ego; 482 struct Ego *ego;
479 struct GNUNET_SERVICE_Client *client = cls; 483 struct GNUNET_SERVICE_Client *client = cls;
480 const char *str; 484 char *str;
485
486 str = GNUNET_strdup ((const char *) &sdm[1]);
487 GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str);
481 488
482 str = (const char *) &sdm[1];
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
484 "Received SET_DEFAULT for service `%s' from client\n", 490 "Received SET_DEFAULT for service `%s' from client\n",
485 str); 491 str);
@@ -500,10 +506,12 @@ handle_set_default_message (void *cls,
500 subsystem_cfg_file); 506 subsystem_cfg_file);
501 send_result_code (client, 0, NULL); 507 send_result_code (client, 0, NULL);
502 GNUNET_SERVICE_client_continue (client); 508 GNUNET_SERVICE_client_continue (client);
509 GNUNET_free (str);
503 return; 510 return;
504 } 511 }
505 } 512 }
506 send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); 513 send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
514 GNUNET_free (str);
507 GNUNET_SERVICE_client_continue (client); 515 GNUNET_SERVICE_client_continue (client);
508} 516}
509 517
@@ -585,12 +593,13 @@ handle_create_message (void *cls,
585{ 593{
586 struct GNUNET_SERVICE_Client *client = cls; 594 struct GNUNET_SERVICE_Client *client = cls;
587 struct Ego *ego; 595 struct Ego *ego;
588 const char *str; 596 char *str;
589 char *fn; 597 char *fn;
590 598
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
592 "Received CREATE message from client\n"); 600 "Received CREATE message from client\n");
593 str = (const char *) &crm[1]; 601 str = GNUNET_strdup ((const char *) &crm[1]);
602 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
594 for (ego = ego_head; NULL != ego; ego = ego->next) 603 for (ego = ego_head; NULL != ego; ego = ego->next)
595 { 604 {
596 if (0 == strcmp (ego->identifier, 605 if (0 == strcmp (ego->identifier,
@@ -598,6 +607,7 @@ handle_create_message (void *cls,
598 { 607 {
599 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego")); 608 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego"));
600 GNUNET_SERVICE_client_continue (client); 609 GNUNET_SERVICE_client_continue (client);
610 GNUNET_free (str);
601 return; 611 return;
602 } 612 }
603 } 613 }
@@ -620,6 +630,7 @@ handle_create_message (void *cls,
620 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 630 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
621 "write", fn); 631 "write", fn);
622 GNUNET_free (fn); 632 GNUNET_free (fn);
633 GNUNET_free (str);
623 notify_listeners (ego); 634 notify_listeners (ego);
624 GNUNET_SERVICE_client_continue (client); 635 GNUNET_SERVICE_client_continue (client);
625} 636}
@@ -726,18 +737,22 @@ handle_rename_message (void *cls,
726{ 737{
727 uint16_t old_name_len; 738 uint16_t old_name_len;
728 struct Ego *ego; 739 struct Ego *ego;
729 const char *old_name; 740 char *old_name;
730 const char *new_name; 741 char *new_name;
731 struct RenameContext rename_ctx; 742 struct RenameContext rename_ctx;
732 struct GNUNET_SERVICE_Client *client = cls; 743 struct GNUNET_SERVICE_Client *client = cls;
733 char *fn_old; 744 char *fn_old;
734 char *fn_new; 745 char *fn_new;
746 const char *old_name_tmp;
735 747
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Received RENAME message from client\n"); 749 "Received RENAME message from client\n");
738 old_name_len = ntohs (rm->old_name_len); 750 old_name_len = ntohs (rm->old_name_len);
739 old_name = (const char *) &rm[1]; 751 old_name_tmp = (const char *) &rm[1];
740 new_name = &old_name[old_name_len]; 752 old_name = GNUNET_strdup (old_name_tmp);
753 GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
754 new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
755 GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], old_name);
741 756
742 /* check if new name is already in use */ 757 /* check if new name is already in use */
743 for (ego = ego_head; NULL != ego; ego = ego->next) 758 for (ego = ego_head; NULL != ego; ego = ego->next)
@@ -747,6 +762,8 @@ handle_rename_message (void *cls,
747 { 762 {
748 send_result_code (client, 1, gettext_noop ("target name already exists")); 763 send_result_code (client, 1, gettext_noop ("target name already exists"));
749 GNUNET_SERVICE_client_continue (client); 764 GNUNET_SERVICE_client_continue (client);
765 GNUNET_free (old_name);
766 GNUNET_free (new_name);
750 return; 767 return;
751 } 768 }
752 } 769 }
@@ -776,6 +793,8 @@ handle_rename_message (void *cls,
776 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); 793 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
777 GNUNET_free (fn_old); 794 GNUNET_free (fn_old);
778 GNUNET_free (fn_new); 795 GNUNET_free (fn_new);
796 GNUNET_free (old_name);
797 GNUNET_free (new_name);
779 notify_listeners (ego); 798 notify_listeners (ego);
780 send_result_code (client, 0, NULL); 799 send_result_code (client, 0, NULL);
781 GNUNET_SERVICE_client_continue (client); 800 GNUNET_SERVICE_client_continue (client);
@@ -785,6 +804,8 @@ handle_rename_message (void *cls,
785 804
786 /* failed to locate old name */ 805 /* failed to locate old name */
787 send_result_code (client, 1, gettext_noop ("no matching ego found")); 806 send_result_code (client, 1, gettext_noop ("no matching ego found"));
807 GNUNET_free (old_name);
808 GNUNET_free (new_name);
788 GNUNET_SERVICE_client_continue (client); 809 GNUNET_SERVICE_client_continue (client);
789} 810}
790 811
@@ -868,13 +889,15 @@ handle_delete_message (void *cls,
868 const struct DeleteMessage *dm) 889 const struct DeleteMessage *dm)
869{ 890{
870 struct Ego *ego; 891 struct Ego *ego;
871 const char *name; 892 char *name;
872 char *fn; 893 char *fn;
873 struct GNUNET_SERVICE_Client *client = cls; 894 struct GNUNET_SERVICE_Client *client = cls;
874 895
875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
876 "Received DELETE message from client\n"); 897 "Received DELETE message from client\n");
877 name = (const char *) &dm[1]; 898 name = GNUNET_strdup ((const char *) &dm[1]);
899 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
900
878 for (ego = ego_head; NULL != ego; ego = ego->next) 901 for (ego = ego_head; NULL != ego; ego = ego->next)
879 { 902 {
880 if (0 == strcmp (ego->identifier, 903 if (0 == strcmp (ego->identifier,
@@ -901,6 +924,7 @@ handle_delete_message (void *cls,
901 notify_listeners (ego); 924 notify_listeners (ego);
902 GNUNET_free (ego->pk); 925 GNUNET_free (ego->pk);
903 GNUNET_free (ego); 926 GNUNET_free (ego);
927 GNUNET_free (name);
904 send_result_code (client, 0, NULL); 928 send_result_code (client, 0, NULL);
905 GNUNET_SERVICE_client_continue (client); 929 GNUNET_SERVICE_client_continue (client);
906 return; 930 return;
@@ -908,6 +932,7 @@ handle_delete_message (void *cls,
908 } 932 }
909 933
910 send_result_code (client, 1, gettext_noop ("no matching ego found")); 934 send_result_code (client, 1, gettext_noop ("no matching ego found"));
935 GNUNET_free (name);
911 GNUNET_SERVICE_client_continue (client); 936 GNUNET_SERVICE_client_continue (client);
912} 937}
913 938
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c
index 593a5dbb0..25aec8ede 100644
--- a/src/identity/identity_api_lookup.c
+++ b/src/identity/identity_api_lookup.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*/
@@ -131,6 +131,12 @@ GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
131 el->identity = GNUNET_IDENTITY_connect (cfg, 131 el->identity = GNUNET_IDENTITY_connect (cfg,
132 &identity_cb, 132 &identity_cb,
133 el); 133 el);
134 if (NULL == el->identity)
135 {
136 GNUNET_free (el->name);
137 GNUNET_free (el);
138 return NULL;
139 }
134 return el; 140 return el;
135} 141}
136 142
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index 52685c52e..355d75fd9 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -436,13 +436,6 @@ ego_info_response (struct GNUNET_REST_RequestHandle *con,
436 json_decref (name_str); 436 json_decref (name_str);
437 GNUNET_JSONAPI_document_resource_add (json_document, json_resource); 437 GNUNET_JSONAPI_document_resource_add (json_document, json_resource);
438 } 438 }
439 if (0 == GNUNET_JSONAPI_document_resource_count (json_document))
440 {
441 GNUNET_JSONAPI_document_delete (json_document);
442 handle->emsg = GNUNET_strdup ("No identities found!");
443 GNUNET_SCHEDULER_add_now (&do_error, handle);
444 return;
445 }
446 GNUNET_JSONAPI_document_serialize (json_document, &result_str); 439 GNUNET_JSONAPI_document_serialize (json_document, &result_str);
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
448 resp = GNUNET_REST_create_response (result_str); 441 resp = GNUNET_REST_create_response (result_str);
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 08e9dd156..41b2b1382 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -66,7 +66,7 @@ gnunetinclude_HEADERS = \
66 gnunet_hello_lib.h \ 66 gnunet_hello_lib.h \
67 gnunet_helper_lib.h \ 67 gnunet_helper_lib.h \
68 gnunet_identity_service.h \ 68 gnunet_identity_service.h \
69 gnunet_identity_provider_service.h \ 69 gnunet_reclaim_service.h \
70 gnunet_json_lib.h \ 70 gnunet_json_lib.h \
71 gnunet_jsonapi_lib.h \ 71 gnunet_jsonapi_lib.h \
72 gnunet_jsonapi_util.h \ 72 gnunet_jsonapi_util.h \
diff --git a/src/include/gnunet_abe_lib.h b/src/include/gnunet_abe_lib.h
index d380c9b03..554d4488b 100644
--- a/src/include/gnunet_abe_lib.h
+++ b/src/include/gnunet_abe_lib.h
@@ -87,7 +87,7 @@ GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key,
87 * Delete a CP-ABE key. 87 * Delete a CP-ABE key.
88 * 88 *
89 * @param key the key to delete 89 * @param key the key to delete
90 * @param delete_pub GNUNE_YES if the public key should also be freed (bug in gabe) 90 * @param delete_pub GNUNET_YES if the public key should also be freed (bug in gabe)
91 * @return fresh private key; free using #GNUNET_free 91 * @return fresh private key; free using #GNUNET_free
92 */ 92 */
93void 93void
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index b4bf5b0aa..1b982cc15 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -1074,7 +1074,7 @@ GNUNET_ntoh_double (double d);
1074 * @param tsize the target size for the resulting vector, use 0 to 1074 * @param tsize the target size for the resulting vector, use 0 to
1075 * free the vector (then, arr will be NULL afterwards). 1075 * free the vector (then, arr will be NULL afterwards).
1076 */ 1076 */
1077#define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&arr, sizeof(arr[0]), &size, tsize, __FILE__, __LINE__) 1077#define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&(arr), sizeof((arr)[0]), &size, tsize, __FILE__, __LINE__)
1078 1078
1079/** 1079/**
1080 * @ingroup memory 1080 * @ingroup memory
@@ -1089,7 +1089,7 @@ GNUNET_ntoh_double (double d);
1089 * array size 1089 * array size
1090 * @param element the element that will be appended to the array 1090 * @param element the element that will be appended to the array
1091 */ 1091 */
1092#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0) 1092#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); (arr)[size-1] = element; } while(0)
1093 1093
1094/** 1094/**
1095 * @ingroup memory 1095 * @ingroup memory
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 0bffef212..8a591fa09 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -206,14 +206,15 @@ struct GNUNET_CRYPTO_EcdsaSignature
206 206
207 207
208/** 208/**
209 * Public ECC key (always for Curve25519) encoded in a format suitable 209 * Public ECC key (always for curve Ed25519) encoded in a format
210 * for network transmission and EdDSA signatures. 210 * suitable for network transmission and EdDSA signatures.
211 */ 211 */
212struct GNUNET_CRYPTO_EddsaPublicKey 212struct GNUNET_CRYPTO_EddsaPublicKey
213{ 213{
214 /** 214 /**
215 * Q consists of an x- and a y-value, each mod p (256 bits), given 215 * Point Q consists of a y-value mod p (256 bits); the x-value is
216 * here in affine coordinates and Ed25519 standard compact format. 216 * always positive. The point is stored in Ed25519 standard
217 * compact format.
217 */ 218 */
218 unsigned char q_y[256 / 8]; 219 unsigned char q_y[256 / 8];
219 220
@@ -725,6 +726,23 @@ GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc);
725 726
726 727
727/** 728/**
729 * Calculate HMAC of a message (RFC 2104)
730 * TODO: Shouldn' this be the standard hmac function and
731 * the above be renamed?
732 *
733 * @param key secret key
734 * @param key_len secret key length
735 * @param plaintext input plaintext
736 * @param plaintext_len length of @a plaintext
737 * @param hmac where to store the hmac
738 */
739void
740GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
741 const void *plaintext, size_t plaintext_len,
742 struct GNUNET_HashCode *hmac);
743
744
745/**
728 * @ingroup hash 746 * @ingroup hash
729 * Calculate HMAC of a message (RFC 2104) 747 * Calculate HMAC of a message (RFC 2104)
730 * 748 *
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index ba1392510..0fc6ac19c 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -82,6 +82,7 @@
82#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY 61 82#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY 61
83#define GNUNET_DNSPARSER_TYPE_TKEY 249 83#define GNUNET_DNSPARSER_TYPE_TKEY 249
84#define GNUNET_DNSPARSER_TYPE_TSIG 250 84#define GNUNET_DNSPARSER_TYPE_TSIG 250
85#define GNUNET_DNSPARSER_TYPE_ALL 255
85#define GNUNET_DNSPARSER_TYPE_URI 256 86#define GNUNET_DNSPARSER_TYPE_URI 256
86#define GNUNET_DNSPARSER_TYPE_TA 32768 87#define GNUNET_DNSPARSER_TYPE_TA 32768
87 88
@@ -840,6 +841,58 @@ GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
840 size_t udp_payload_length, 841 size_t udp_payload_length,
841 size_t *off); 842 size_t *off);
842 843
844/* ***************** low-level duplication API ******************** */
845
846/**
847 * Duplicate (deep-copy) the given DNS record
848 *
849 * @param r the record
850 * @return the newly allocated record
851 */
852struct GNUNET_DNSPARSER_Record *
853GNUNET_DNSPARSER_duplicate_record (const struct GNUNET_DNSPARSER_Record *r);
854
855
856/**
857 * Duplicate (deep-copy) the given DNS record
858 *
859 * @param r the record
860 * @return the newly allocated record
861 */
862struct GNUNET_DNSPARSER_SoaRecord *
863GNUNET_DNSPARSER_duplicate_soa_record (const struct GNUNET_DNSPARSER_SoaRecord *r);
864
865
866/**
867 * Duplicate (deep-copy) the given DNS record
868 *
869 * @param r the record
870 * @return the newly allocated record
871 */
872struct GNUNET_DNSPARSER_CertRecord *
873GNUNET_DNSPARSER_duplicate_cert_record (const struct GNUNET_DNSPARSER_CertRecord *r);
874
875
876/**
877 * Duplicate (deep-copy) the given DNS record
878 *
879 * @param r the record
880 * @return the newly allocated record
881 */
882struct GNUNET_DNSPARSER_MxRecord *
883GNUNET_DNSPARSER_duplicate_mx_record (const struct GNUNET_DNSPARSER_MxRecord *r);
884
885
886/**
887 * Duplicate (deep-copy) the given DNS record
888 *
889 * @param r the record
890 * @return the newly allocated record
891 */
892struct GNUNET_DNSPARSER_SrvRecord *
893GNUNET_DNSPARSER_duplicate_srv_record (const struct GNUNET_DNSPARSER_SrvRecord *r);
894
895
843/* ***************** low-level deallocation API ******************** */ 896/* ***************** low-level deallocation API ******************** */
844 897
845/** 898/**
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h
index 20846238b..693cc6cdb 100644
--- a/src/include/gnunet_gnsrecord_lib.h
+++ b/src/include/gnunet_gnsrecord_lib.h
@@ -132,6 +132,16 @@ extern "C"
132#define GNUNET_GNSRECORD_TYPE_ABE_MASTER 65551 132#define GNUNET_GNSRECORD_TYPE_ABE_MASTER 65551
133 133
134/** 134/**
135 * Record type for reclaim OIDC clients
136 */
137#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT 65552
138
139/**
140 * Record type for reclaim OIDC redirect URIs
141 */
142#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553
143
144/**
135 * Flags that can be set for a record. 145 * Flags that can be set for a record.
136 */ 146 */
137enum GNUNET_GNSRECORD_Flags 147enum GNUNET_GNSRECORD_Flags
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 36aa424b4..4400db7e1 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2656,35 +2656,35 @@ extern "C"
2656 * 2656 *
2657 * IDENTITY PROVIDER MESSAGE TYPES 2657 * IDENTITY PROVIDER MESSAGE TYPES
2658 */ 2658 */
2659#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE 961 2659#define GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE 961
2660 2660
2661#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE 962 2661#define GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE_RESPONSE 962
2662 2662
2663#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_START 963 2663#define GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START 963
2664 2664
2665#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_STOP 964 2665#define GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP 964
2666 2666
2667#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_NEXT 965 2667#define GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT 965
2668 2668
2669#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT 966 2669#define GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT 966
2670 2670
2671#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET 967 2671#define GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET 967
2672 2672
2673#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT 968 2673#define GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT 968
2674 2674
2675#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET 969 2675#define GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET 969
2676 2676
2677#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT 970 2677#define GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT 970
2678 2678
2679#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET 971 2679#define GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET 971
2680 2680
2681#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT 972 2681#define GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT 972
2682 2682
2683#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START 973 2683#define GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START 973
2684 2684
2685#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP 974 2685#define GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP 974
2686 2686
2687#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT 975 2687#define GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT 975
2688 2688
2689/************************************************** 2689/**************************************************
2690 * 2690 *
diff --git a/src/include/gnunet_identity_attribute_lib.h b/src/include/gnunet_reclaim_attribute_lib.h
index eb01f7ac2..df5356d76 100644
--- a/src/include/gnunet_identity_attribute_lib.h
+++ b/src/include/gnunet_reclaim_attribute_lib.h
@@ -25,8 +25,8 @@
25 * @defgroup identity-provider Identity Provider service 25 * @defgroup identity-provider Identity Provider service
26 * @{ 26 * @{
27 */ 27 */
28#ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H 28#ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H
29#define GNUNET_IDENTITY_ATTRIBUTE_LIB_H 29#define GNUNET_RECLAIM_ATTRIBUTE_LIB_H
30 30
31#ifdef __cplusplus 31#ifdef __cplusplus
32extern "C" 32extern "C"
@@ -42,19 +42,19 @@ extern "C"
42/** 42/**
43 * No value attribute. 43 * No value attribute.
44 */ 44 */
45#define GNUNET_IDENTITY_ATTRIBUTE_TYPE_NONE 0 45#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE 0
46 46
47/** 47/**
48 * String attribute. 48 * String attribute.
49 */ 49 */
50#define GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING 1 50#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING 1
51 51
52 52
53 53
54/** 54/**
55 * An attribute. 55 * An attribute.
56 */ 56 */
57struct GNUNET_IDENTITY_ATTRIBUTE_Claim 57struct GNUNET_RECLAIM_ATTRIBUTE_Claim
58{ 58{
59 /** 59 /**
60 * The name of the attribute. Note "name" must never be individually 60 * The name of the attribute. Note "name" must never be individually
@@ -86,35 +86,35 @@ struct GNUNET_IDENTITY_ATTRIBUTE_Claim
86 86
87}; 87};
88 88
89struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList 89struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList
90{ 90{
91 /** 91 /**
92 * List head 92 * List head
93 */ 93 */
94 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_head; 94 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_head;
95 95
96 /** 96 /**
97 * List tail 97 * List tail
98 */ 98 */
99 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *list_tail; 99 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *list_tail;
100}; 100};
101 101
102struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry 102struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry
103{ 103{
104 /** 104 /**
105 * DLL 105 * DLL
106 */ 106 */
107 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *prev; 107 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *prev;
108 108
109 /** 109 /**
110 * DLL 110 * DLL
111 */ 111 */
112 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *next; 112 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *next;
113 113
114 /** 114 /**
115 * The attribute claim 115 * The attribute claim
116 */ 116 */
117 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim; 117 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
118}; 118};
119 119
120/** 120/**
@@ -126,8 +126,8 @@ struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry
126 * @param data_size the attribute value size 126 * @param data_size the attribute value size
127 * @return the new attribute 127 * @return the new attribute
128 */ 128 */
129struct GNUNET_IDENTITY_ATTRIBUTE_Claim * 129struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
130GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, 130GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
131 uint32_t type, 131 uint32_t type,
132 const void* data, 132 const void* data,
133 size_t data_size); 133 size_t data_size);
@@ -141,13 +141,13 @@ GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name,
141 * @return the required buffer size 141 * @return the required buffer size
142 */ 142 */
143size_t 143size_t
144GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); 144GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
145 145
146void 146void
147GNUNET_IDENTITY_ATTRIBUTE_list_destroy (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); 147GNUNET_RECLAIM_ATTRIBUTE_list_destroy (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
148 148
149void 149void
150GNUNET_IDENTITY_ATTRIBUTE_list_add (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 150GNUNET_RECLAIM_ATTRIBUTE_list_add (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
151 const char* attr_name, 151 const char* attr_name,
152 uint32_t type, 152 uint32_t type,
153 const void* data, 153 const void* data,
@@ -162,7 +162,7 @@ GNUNET_IDENTITY_ATTRIBUTE_list_add (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *
162 * @return length of serialized data 162 * @return length of serialized data
163 */ 163 */
164size_t 164size_t
165GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 165GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
166 char *result); 166 char *result);
167 167
168/** 168/**
@@ -173,8 +173,8 @@ GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE
173 * 173 *
174 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller 174 * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
175 */ 175 */
176struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList * 176struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
177GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (const char* data, 177GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data,
178 size_t data_size); 178 size_t data_size);
179 179
180 180
@@ -186,7 +186,7 @@ GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (const char* data,
186 * @return the required buffer size 186 * @return the required buffer size
187 */ 187 */
188size_t 188size_t
189GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr); 189GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr);
190 190
191 191
192 192
@@ -199,7 +199,7 @@ GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRI
199 * @return length of serialized data 199 * @return length of serialized data
200 */ 200 */
201size_t 201size_t
202GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, 202GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
203 char *result); 203 char *result);
204 204
205/** 205/**
@@ -210,12 +210,12 @@ GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Clai
210 * 210 *
211 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller 211 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
212 */ 212 */
213struct GNUNET_IDENTITY_ATTRIBUTE_Claim * 213struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
214GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data, 214GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data,
215 size_t data_size); 215 size_t data_size);
216 216
217struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList* 217struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList*
218GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); 218GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
219 219
220/** 220/**
221 * Convert a type name to the corresponding number 221 * Convert a type name to the corresponding number
@@ -224,7 +224,7 @@ GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim
224 * @return corresponding number, UINT32_MAX on error 224 * @return corresponding number, UINT32_MAX on error
225 */ 225 */
226uint32_t 226uint32_t
227GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename); 227GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename);
228 228
229/** 229/**
230 * Convert human-readable version of a 'claim' of an attribute to the binary 230 * Convert human-readable version of a 'claim' of an attribute to the binary
@@ -237,7 +237,7 @@ GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename);
237 * @return #GNUNET_OK on success 237 * @return #GNUNET_OK on success
238 */ 238 */
239int 239int
240GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type, 240GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
241 const char *s, 241 const char *s,
242 void **data, 242 void **data,
243 size_t *data_size); 243 size_t *data_size);
@@ -251,7 +251,7 @@ GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type,
251 * @return NULL on error, otherwise human-readable representation of the claim 251 * @return NULL on error, otherwise human-readable representation of the claim
252 */ 252 */
253char * 253char *
254GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type, 254GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
255 const void* data, 255 const void* data,
256 size_t data_size); 256 size_t data_size);
257 257
@@ -262,7 +262,7 @@ GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type,
262 * @return corresponding typestring, NULL on error 262 * @return corresponding typestring, NULL on error
263 */ 263 */
264const char* 264const char*
265GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type); 265GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type);
266 266
267 267
268#if 0 /* keep Emacsens' auto-indent happy */ 268#if 0 /* keep Emacsens' auto-indent happy */
@@ -273,9 +273,9 @@ GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type);
273#endif 273#endif
274 274
275 275
276/* ifndef GNUNET_IDENTITY_ATTRIBUTE_LIB_H */ 276/* ifndef GNUNET_RECLAIM_ATTRIBUTE_LIB_H */
277#endif 277#endif
278 278
279/** @} */ /* end of group identity */ 279/** @} */ /* end of group identity */
280 280
281/* end of gnunet_identity_attribute_lib.h */ 281/* end of gnunet_reclaim_attribute_lib.h */
diff --git a/src/include/gnunet_identity_attribute_plugin.h b/src/include/gnunet_reclaim_attribute_plugin.h
index 7c399c616..cf0bb141a 100644
--- a/src/include/gnunet_identity_attribute_plugin.h
+++ b/src/include/gnunet_reclaim_attribute_plugin.h
@@ -26,11 +26,11 @@
26 * Plugin API for the idp database backend 26 * Plugin API for the idp database backend
27 * @{ 27 * @{
28 */ 28 */
29#ifndef GNUNET_IDENTITY_ATTRIBUTE_PLUGIN_H 29#ifndef GNUNET_RECLAIM_ATTRIBUTE_PLUGIN_H
30#define GNUNET_IDENTITY_ATTRIBUTE_PLUGIN_H 30#define GNUNET_RECLAIM_ATTRIBUTE_PLUGIN_H
31 31
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33#include "gnunet_identity_attribute_lib.h" 33#include "gnunet_reclaim_attribute_lib.h"
34 34
35#ifdef __cplusplus 35#ifdef __cplusplus
36extern "C" 36extern "C"
@@ -51,7 +51,7 @@ extern "C"
51 * @param data_size number of bytes in @a data 51 * @param data_size number of bytes in @a data
52 * @return NULL on error, otherwise human-readable representation of the value 52 * @return NULL on error, otherwise human-readable representation of the value
53 */ 53 */
54typedef char * (*GNUNET_IDENTITY_ATTRIBUTE_ValueToStringFunction) (void *cls, 54typedef char * (*GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction) (void *cls,
55 uint32_t type, 55 uint32_t type,
56 const void *data, 56 const void *data,
57 size_t data_size); 57 size_t data_size);
@@ -69,7 +69,7 @@ typedef char * (*GNUNET_IDENTITY_ATTRIBUTE_ValueToStringFunction) (void *cls,
69 * @param data_size set to number of bytes in @a data 69 * @param data_size set to number of bytes in @a data
70 * @return #GNUNET_OK on success 70 * @return #GNUNET_OK on success
71 */ 71 */
72typedef int (*GNUNET_IDENTITY_ATTRIBUTE_StringToValueFunction) (void *cls, 72typedef int (*GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction) (void *cls,
73 uint32_t type, 73 uint32_t type,
74 const char *s, 74 const char *s,
75 void **data, 75 void **data,
@@ -84,7 +84,7 @@ typedef int (*GNUNET_IDENTITY_ATTRIBUTE_StringToValueFunction) (void *cls,
84 * @param typename name to convert 84 * @param typename name to convert
85 * @return corresponding number, UINT32_MAX on error 85 * @return corresponding number, UINT32_MAX on error
86 */ 86 */
87typedef uint32_t (*GNUNET_IDENTITY_ATTRIBUTE_TypenameToNumberFunction) (void *cls, 87typedef uint32_t (*GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction) (void *cls,
88 const char *typename); 88 const char *typename);
89 89
90 90
@@ -96,7 +96,7 @@ typedef uint32_t (*GNUNET_IDENTITY_ATTRIBUTE_TypenameToNumberFunction) (void *cl
96 * @param type number of a type to convert 96 * @param type number of a type to convert
97 * @return corresponding typestring, NULL on error 97 * @return corresponding typestring, NULL on error
98 */ 98 */
99typedef const char * (*GNUNET_IDENTITY_ATTRIBUTE_NumberToTypenameFunction) (void *cls, 99typedef const char * (*GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction) (void *cls,
100 uint32_t type); 100 uint32_t type);
101 101
102 102
@@ -104,7 +104,7 @@ typedef const char * (*GNUNET_IDENTITY_ATTRIBUTE_NumberToTypenameFunction) (void
104 * Each plugin is required to return a pointer to a struct of this 104 * Each plugin is required to return a pointer to a struct of this
105 * type as the return value from its entry point. 105 * type as the return value from its entry point.
106 */ 106 */
107struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions 107struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions
108{ 108{
109 109
110 /** 110 /**
@@ -115,22 +115,22 @@ struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions
115 /** 115 /**
116 * Conversion to string. 116 * Conversion to string.
117 */ 117 */
118 GNUNET_IDENTITY_ATTRIBUTE_ValueToStringFunction value_to_string; 118 GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction value_to_string;
119 119
120 /** 120 /**
121 * Conversion to binary. 121 * Conversion to binary.
122 */ 122 */
123 GNUNET_IDENTITY_ATTRIBUTE_StringToValueFunction string_to_value; 123 GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction string_to_value;
124 124
125 /** 125 /**
126 * Typename to number. 126 * Typename to number.
127 */ 127 */
128 GNUNET_IDENTITY_ATTRIBUTE_TypenameToNumberFunction typename_to_number; 128 GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction typename_to_number;
129 129
130 /** 130 /**
131 * Number to typename. 131 * Number to typename.
132 */ 132 */
133 GNUNET_IDENTITY_ATTRIBUTE_NumberToTypenameFunction number_to_typename; 133 GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction number_to_typename;
134 134
135}; 135};
136 136
diff --git a/src/include/gnunet_identity_provider_plugin.h b/src/include/gnunet_reclaim_plugin.h
index 2330066dd..c400af64c 100644
--- a/src/include/gnunet_identity_provider_plugin.h
+++ b/src/include/gnunet_reclaim_plugin.h
@@ -22,15 +22,15 @@
22 * @file 22 * @file
23 * Plugin API for the idp database backend 23 * Plugin API for the idp database backend
24 * 24 *
25 * @defgroup identity-provider-plugin IdP service plugin API 25 * @defgroup reclaim-plugin IdP service plugin API
26 * Plugin API for the idp database backend 26 * Plugin API for the idp database backend
27 * @{ 27 * @{
28 */ 28 */
29#ifndef GNUNET_IDENTITY_PROVIDER_PLUGIN_H 29#ifndef GNUNET_RECLAIM_PLUGIN_H
30#define GNUNET_IDENTITY_PROVIDER_PLUGIN_H 30#define GNUNET_RECLAIM_PLUGIN_H
31 31
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33#include "gnunet_identity_provider_service.h" 33#include "gnunet_reclaim_service.h"
34 34
35#ifdef __cplusplus 35#ifdef __cplusplus
36extern "C" 36extern "C"
@@ -47,15 +47,15 @@ extern "C"
47 * @param cls closure 47 * @param cls closure
48 * @param ticket the ticket 48 * @param ticket the ticket
49 */ 49 */
50typedef void (*GNUNET_IDENTITY_PROVIDER_TicketIterator) (void *cls, 50typedef void (*GNUNET_RECLAIM_TicketIterator) (void *cls,
51 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 51 const struct GNUNET_RECLAIM_Ticket *ticket,
52 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); 52 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
53 53
54 54
55/** 55/**
56 * @brief struct returned by the initialization function of the plugin 56 * @brief struct returned by the initialization function of the plugin
57 */ 57 */
58struct GNUNET_IDENTITY_PROVIDER_PluginFunctions 58struct GNUNET_RECLAIM_PluginFunctions
59{ 59{
60 60
61 /** 61 /**
@@ -71,8 +71,8 @@ struct GNUNET_IDENTITY_PROVIDER_PluginFunctions
71 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 71 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
72 */ 72 */
73 int (*store_ticket) (void *cls, 73 int (*store_ticket) (void *cls,
74 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 74 const struct GNUNET_RECLAIM_Ticket *ticket,
75 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); 75 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
76 76
77 /** 77 /**
78 * Delete a ticket from the database. 78 * Delete a ticket from the database.
@@ -82,7 +82,7 @@ struct GNUNET_IDENTITY_PROVIDER_PluginFunctions
82 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 82 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
83 */ 83 */
84 int (*delete_ticket) (void *cls, 84 int (*delete_ticket) (void *cls,
85 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket); 85 const struct GNUNET_RECLAIM_Ticket *ticket);
86 86
87 87
88 88
@@ -101,11 +101,11 @@ struct GNUNET_IDENTITY_PROVIDER_PluginFunctions
101 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 101 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
102 int audience, 102 int audience,
103 uint64_t offset, 103 uint64_t offset,
104 GNUNET_IDENTITY_PROVIDER_TicketIterator iter, void *iter_cls); 104 GNUNET_RECLAIM_TicketIterator iter, void *iter_cls);
105 105
106 int (*get_ticket_attributes) (void* cls, 106 int (*get_ticket_attributes) (void* cls,
107 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 107 const struct GNUNET_RECLAIM_Ticket *ticket,
108 GNUNET_IDENTITY_PROVIDER_TicketIterator iter, 108 GNUNET_RECLAIM_TicketIterator iter,
109 void *iter_cls); 109 void *iter_cls);
110}; 110};
111 111
diff --git a/src/include/gnunet_identity_provider_service.h b/src/include/gnunet_reclaim_service.h
index 0c72556e8..7e668cd62 100644
--- a/src/include/gnunet_identity_provider_service.h
+++ b/src/include/gnunet_reclaim_service.h
@@ -22,11 +22,11 @@
22 * @file 22 * @file
23 * Identity provider service; implements identity provider for GNUnet 23 * Identity provider service; implements identity provider for GNUnet
24 * 24 *
25 * @defgroup identity-provider Identity Provider service 25 * @defgroup reclaim Identity Provider service
26 * @{ 26 * @{
27 */ 27 */
28#ifndef GNUNET_IDENTITY_PROVIDER_SERVICE_H 28#ifndef GNUNET_RECLAIM_SERVICE_H
29#define GNUNET_IDENTITY_PROVIDER_SERVICE_H 29#define GNUNET_RECLAIM_SERVICE_H
30 30
31#ifdef __cplusplus 31#ifdef __cplusplus
32extern "C" 32extern "C"
@@ -37,27 +37,27 @@ extern "C"
37#endif 37#endif
38 38
39#include "gnunet_util_lib.h" 39#include "gnunet_util_lib.h"
40#include "gnunet_identity_attribute_lib.h" 40#include "gnunet_reclaim_attribute_lib.h"
41 41
42/** 42/**
43 * Version number of GNUnet Identity Provider API. 43 * Version number of GNUnet Identity Provider API.
44 */ 44 */
45#define GNUNET_IDENTITY_PROVIDER_VERSION 0x00000000 45#define GNUNET_RECLAIM_VERSION 0x00000000
46 46
47/** 47/**
48 * Handle to access the identity service. 48 * Handle to access the identity service.
49 */ 49 */
50struct GNUNET_IDENTITY_PROVIDER_Handle; 50struct GNUNET_RECLAIM_Handle;
51 51
52/** 52/**
53 * Handle for a token. 53 * Handle for a token.
54 */ 54 */
55struct GNUNET_IDENTITY_PROVIDER_Token; 55struct GNUNET_RECLAIM_Token;
56 56
57/** 57/**
58 * The ticket 58 * The ticket
59 */ 59 */
60struct GNUNET_IDENTITY_PROVIDER_Ticket 60struct GNUNET_RECLAIM_Ticket
61{ 61{
62 /** 62 /**
63 * The ticket issuer 63 * The ticket issuer
@@ -78,7 +78,7 @@ struct GNUNET_IDENTITY_PROVIDER_Ticket
78/** 78/**
79 * Handle for an operation with the identity provider service. 79 * Handle for an operation with the identity provider service.
80 */ 80 */
81struct GNUNET_IDENTITY_PROVIDER_Operation; 81struct GNUNET_RECLAIM_Operation;
82 82
83 83
84/** 84/**
@@ -87,8 +87,8 @@ struct GNUNET_IDENTITY_PROVIDER_Operation;
87 * @param cfg Configuration to contact the identity provider service. 87 * @param cfg Configuration to contact the identity provider service.
88 * @return handle to communicate with identity provider service 88 * @return handle to communicate with identity provider service
89 */ 89 */
90struct GNUNET_IDENTITY_PROVIDER_Handle * 90struct GNUNET_RECLAIM_Handle *
91GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); 91GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
92 92
93/** 93/**
94 * Continuation called to notify client about result of the 94 * Continuation called to notify client about result of the
@@ -101,7 +101,7 @@ GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
101 * @param emsg NULL on success, otherwise an error message 101 * @param emsg NULL on success, otherwise an error message
102 */ 102 */
103typedef void 103typedef void
104(*GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus) (void *cls, 104(*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls,
105 int32_t success, 105 int32_t success,
106 const char *emsg); 106 const char *emsg);
107 107
@@ -118,12 +118,12 @@ typedef void
118 * @param cont_cls closure for @a cont 118 * @param cont_cls closure for @a cont
119 * @return handle to abort the request 119 * @return handle to abort the request
120 */ 120 */
121struct GNUNET_IDENTITY_PROVIDER_Operation * 121struct GNUNET_RECLAIM_Operation *
122GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 122GNUNET_RECLAIM_attribute_store (struct GNUNET_RECLAIM_Handle *h,
123 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 123 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
124 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, 124 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
125 const struct GNUNET_TIME_Relative *exp_interval, 125 const struct GNUNET_TIME_Relative *exp_interval,
126 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont, 126 GNUNET_RECLAIM_ContinuationWithStatus cont,
127 void *cont_cls); 127 void *cont_cls);
128 128
129 129
@@ -135,19 +135,19 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
135 * @param attr the attribute 135 * @param attr the attribute
136 */ 136 */
137typedef void 137typedef void
138(*GNUNET_IDENTITY_PROVIDER_AttributeResult) (void *cls, 138(*GNUNET_RECLAIM_AttributeResult) (void *cls,
139 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 139 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
140 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr); 140 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr);
141 141
142 142
143 143
144/** 144/**
145 * List all attributes for a local identity. 145 * List all attributes for a local identity.
146 * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle` 146 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
147 * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and 147 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
148 * #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once 148 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
149 * immediately, and then again after 149 * immediately, and then again after
150 * #GNUNET_IDENTITY_PROVIDER_get_attributes_next() is invoked. 150 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
151 * 151 *
152 * On error (disconnect), @a error_cb will be invoked. 152 * On error (disconnect), @a error_cb will be invoked.
153 * On normal completion, @a finish_cb proc will be 153 * On normal completion, @a finish_cb proc will be
@@ -166,36 +166,36 @@ typedef void
166 * @param finish_cb_cls closure for @a finish_cb 166 * @param finish_cb_cls closure for @a finish_cb
167 * @return an iterator handle to use for iteration 167 * @return an iterator handle to use for iteration
168 */ 168 */
169struct GNUNET_IDENTITY_PROVIDER_AttributeIterator * 169struct GNUNET_RECLAIM_AttributeIterator *
170GNUNET_IDENTITY_PROVIDER_get_attributes_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 170GNUNET_RECLAIM_get_attributes_start (struct GNUNET_RECLAIM_Handle *h,
171 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 171 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
172 GNUNET_SCHEDULER_TaskCallback error_cb, 172 GNUNET_SCHEDULER_TaskCallback error_cb,
173 void *error_cb_cls, 173 void *error_cb_cls,
174 GNUNET_IDENTITY_PROVIDER_AttributeResult proc, 174 GNUNET_RECLAIM_AttributeResult proc,
175 void *proc_cls, 175 void *proc_cls,
176 GNUNET_SCHEDULER_TaskCallback finish_cb, 176 GNUNET_SCHEDULER_TaskCallback finish_cb,
177 void *finish_cb_cls); 177 void *finish_cb_cls);
178 178
179 179
180/** 180/**
181 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_get_attributes_start 181 * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
182 * for the next record. 182 * for the next record.
183 * 183 *
184 * @param it the iterator 184 * @param it the iterator
185 */ 185 */
186void 186void
187GNUNET_IDENTITY_PROVIDER_get_attributes_next (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it); 187GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it);
188 188
189 189
190/** 190/**
191 * Stops iteration and releases the idp handle for further calls. Must 191 * Stops iteration and releases the idp handle for further calls. Must
192 * be called on any iteration that has not yet completed prior to calling 192 * be called on any iteration that has not yet completed prior to calling
193 * #GNUNET_IDENTITY_PROVIDER_disconnect. 193 * #GNUNET_RECLAIM_disconnect.
194 * 194 *
195 * @param it the iterator 195 * @param it the iterator
196 */ 196 */
197void 197void
198GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it); 198GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it);
199 199
200 200
201/** 201/**
@@ -207,12 +207,12 @@ GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_At
207 * @param ticket the ticket 207 * @param ticket the ticket
208 */ 208 */
209typedef void 209typedef void
210(*GNUNET_IDENTITY_PROVIDER_TicketCallback)(void *cls, 210(*GNUNET_RECLAIM_TicketCallback)(void *cls,
211 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket); 211 const struct GNUNET_RECLAIM_Ticket *ticket);
212 212
213/** 213/**
214 * Issues a ticket to another identity. The identity may use 214 * Issues a ticket to another identity. The identity may use
215 * GNUNET_IDENTITY_PROVIDER_ticket_consume to consume the ticket 215 * GNUNET_RECLAIM_ticket_consume to consume the ticket
216 * and retrieve the attributes specified in the AttributeList. 216 * and retrieve the attributes specified in the AttributeList.
217 * 217 *
218 * @param h the identity provider to use 218 * @param h the identity provider to use
@@ -223,12 +223,12 @@ typedef void
223 * @param cb_cls the callback closure 223 * @param cb_cls the callback closure
224 * @return handle to abort the operation 224 * @return handle to abort the operation
225 */ 225 */
226struct GNUNET_IDENTITY_PROVIDER_Operation * 226struct GNUNET_RECLAIM_Operation *
227GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 227GNUNET_RECLAIM_ticket_issue (struct GNUNET_RECLAIM_Handle *h,
228 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, 228 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
229 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, 229 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
230 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 230 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
231 GNUNET_IDENTITY_PROVIDER_TicketCallback cb, 231 GNUNET_RECLAIM_TicketCallback cb,
232 void *cb_cls); 232 void *cb_cls);
233 233
234/** 234/**
@@ -242,11 +242,11 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h
242 * @param cb_cls the callback closure 242 * @param cb_cls the callback closure
243 * @return handle to abort the operation 243 * @return handle to abort the operation
244 */ 244 */
245struct GNUNET_IDENTITY_PROVIDER_Operation * 245struct GNUNET_RECLAIM_Operation *
246GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 246GNUNET_RECLAIM_ticket_revoke (struct GNUNET_RECLAIM_Handle *h,
247 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 247 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
248 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 248 const struct GNUNET_RECLAIM_Ticket *ticket,
249 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb, 249 GNUNET_RECLAIM_ContinuationWithStatus cb,
250 void *cb_cls); 250 void *cb_cls);
251 251
252 252
@@ -262,11 +262,11 @@ GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *
262 * @param cb_cls the callback closure 262 * @param cb_cls the callback closure
263 * @return handle to abort the operation 263 * @return handle to abort the operation
264 */ 264 */
265struct GNUNET_IDENTITY_PROVIDER_Operation * 265struct GNUNET_RECLAIM_Operation *
266GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 266GNUNET_RECLAIM_ticket_consume (struct GNUNET_RECLAIM_Handle *h,
267 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 267 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
268 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 268 const struct GNUNET_RECLAIM_Ticket *ticket,
269 GNUNET_IDENTITY_PROVIDER_AttributeResult cb, 269 GNUNET_RECLAIM_AttributeResult cb,
270 void *cb_cls); 270 void *cb_cls);
271 271
272/** 272/**
@@ -286,12 +286,12 @@ GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle
286 * @param finish_cb_cls closure for @a finish_cb 286 * @param finish_cb_cls closure for @a finish_cb
287 * @return an iterator handle to use for iteration 287 * @return an iterator handle to use for iteration
288 */ 288 */
289struct GNUNET_IDENTITY_PROVIDER_TicketIterator * 289struct GNUNET_RECLAIM_TicketIterator *
290GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 290GNUNET_RECLAIM_ticket_iteration_start (struct GNUNET_RECLAIM_Handle *h,
291 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 291 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
292 GNUNET_SCHEDULER_TaskCallback error_cb, 292 GNUNET_SCHEDULER_TaskCallback error_cb,
293 void *error_cb_cls, 293 void *error_cb_cls,
294 GNUNET_IDENTITY_PROVIDER_TicketCallback proc, 294 GNUNET_RECLAIM_TicketCallback proc,
295 void *proc_cls, 295 void *proc_cls,
296 GNUNET_SCHEDULER_TaskCallback finish_cb, 296 GNUNET_SCHEDULER_TaskCallback finish_cb,
297 void *finish_cb_cls); 297 void *finish_cb_cls);
@@ -313,34 +313,34 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER
313 * @param finish_cb_cls closure for @a finish_cb 313 * @param finish_cb_cls closure for @a finish_cb
314 * @return an iterator handle to use for iteration 314 * @return an iterator handle to use for iteration
315 */ 315 */
316struct GNUNET_IDENTITY_PROVIDER_TicketIterator * 316struct GNUNET_RECLAIM_TicketIterator *
317GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 317GNUNET_RECLAIM_ticket_iteration_start_rp (struct GNUNET_RECLAIM_Handle *h,
318 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 318 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
319 GNUNET_SCHEDULER_TaskCallback error_cb, 319 GNUNET_SCHEDULER_TaskCallback error_cb,
320 void *error_cb_cls, 320 void *error_cb_cls,
321 GNUNET_IDENTITY_PROVIDER_TicketCallback proc, 321 GNUNET_RECLAIM_TicketCallback proc,
322 void *proc_cls, 322 void *proc_cls,
323 GNUNET_SCHEDULER_TaskCallback finish_cb, 323 GNUNET_SCHEDULER_TaskCallback finish_cb,
324 void *finish_cb_cls); 324 void *finish_cb_cls);
325 325
326/** 326/**
327 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_ticket_iteration_start 327 * Calls the record processor specified in #GNUNET_RECLAIM_ticket_iteration_start
328 * for the next record. 328 * for the next record.
329 * 329 *
330 * @param it the iterator 330 * @param it the iterator
331 */ 331 */
332void 332void
333GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it); 333GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it);
334 334
335/** 335/**
336 * Stops iteration and releases the idp handle for further calls. Must 336 * Stops iteration and releases the idp handle for further calls. Must
337 * be called on any iteration that has not yet completed prior to calling 337 * be called on any iteration that has not yet completed prior to calling
338 * #GNUNET_IDENTITY_PROVIDER_disconnect. 338 * #GNUNET_RECLAIM_disconnect.
339 * 339 *
340 * @param it the iterator 340 * @param it the iterator
341 */ 341 */
342void 342void
343GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it); 343GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it);
344 344
345/** 345/**
346 * Disconnect from identity provider service. 346 * Disconnect from identity provider service.
@@ -348,7 +348,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_
348 * @param h identity provider service to disconnect 348 * @param h identity provider service to disconnect
349 */ 349 */
350void 350void
351GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h); 351GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h);
352 352
353 353
354/** 354/**
@@ -360,7 +360,7 @@ GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h);
360 * @param op operation to cancel 360 * @param op operation to cancel
361 */ 361 */
362void 362void
363GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op); 363GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op);
364 364
365#if 0 /* keep Emacsens' auto-indent happy */ 365#if 0 /* keep Emacsens' auto-indent happy */
366{ 366{
@@ -370,9 +370,9 @@ GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op);
370#endif 370#endif
371 371
372 372
373/* ifndef GNUNET_IDENTITY_PROVIDER_SERVICE_H */ 373/* ifndef GNUNET_RECLAIM_SERVICE_H */
374#endif 374#endif
375 375
376/** @} */ /* end of group identity */ 376/** @} */ /* end of group identity */
377 377
378/* end of gnunet_identity_provider_service.h */ 378/* end of gnunet_reclaim_service.h */
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index d7accaf2c..829f8be7e 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -151,12 +151,12 @@ extern "C"
151/** 151/**
152 * Signature for the first round of distributed key generation. 152 * Signature for the first round of distributed key generation.
153 */ 153 */
154#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 22 154#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1 21
155 155
156/** 156/**
157 * Signature for the second round of distributed key generation. 157 * Signature for the second round of distributed key generation.
158 */ 158 */
159#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG2 23 159#define GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG2 22
160 160
161/** 161/**
162 * Signature for cooperatice decryption. 162 * Signature for cooperatice decryption.
@@ -181,7 +181,7 @@ extern "C"
181/** 181/**
182 * Signature for a GNUid Ticket 182 * Signature for a GNUid Ticket
183 */ 183 */
184#define GNUNET_SIGNATURE_PURPOSE_GNUID_TICKET 27 184#define GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN 27
185 185
186/** 186/**
187 * Signature for a GNUnet credential 187 * Signature for a GNUnet credential
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 1fdab93b2..c1d76ef71 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -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*/
@@ -339,7 +339,9 @@ GNUNET_STRINGS_string_to_data (const char *enc,
339 * @return the size of the output 339 * @return the size of the output
340 */ 340 */
341size_t 341size_t
342GNUNET_STRINGS_base64_encode (const char *data, size_t len, char **output); 342GNUNET_STRINGS_base64_encode (const void *in,
343 size_t len,
344 char **output);
343 345
344 346
345/** 347/**
@@ -354,7 +356,7 @@ GNUNET_STRINGS_base64_encode (const char *data, size_t len, char **output);
354size_t 356size_t
355GNUNET_STRINGS_base64_decode (const char *data, 357GNUNET_STRINGS_base64_decode (const char *data,
356 size_t len, 358 size_t len,
357 char **output); 359 void **output);
358 360
359 361
360/** 362/**
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index 20d29b906..f8441cc2b 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -1449,17 +1449,15 @@ check_client_member_join (void *cls,
1449 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1]; 1449 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1];
1450 uint32_t relay_count = ntohl (msg->relay_count); 1450 uint32_t relay_count = ntohl (msg->relay_count);
1451 1451
1452 if (0 == relay_count) 1452 if (0 != relay_count)
1453 { 1453 {
1454 GNUNET_break (0); 1454 if (UINT32_MAX / relay_count < sizeof (*relays)){
1455 return GNUNET_SYSERR; 1455 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1456 } 1456 "relay_count (%lu) * sizeof (*relays) (%lu) exceeds UINT32_MAX!\n",
1457 if (UINT32_MAX / relay_count < sizeof (*relays)){ 1457 (unsigned long)relay_count,
1458 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1458 sizeof (*relays));
1459 "relay_count (%lu) * sizeof (*relays) (%lu) exceeds UINT32_MAX!\n", 1459 return GNUNET_SYSERR;
1460 (unsigned long)relay_count, 1460 }
1461 sizeof (*relays));
1462 return GNUNET_SYSERR;
1463 } 1461 }
1464 uint32_t relay_size = relay_count * sizeof (*relays); 1462 uint32_t relay_size = relay_count * sizeof (*relays);
1465 struct GNUNET_MessageHeader *join_msg = NULL; 1463 struct GNUNET_MessageHeader *join_msg = NULL;
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index 3a7c6d961..7766ff875 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -160,6 +160,7 @@ notify (void *cls,
160 160
161 *data_size = sizeof (struct pingpong_msg); 161 *data_size = sizeof (struct pingpong_msg);
162 GNUNET_memcpy(data, pp_msg, *data_size); 162 GNUNET_memcpy(data, pp_msg, *data_size);
163 GNUNET_free (pp_msg);
163 164
164 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 165 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
165 "Peer #%u sents ping to origin\n", mc_peer->peer); 166 "Peer #%u sents ping to origin\n", mc_peer->peer);
@@ -328,6 +329,7 @@ origin_notify (void *cls,
328 pp_msg->msg = PONG; 329 pp_msg->msg = PONG;
329 *data_size = sizeof (struct pingpong_msg); 330 *data_size = sizeof (struct pingpong_msg);
330 GNUNET_memcpy(data, pp_msg, *data_size); 331 GNUNET_memcpy(data, pp_msg, *data_size);
332 GNUNET_free (pp_msg);
331 333
332 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n"); 334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n");
333 335
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c
index 6c89cdb05..ddc8b483a 100644
--- a/src/namestore/gnunet-zoneimport.c
+++ b/src/namestore/gnunet-zoneimport.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*/
@@ -456,6 +456,7 @@ build_dns_query (struct Request *req,
456 char *rawp; 456 char *rawp;
457 struct GNUNET_DNSPARSER_Packet p; 457 struct GNUNET_DNSPARSER_Packet p;
458 struct GNUNET_DNSPARSER_Query q; 458 struct GNUNET_DNSPARSER_Query q;
459 int ret;
459 460
460 q.name = (char *) req->hostname; 461 q.name = (char *) req->hostname;
461 q.type = GNUNET_DNSPARSER_TYPE_NS; 462 q.type = GNUNET_DNSPARSER_TYPE_NS;
@@ -467,12 +468,14 @@ build_dns_query (struct Request *req,
467 p.num_queries = 1; 468 p.num_queries = 1;
468 p.queries = &q; 469 p.queries = &q;
469 p.id = req->id; 470 p.id = req->id;
470 if (GNUNET_OK != 471 ret = GNUNET_DNSPARSER_pack (&p,
471 GNUNET_DNSPARSER_pack (&p, 472 UINT16_MAX,
472 UINT16_MAX, 473 &rawp,
473 &rawp, 474 raw_size);
474 raw_size)) 475 if (GNUNET_OK != ret)
475 { 476 {
477 if (GNUNET_NO == ret)
478 GNUNET_free (rawp);
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
477 "Failed to pack query for hostname `%s'\n", 480 "Failed to pack query for hostname `%s'\n",
478 req->hostname); 481 req->hostname);
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index 33c48b244..e16fe91b7 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -55,7 +55,7 @@ struct FlatFileEntry
55 /** 55 /**
56 * Entry zone 56 * Entry zone
57 */ 57 */
58 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key; 58 struct GNUNET_CRYPTO_EcdsaPrivateKey private_key;
59 59
60 /** 60 /**
61 * Record cound 61 * Record cound
@@ -93,7 +93,6 @@ static int
93database_setup (struct Plugin *plugin) 93database_setup (struct Plugin *plugin)
94{ 94{
95 char *afsdir; 95 char *afsdir;
96 char *key;
97 char *record_data; 96 char *record_data;
98 char *zone_private_key; 97 char *zone_private_key;
99 char *record_data_b64; 98 char *record_data_b64;
@@ -104,7 +103,6 @@ database_setup (struct Plugin *plugin)
104 char *record_count; 103 char *record_count;
105 size_t record_data_size; 104 size_t record_data_size;
106 uint64_t size; 105 uint64_t size;
107 size_t key_len;
108 struct GNUNET_HashCode hkey; 106 struct GNUNET_HashCode hkey;
109 struct GNUNET_DISK_FileHandle *fh; 107 struct GNUNET_DISK_FileHandle *fh;
110 struct FlatFileEntry *entry; 108 struct FlatFileEntry *entry;
@@ -232,7 +230,7 @@ database_setup (struct Plugin *plugin)
232 record_data_size 230 record_data_size
233 = GNUNET_STRINGS_base64_decode (record_data_b64, 231 = GNUNET_STRINGS_base64_decode (record_data_b64,
234 strlen (record_data_b64), 232 strlen (record_data_b64),
235 &record_data); 233 (void **) &record_data);
236 entry->record_data = 234 entry->record_data =
237 GNUNET_new_array (entry->record_count, 235 GNUNET_new_array (entry->record_count,
238 struct GNUNET_GNSRECORD_Data); 236 struct GNUNET_GNSRECORD_Data);
@@ -251,21 +249,34 @@ database_setup (struct Plugin *plugin)
251 break; 249 break;
252 } 250 }
253 GNUNET_free (record_data); 251 GNUNET_free (record_data);
254 GNUNET_STRINGS_base64_decode (zone_private_key, 252
255 strlen (zone_private_key), 253 {
256 (char**)&entry->private_key); 254 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key;
257 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); 255
258 key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 256 GNUNET_STRINGS_base64_decode (zone_private_key,
259 GNUNET_memcpy (key, 257 strlen (zone_private_key),
260 label, 258 (void**)&private_key);
261 strlen (label)); 259 entry->private_key = *private_key;
262 GNUNET_memcpy (key+strlen(label), 260 GNUNET_free (private_key);
263 entry->private_key, 261 }
264 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 262
265 GNUNET_CRYPTO_hash (key, 263 {
266 key_len, 264 char *key;
267 &hkey); 265 size_t key_len;
268 GNUNET_free (key); 266
267 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
268 key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
269 GNUNET_memcpy (key,
270 label,
271 strlen (label));
272 GNUNET_memcpy (key+strlen(label),
273 &entry->private_key,
274 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
275 GNUNET_CRYPTO_hash (key,
276 key_len,
277 &hkey);
278 GNUNET_free (key);
279 }
269 if (GNUNET_OK != 280 if (GNUNET_OK !=
270 GNUNET_CONTAINER_multihashmap_put (plugin->hm, 281 GNUNET_CONTAINER_multihashmap_put (plugin->hm,
271 &hkey, 282 &hkey,
@@ -302,7 +313,7 @@ store_and_free_entries (void *cls,
302 ssize_t data_size; 313 ssize_t data_size;
303 314
304 (void) key; 315 (void) key;
305 GNUNET_STRINGS_base64_encode ((char*)entry->private_key, 316 GNUNET_STRINGS_base64_encode (&entry->private_key,
306 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 317 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
307 &zone_private_key); 318 &zone_private_key);
308 data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, 319 data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count,
@@ -353,7 +364,6 @@ store_and_free_entries (void *cls,
353 strlen (line)); 364 strlen (line));
354 365
355 GNUNET_free (line); 366 GNUNET_free (line);
356 GNUNET_free (entry->private_key);
357 GNUNET_free (entry->label); 367 GNUNET_free (entry->label);
358 GNUNET_free (entry->record_data); 368 GNUNET_free (entry->record_data);
359 GNUNET_free (entry); 369 GNUNET_free (entry);
@@ -441,11 +451,10 @@ namestore_flat_store_records (void *cls,
441 return GNUNET_OK; 451 return GNUNET_OK;
442 } 452 }
443 entry = GNUNET_new (struct FlatFileEntry); 453 entry = GNUNET_new (struct FlatFileEntry);
444 entry->private_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
445 GNUNET_asprintf (&entry->label, 454 GNUNET_asprintf (&entry->label,
446 label, 455 label,
447 strlen (label)); 456 strlen (label));
448 GNUNET_memcpy (entry->private_key, 457 GNUNET_memcpy (&entry->private_key,
449 zone_key, 458 zone_key,
450 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 459 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
451 entry->rvalue = rvalue; 460 entry->rvalue = rvalue;
@@ -519,7 +528,7 @@ namestore_flat_lookup_records (void *cls,
519 if (NULL != iter) 528 if (NULL != iter)
520 iter (iter_cls, 529 iter (iter_cls,
521 0, 530 0,
522 entry->private_key, 531 &entry->private_key,
523 entry->label, 532 entry->label,
524 entry->record_count, 533 entry->record_count,
525 entry->record_data); 534 entry->record_data);
@@ -586,7 +595,7 @@ iterate_zones (void *cls,
586 if (0 == ic->limit) 595 if (0 == ic->limit)
587 return GNUNET_NO; 596 return GNUNET_NO;
588 if ( (NULL != ic->zone) && 597 if ( (NULL != ic->zone) &&
589 (0 != memcmp (entry->private_key, 598 (0 != memcmp (&entry->private_key,
590 ic->zone, 599 ic->zone,
591 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) 600 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
592 return GNUNET_YES; 601 return GNUNET_YES;
@@ -598,7 +607,7 @@ iterate_zones (void *cls,
598 } 607 }
599 ic->iter (ic->iter_cls, 608 ic->iter (ic->iter_cls,
600 ic->pos, 609 ic->pos,
601 entry->private_key, 610 &entry->private_key,
602 entry->label, 611 entry->label,
603 entry->record_count, 612 entry->record_count,
604 entry->record_data); 613 entry->record_data);
@@ -668,7 +677,7 @@ zone_to_name (void *cls,
668 struct FlatFileEntry *entry = value; 677 struct FlatFileEntry *entry = value;
669 678
670 (void) key; 679 (void) key;
671 if (0 != memcmp (entry->private_key, 680 if (0 != memcmp (&entry->private_key,
672 ztn->zone, 681 ztn->zone,
673 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) 682 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
674 return GNUNET_YES; 683 return GNUNET_YES;
@@ -683,7 +692,7 @@ zone_to_name (void *cls,
683 { 692 {
684 ztn->iter (ztn->iter_cls, 693 ztn->iter (ztn->iter_cls,
685 0, 694 0,
686 entry->private_key, 695 &entry->private_key,
687 entry->label, 696 entry->label,
688 entry->record_count, 697 entry->record_count,
689 entry->record_data); 698 entry->record_data);
diff --git a/src/psyc/Makefile.am b/src/psyc/Makefile.am
index 26db608f3..d5c797f52 100644
--- a/src/psyc/Makefile.am
+++ b/src/psyc/Makefile.am
@@ -48,8 +48,8 @@ gnunet_service_psyc_CFLAGS = $(AM_CFLAGS)
48 48
49 49
50if HAVE_TESTING 50if HAVE_TESTING
51check_PROGRAMS = \ 51#check_PROGRAMS = \
52 test_psyc2 52# test_psyc2
53# test_psyc 53# test_psyc
54endif 54endif
55 55
diff --git a/src/identity-attribute/Makefile.am b/src/reclaim-attribute/Makefile.am
index 2c73a443e..7db2925b1 100644
--- a/src/identity-attribute/Makefile.am
+++ b/src/reclaim-attribute/Makefile.am
@@ -17,28 +17,28 @@ if USE_COVERAGE
17endif 17endif
18 18
19lib_LTLIBRARIES = \ 19lib_LTLIBRARIES = \
20 libgnunetidentityattribute.la 20 libgnunetreclaimattribute.la
21 21
22libgnunetidentityattribute_la_SOURCES = \ 22libgnunetreclaimattribute_la_SOURCES = \
23 identity_attribute.c 23 reclaim_attribute.c
24libgnunetidentityattribute_la_LIBADD = \ 24libgnunetreclaimattribute_la_LIBADD = \
25 $(top_builddir)/src/util/libgnunetutil.la \ 25 $(top_builddir)/src/util/libgnunetutil.la \
26 $(GN_LIBINTL) 26 $(GN_LIBINTL)
27libgnunetidentityattribute_la_LDFLAGS = \ 27libgnunetreclaimattribute_la_LDFLAGS = \
28 $(GN_LIB_LDFLAGS) $(WINFLAGS) \ 28 $(GN_LIB_LDFLAGS) $(WINFLAGS) \
29 -version-info 0:0:0 29 -version-info 0:0:0
30 30
31 31
32plugin_LTLIBRARIES = \ 32plugin_LTLIBRARIES = \
33 libgnunet_plugin_identity_attribute_gnuid.la 33 libgnunet_plugin_reclaim_attribute_gnuid.la
34 34
35 35
36libgnunet_plugin_identity_attribute_gnuid_la_SOURCES = \ 36libgnunet_plugin_reclaim_attribute_gnuid_la_SOURCES = \
37 plugin_identity_attribute_gnuid.c 37 plugin_reclaim_attribute_gnuid.c
38libgnunet_plugin_identity_attribute_gnuid_la_LIBADD = \ 38libgnunet_plugin_reclaim_attribute_gnuid_la_LIBADD = \
39 $(top_builddir)/src/util/libgnunetutil.la \ 39 $(top_builddir)/src/util/libgnunetutil.la \
40 $(LTLIBINTL) 40 $(LTLIBINTL)
41libgnunet_plugin_identity_attribute_gnuid_la_LDFLAGS = \ 41libgnunet_plugin_reclaim_attribute_gnuid_la_LDFLAGS = \
42 $(GN_PLUGIN_LDFLAGS) 42 $(GN_PLUGIN_LDFLAGS)
43 43
44 44
diff --git a/src/identity-attribute/plugin_identity_attribute_gnuid.c b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c
index c09b167f5..48afc0732 100644
--- a/src/identity-attribute/plugin_identity_attribute_gnuid.c
+++ b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c
@@ -17,7 +17,7 @@
17*/ 17*/
18 18
19/** 19/**
20 * @file identity-attribute/plugin_identity_attribute_gnuid.c 20 * @file reclaim-attribute/plugin_reclaim_attribute_gnuid.c
21 * @brief identity attribute plugin to provide the API for fundamental 21 * @brief identity attribute plugin to provide the API for fundamental
22 * attribute types. 22 * attribute types.
23 * 23 *
@@ -25,7 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_identity_attribute_plugin.h" 28#include "gnunet_reclaim_attribute_plugin.h"
29#include <inttypes.h> 29#include <inttypes.h>
30 30
31 31
@@ -47,7 +47,7 @@ gnuid_value_to_string (void *cls,
47 47
48 switch (type) 48 switch (type)
49 { 49 {
50 case GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING: 50 case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING:
51 return GNUNET_strndup (data, data_size); 51 return GNUNET_strndup (data, data_size);
52 default: 52 default:
53 return NULL; 53 return NULL;
@@ -78,7 +78,7 @@ gnuid_string_to_value (void *cls,
78 switch (type) 78 switch (type)
79 { 79 {
80 80
81 case GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING: 81 case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING:
82 *data = GNUNET_strdup (s); 82 *data = GNUNET_strdup (s);
83 *data_size = strlen (s); 83 *data_size = strlen (s);
84 return GNUNET_OK; 84 return GNUNET_OK;
@@ -96,7 +96,7 @@ static struct {
96 const char *name; 96 const char *name;
97 uint32_t number; 97 uint32_t number;
98} gnuid_name_map[] = { 98} gnuid_name_map[] = {
99 { "STRING", GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING }, 99 { "STRING", GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING },
100 { NULL, UINT32_MAX } 100 { NULL, UINT32_MAX }
101}; 101};
102 102
@@ -151,11 +151,11 @@ gnuid_number_to_typename (void *cls,
151 * @return the exported block API 151 * @return the exported block API
152 */ 152 */
153void * 153void *
154libgnunet_plugin_identity_attribute_gnuid_init (void *cls) 154libgnunet_plugin_reclaim_attribute_gnuid_init (void *cls)
155{ 155{
156 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api; 156 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api;
157 157
158 api = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions); 158 api = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions);
159 api->value_to_string = &gnuid_value_to_string; 159 api->value_to_string = &gnuid_value_to_string;
160 api->string_to_value = &gnuid_string_to_value; 160 api->string_to_value = &gnuid_string_to_value;
161 api->typename_to_number = &gnuid_typename_to_number; 161 api->typename_to_number = &gnuid_typename_to_number;
@@ -171,12 +171,12 @@ libgnunet_plugin_identity_attribute_gnuid_init (void *cls)
171 * @return NULL 171 * @return NULL
172 */ 172 */
173void * 173void *
174libgnunet_plugin_identity_attribute_gnuid_done (void *cls) 174libgnunet_plugin_reclaim_attribute_gnuid_done (void *cls)
175{ 175{
176 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api = cls; 176 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = cls;
177 177
178 GNUNET_free (api); 178 GNUNET_free (api);
179 return NULL; 179 return NULL;
180} 180}
181 181
182/* end of plugin_identity_attribute_type_gnuid.c */ 182/* end of plugin_reclaim_attribute_type_gnuid.c */
diff --git a/src/identity-attribute/identity_attribute.c b/src/reclaim-attribute/reclaim_attribute.c
index 7d47c46a7..1ffa9618f 100644
--- a/src/identity-attribute/identity_attribute.c
+++ b/src/reclaim-attribute/reclaim_attribute.c
@@ -17,14 +17,14 @@
17 */ 17 */
18 18
19/** 19/**
20 * @file identity-attribute/identity_attribute.c 20 * @file reclaim-attribute/reclaim_attribute.c
21 * @brief helper library to manage identity attributes 21 * @brief helper library to manage identity attributes
22 * @author Martin Schanzenbach 22 * @author Martin Schanzenbach
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
26#include "identity_attribute.h" 26#include "reclaim_attribute.h"
27#include "gnunet_identity_attribute_plugin.h" 27#include "gnunet_reclaim_attribute_plugin.h"
28 28
29/** 29/**
30 * Handle for a plugin 30 * Handle for a plugin
@@ -39,7 +39,7 @@ struct Plugin
39 /** 39 /**
40 * Plugin API 40 * Plugin API
41 */ 41 */
42 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api; 42 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api;
43}; 43};
44 44
45/** 45/**
@@ -65,7 +65,7 @@ add_plugin (void* cls,
65 const char *library_name, 65 const char *library_name,
66 void *lib_ret) 66 void *lib_ret)
67{ 67{
68 struct GNUNET_IDENTITY_ATTRIBUTE_PluginFunctions *api = lib_ret; 68 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret;
69 struct Plugin *plugin; 69 struct Plugin *plugin;
70 70
71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -86,7 +86,7 @@ init()
86 if (GNUNET_YES == initialized) 86 if (GNUNET_YES == initialized)
87 return; 87 return;
88 initialized = GNUNET_YES; 88 initialized = GNUNET_YES;
89 GNUNET_PLUGIN_load_all ("libgnunet_plugin_identity_attribute_", NULL, 89 GNUNET_PLUGIN_load_all ("libgnunet_plugin_reclaim_attribute_", NULL,
90 &add_plugin, NULL); 90 &add_plugin, NULL);
91} 91}
92 92
@@ -97,7 +97,7 @@ init()
97 * @return corresponding number, UINT32_MAX on error 97 * @return corresponding number, UINT32_MAX on error
98 */ 98 */
99uint32_t 99uint32_t
100GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename) 100GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename)
101{ 101{
102 unsigned int i; 102 unsigned int i;
103 struct Plugin *plugin; 103 struct Plugin *plugin;
@@ -121,7 +121,7 @@ GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (const char *typename)
121 * @return corresponding typestring, NULL on error 121 * @return corresponding typestring, NULL on error
122 */ 122 */
123const char* 123const char*
124GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type) 124GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type)
125{ 125{
126 unsigned int i; 126 unsigned int i;
127 struct Plugin *plugin; 127 struct Plugin *plugin;
@@ -149,7 +149,7 @@ GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type)
149 * @return #GNUNET_OK on success 149 * @return #GNUNET_OK on success
150 */ 150 */
151int 151int
152GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type, 152GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
153 const char *s, 153 const char *s,
154 void **data, 154 void **data,
155 size_t *data_size) 155 size_t *data_size)
@@ -180,7 +180,7 @@ GNUNET_IDENTITY_ATTRIBUTE_string_to_value (uint32_t type,
180 * @return NULL on error, otherwise human-readable representation of the claim 180 * @return NULL on error, otherwise human-readable representation of the claim
181 */ 181 */
182char * 182char *
183GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type, 183GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
184 const void* data, 184 const void* data,
185 size_t data_size) 185 size_t data_size)
186{ 186{
@@ -210,31 +210,35 @@ GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type,
210 * @param data_size the attribute value size 210 * @param data_size the attribute value size
211 * @return the new attribute 211 * @return the new attribute
212 */ 212 */
213struct GNUNET_IDENTITY_ATTRIBUTE_Claim * 213struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
214GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, 214GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
215 uint32_t type, 215 uint32_t type,
216 const void* data, 216 const void* data,
217 size_t data_size) 217 size_t data_size)
218{ 218{
219 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr; 219 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
220 char *write_ptr; 220 char *write_ptr;
221 char *attr_name_tmp = GNUNET_strdup (attr_name);
221 222
222 attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) + 223 GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp);
223 strlen (attr_name) + 1 + 224
225 attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) +
226 strlen (attr_name_tmp) + 1 +
224 data_size); 227 data_size);
225 attr->type = type; 228 attr->type = type;
226 attr->data_size = data_size; 229 attr->data_size = data_size;
227 attr->version = 0; 230 attr->version = 0;
228 write_ptr = (char*)&attr[1]; 231 write_ptr = (char*)&attr[1];
229 GNUNET_memcpy (write_ptr, 232 GNUNET_memcpy (write_ptr,
230 attr_name, 233 attr_name_tmp,
231 strlen (attr_name) + 1); 234 strlen (attr_name_tmp) + 1);
232 attr->name = write_ptr; 235 attr->name = write_ptr;
233 write_ptr += strlen (attr->name) + 1; 236 write_ptr += strlen (attr->name) + 1;
234 GNUNET_memcpy (write_ptr, 237 GNUNET_memcpy (write_ptr,
235 data, 238 data,
236 data_size); 239 data_size);
237 attr->data = write_ptr; 240 attr->data = write_ptr;
241 GNUNET_free (attr_name_tmp);
238 return attr; 242 return attr;
239} 243}
240 244
@@ -249,15 +253,15 @@ GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name,
249 * @return 253 * @return
250 */ 254 */
251void 255void
252GNUNET_IDENTITY_ATTRIBUTE_list_add (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *claim_list, 256GNUNET_RECLAIM_ATTRIBUTE_list_add (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list,
253 const char* attr_name, 257 const char* attr_name,
254 uint32_t type, 258 uint32_t type,
255 const void* data, 259 const void* data,
256 size_t data_size) 260 size_t data_size)
257{ 261{
258 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 262 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
259 le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); 263 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
260 le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name, 264 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
261 type, 265 type,
262 data, 266 data,
263 data_size); 267 data_size);
@@ -267,20 +271,20 @@ GNUNET_IDENTITY_ATTRIBUTE_list_add (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *
267} 271}
268 272
269size_t 273size_t
270GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 274GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
271{ 275{
272 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 276 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
273 size_t len = 0; 277 size_t len = 0;
274 for (le = attrs->list_head; NULL != le; le = le->next) 278 for (le = attrs->list_head; NULL != le; le = le->next)
275 len += GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (le->claim); 279 len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim);
276 return len; 280 return len;
277} 281}
278 282
279size_t 283size_t
280GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 284GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
281 char *result) 285 char *result)
282{ 286{
283 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 287 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
284 size_t len; 288 size_t len;
285 size_t total_len; 289 size_t total_len;
286 char* write_ptr; 290 char* write_ptr;
@@ -289,7 +293,7 @@ GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE
289 total_len = 0; 293 total_len = 0;
290 for (le = attrs->list_head; NULL != le; le = le->next) 294 for (le = attrs->list_head; NULL != le; le = le->next)
291 { 295 {
292 len = GNUNET_IDENTITY_ATTRIBUTE_serialize (le->claim, 296 len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim,
293 write_ptr); 297 write_ptr);
294 total_len += len; 298 total_len += len;
295 write_ptr += len; 299 write_ptr += len;
@@ -297,49 +301,49 @@ GNUNET_IDENTITY_ATTRIBUTE_list_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE
297 return total_len; 301 return total_len;
298} 302}
299 303
300struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList * 304struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
301GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (const char* data, 305GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data,
302 size_t data_size) 306 size_t data_size)
303{ 307{
304 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; 308 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
305 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 309 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
306 size_t attr_len; 310 size_t attr_len;
307 const char* read_ptr; 311 const char* read_ptr;
308 312
309 if (data_size < sizeof (struct Attribute)) 313 if (data_size < sizeof (struct Attribute))
310 return NULL; 314 return NULL;
311 315
312 attrs = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); 316 attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
313 read_ptr = data; 317 read_ptr = data;
314 while (((data + data_size) - read_ptr) >= sizeof (struct Attribute)) 318 while (((data + data_size) - read_ptr) >= sizeof (struct Attribute))
315 { 319 {
316 320
317 le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); 321 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
318 le->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize (read_ptr, 322 le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr,
319 data_size - (read_ptr - data)); 323 data_size - (read_ptr - data));
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
321 "Deserialized attribute %s\n", le->claim->name); 325 "Deserialized attribute %s\n", le->claim->name);
322 GNUNET_CONTAINER_DLL_insert (attrs->list_head, 326 GNUNET_CONTAINER_DLL_insert (attrs->list_head,
323 attrs->list_tail, 327 attrs->list_tail,
324 le); 328 le);
325 attr_len = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (le->claim); 329 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim);
326 read_ptr += attr_len; 330 read_ptr += attr_len;
327 } 331 }
328 return attrs; 332 return attrs;
329} 333}
330 334
331struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList* 335struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList*
332GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 336GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
333{ 337{
334 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 338 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
335 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *result_le; 339 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le;
336 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *result; 340 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result;
337 341
338 result = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); 342 result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
339 for (le = attrs->list_head; NULL != le; le = le->next) 343 for (le = attrs->list_head; NULL != le; le = le->next)
340 { 344 {
341 result_le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); 345 result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
342 result_le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (le->claim->name, 346 result_le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name,
343 le->claim->type, 347 le->claim->type,
344 le->claim->data, 348 le->claim->data,
345 le->claim->data_size); 349 le->claim->data_size);
@@ -352,10 +356,10 @@ GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim
352 356
353 357
354void 358void
355GNUNET_IDENTITY_ATTRIBUTE_list_destroy (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 359GNUNET_RECLAIM_ATTRIBUTE_list_destroy (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
356{ 360{
357 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 361 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
358 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *tmp_le; 362 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le;
359 363
360 for (le = attrs->list_head; NULL != le;) 364 for (le = attrs->list_head; NULL != le;)
361 { 365 {
@@ -369,7 +373,7 @@ GNUNET_IDENTITY_ATTRIBUTE_list_destroy (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimLi
369} 373}
370 374
371size_t 375size_t
372GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 376GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
373{ 377{
374 return sizeof (struct Attribute) 378 return sizeof (struct Attribute)
375 + strlen (attr->name) 379 + strlen (attr->name)
@@ -377,7 +381,7 @@ GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (const struct GNUNET_IDENTITY_ATTRI
377} 381}
378 382
379size_t 383size_t
380GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, 384GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
381 char *result) 385 char *result)
382{ 386{
383 size_t data_len_ser; 387 size_t data_len_ser;
@@ -403,11 +407,11 @@ GNUNET_IDENTITY_ATTRIBUTE_serialize (const struct GNUNET_IDENTITY_ATTRIBUTE_Clai
403 return sizeof (struct Attribute) + strlen (attr->name) + attr->data_size; 407 return sizeof (struct Attribute) + strlen (attr->name) + attr->data_size;
404} 408}
405 409
406struct GNUNET_IDENTITY_ATTRIBUTE_Claim * 410struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
407GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data, 411GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data,
408 size_t data_size) 412 size_t data_size)
409{ 413{
410 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr; 414 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
411 struct Attribute *attr_ser; 415 struct Attribute *attr_ser;
412 size_t data_len; 416 size_t data_len;
413 size_t name_len; 417 size_t name_len;
@@ -419,7 +423,7 @@ GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data,
419 attr_ser = (struct Attribute*)data; 423 attr_ser = (struct Attribute*)data;
420 data_len = ntohs (attr_ser->data_size); 424 data_len = ntohs (attr_ser->data_size);
421 name_len = ntohs (attr_ser->name_len); 425 name_len = ntohs (attr_ser->name_len);
422 attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) 426 attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim)
423 + data_len + name_len + 1); 427 + data_len + name_len + 1);
424 attr->type = ntohs (attr_ser->attribute_type); 428 attr->type = ntohs (attr_ser->attribute_type);
425 attr->version = ntohl (attr_ser->attribute_version); 429 attr->version = ntohl (attr_ser->attribute_version);
@@ -441,4 +445,4 @@ GNUNET_IDENTITY_ATTRIBUTE_deserialize (const char* data,
441 445
442} 446}
443 447
444/* end of identity_attribute.c */ 448/* end of reclaim_attribute.c */
diff --git a/src/identity-attribute/identity_attribute.h b/src/reclaim-attribute/reclaim_attribute.h
index 2346dcde1..746d32980 100644
--- a/src/identity-attribute/identity_attribute.h
+++ b/src/reclaim-attribute/reclaim_attribute.h
@@ -17,14 +17,14 @@
17 */ 17 */
18/** 18/**
19 * @author Martin Schanzenbach 19 * @author Martin Schanzenbach
20 * @file identity-attribute/identity_attribute.h 20 * @file reclaim-attribute/reclaim_attribute.h
21 * @brief GNUnet Identity attributes 21 * @brief GNUnet reclaim identity attributes
22 * 22 *
23 */ 23 */
24#ifndef IDENTITY_ATTRIBUTE_H 24#ifndef RECLAIM_ATTRIBUTE_H
25#define IDENTITY_ATTRIBUTE_H 25#define RECLAIM_ATTRIBUTE_H
26 26
27#include "gnunet_identity_provider_service.h" 27#include "gnunet_reclaim_service.h"
28 28
29struct Attribute 29struct Attribute
30{ 30{
diff --git a/src/identity-provider/.gitignore b/src/reclaim/.gitignore
index ef77fccdc..ef77fccdc 100644
--- a/src/identity-provider/.gitignore
+++ b/src/reclaim/.gitignore
diff --git a/src/identity-provider/Makefile.am b/src/reclaim/Makefile.am
index 2eb699542..2ee43d21a 100644
--- a/src/identity-provider/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -13,12 +13,12 @@ if USE_COVERAGE
13endif 13endif
14 14
15if HAVE_SQLITE 15if HAVE_SQLITE
16SQLITE_PLUGIN = libgnunet_plugin_identity_provider_sqlite.la 16SQLITE_PLUGIN = libgnunet_plugin_reclaim_sqlite.la
17endif 17endif
18 18
19EXTRA_DIST = \ 19EXTRA_DIST = \
20 test_idp_defaults.conf \ 20 test_reclaim_defaults.conf \
21 test_idp.conf \ 21 test_reclaim.conf \
22 $(check_SCRIPTS) 22 $(check_SCRIPTS)
23 23
24pkgcfgdir= $(pkgdatadir)/config.d/ 24pkgcfgdir= $(pkgdatadir)/config.d/
@@ -26,46 +26,46 @@ pkgcfgdir= $(pkgdatadir)/config.d/
26libexecdir= $(pkglibdir)/libexec/ 26libexecdir= $(pkglibdir)/libexec/
27 27
28pkgcfg_DATA = \ 28pkgcfg_DATA = \
29 identity-provider.conf 29 reclaim.conf
30 30
31lib_LTLIBRARIES = \ 31lib_LTLIBRARIES = \
32 libgnunetidentityprovider.la 32 libgnunetreclaim.la
33plugin_LTLIBRARIES = \ 33plugin_LTLIBRARIES = \
34 libgnunet_plugin_rest_identity_provider.la \ 34 libgnunet_plugin_rest_reclaim.la \
35 libgnunet_plugin_rest_openid_connect.la \ 35 libgnunet_plugin_rest_openid_connect.la \
36 libgnunet_plugin_gnsrecord_identity_provider.la \ 36 libgnunet_plugin_gnsrecord_reclaim.la \
37 $(SQLITE_PLUGIN) 37 $(SQLITE_PLUGIN)
38 38
39bin_PROGRAMS = \ 39bin_PROGRAMS = \
40 gnunet-idp 40 gnunet-reclaim
41 41
42libexec_PROGRAMS = \ 42libexec_PROGRAMS = \
43 gnunet-service-identity-provider 43 gnunet-service-reclaim
44 44
45libgnunet_plugin_gnsrecord_identity_provider_la_SOURCES = \ 45libgnunet_plugin_gnsrecord_reclaim_la_SOURCES = \
46 plugin_gnsrecord_identity_provider.c 46 plugin_gnsrecord_reclaim.c
47libgnunet_plugin_gnsrecord_identity_provider_la_LIBADD = \ 47libgnunet_plugin_gnsrecord_reclaim_la_LIBADD = \
48 $(top_builddir)/src/util/libgnunetutil.la \ 48 $(top_builddir)/src/util/libgnunetutil.la \
49 $(LTLIBINTL) 49 $(LTLIBINTL)
50libgnunet_plugin_gnsrecord_identity_provider_la_LDFLAGS = \ 50libgnunet_plugin_gnsrecord_reclaim_la_LDFLAGS = \
51 $(GN_PLUGIN_LDFLAGS) 51 $(GN_PLUGIN_LDFLAGS)
52 52
53libgnunet_plugin_identity_provider_sqlite_la_SOURCES = \ 53libgnunet_plugin_reclaim_sqlite_la_SOURCES = \
54 plugin_identity_provider_sqlite.c 54 plugin_reclaim_sqlite.c
55libgnunet_plugin_identity_provider_sqlite_la_LIBADD = \ 55libgnunet_plugin_reclaim_sqlite_la_LIBADD = \
56 libgnunetidentityprovider.la \ 56 libgnunetreclaim.la \
57 $(top_builddir)/src/sq/libgnunetsq.la \ 57 $(top_builddir)/src/sq/libgnunetsq.la \
58 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 58 $(top_builddir)/src/statistics/libgnunetstatistics.la \
59 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ 59 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \
60 $(LTLIBINTL) 60 $(LTLIBINTL)
61libgnunet_plugin_identity_provider_sqlite_la_LDFLAGS = \ 61libgnunet_plugin_reclaim_sqlite_la_LDFLAGS = \
62 $(GN_PLUGIN_LDFLAGS) 62 $(GN_PLUGIN_LDFLAGS)
63 63
64 64
65 65
66gnunet_service_identity_provider_SOURCES = \ 66gnunet_service_reclaim_SOURCES = \
67 gnunet-service-identity-provider.c 67 gnunet-service-reclaim.c
68gnunet_service_identity_provider_LDADD = \ 68gnunet_service_reclaim_LDADD = \
69 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 69 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
70 $(top_builddir)/src/util/libgnunetutil.la \ 70 $(top_builddir)/src/util/libgnunetutil.la \
71 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 71 $(top_builddir)/src/namestore/libgnunetnamestore.la \
@@ -73,66 +73,67 @@ gnunet_service_identity_provider_LDADD = \
73 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 73 $(top_builddir)/src/statistics/libgnunetstatistics.la \
74 $(top_builddir)/src/abe/libgnunetabe.la \ 74 $(top_builddir)/src/abe/libgnunetabe.la \
75 $(top_builddir)/src/credential/libgnunetcredential.la \ 75 $(top_builddir)/src/credential/libgnunetcredential.la \
76 $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ 76 $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \
77 libgnunetidentityprovider.la \ 77 libgnunetreclaim.la \
78 $(top_builddir)/src/gns/libgnunetgns.la \ 78 $(top_builddir)/src/gns/libgnunetgns.la \
79 $(GN_LIBINTL) 79 $(GN_LIBINTL)
80 80
81libgnunetidentityprovider_la_SOURCES = \ 81libgnunetreclaim_la_SOURCES = \
82 identity_provider_api.c \ 82 reclaim_api.c \
83 identity_provider.h 83 reclaim.h
84libgnunetidentityprovider_la_LIBADD = \ 84libgnunetreclaim_la_LIBADD = \
85 $(top_builddir)/src/util/libgnunetutil.la \ 85 $(top_builddir)/src/util/libgnunetutil.la \
86 $(GN_LIBINTL) $(XLIB) 86 $(GN_LIBINTL) $(XLIB)
87libgnunetidentityprovider_la_LDFLAGS = \ 87libgnunetreclaim_la_LDFLAGS = \
88 $(GN_LIB_LDFLAGS) $(WINFLAGS) \ 88 $(GN_LIB_LDFLAGS) $(WINFLAGS) \
89 -version-info 0:0:0 89 -version-info 0:0:0
90 90
91libgnunet_plugin_rest_identity_provider_la_SOURCES = \ 91libgnunet_plugin_rest_reclaim_la_SOURCES = \
92 plugin_rest_identity_provider.c \ 92 plugin_rest_reclaim.c
93 jwt.c 93libgnunet_plugin_rest_reclaim_la_LIBADD = \
94libgnunet_plugin_rest_identity_provider_la_LIBADD = \
95 $(top_builddir)/src/identity/libgnunetidentity.la \ 94 $(top_builddir)/src/identity/libgnunetidentity.la \
96 libgnunetidentityprovider.la \ 95 libgnunetreclaim.la \
97 $(top_builddir)/src/rest/libgnunetrest.la \ 96 $(top_builddir)/src/rest/libgnunetrest.la \
98 $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ 97 $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \
99 $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ 98 $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \
100 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 99 $(top_builddir)/src/namestore/libgnunetnamestore.la \
101 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ 100 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
102 $(LTLIBINTL) -ljansson -lmicrohttpd 101 $(LTLIBINTL) -ljansson -lmicrohttpd
103libgnunet_plugin_rest_identity_provider_la_LDFLAGS = \ 102libgnunet_plugin_rest_reclaim_la_LDFLAGS = \
104 $(GN_PLUGIN_LDFLAGS) 103 $(GN_PLUGIN_LDFLAGS)
105 104
106libgnunet_plugin_rest_openid_connect_la_SOURCES = \ 105libgnunet_plugin_rest_openid_connect_la_SOURCES = \
107 plugin_rest_openid_connect.c \ 106 plugin_rest_openid_connect.c \
108 jwt.c 107 oidc_helper.c
109libgnunet_plugin_rest_openid_connect_la_LIBADD = \ 108libgnunet_plugin_rest_openid_connect_la_LIBADD = \
110 $(top_builddir)/src/identity/libgnunetidentity.la \ 109 $(top_builddir)/src/identity/libgnunetidentity.la \
111 libgnunetidentityprovider.la \ 110 libgnunetreclaim.la \
112 $(top_builddir)/src/rest/libgnunetrest.la \ 111 $(top_builddir)/src/rest/libgnunetrest.la \
113 $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ 112 $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \
114 $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ 113 $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \
115 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 114 $(top_builddir)/src/namestore/libgnunetnamestore.la \
115 $(top_builddir)/src/gns/libgnunetgns.la \
116 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
116 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ 117 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
117 $(LTLIBINTL) -ljansson -lmicrohttpd 118 $(LTLIBINTL) -ljansson -lmicrohttpd
118libgnunet_plugin_rest_openid_connect_la_LDFLAGS = \ 119libgnunet_plugin_rest_openid_connect_la_LDFLAGS = \
119 $(GN_PLUGIN_LDFLAGS) 120 $(GN_PLUGIN_LDFLAGS)
120 121
121gnunet_idp_SOURCES = \ 122gnunet_reclaim_SOURCES = \
122 gnunet-idp.c 123 gnunet-reclaim.c
123gnunet_idp_LDADD = \ 124gnunet_reclaim_LDADD = \
124 $(top_builddir)/src/util/libgnunetutil.la \ 125 $(top_builddir)/src/util/libgnunetutil.la \
125 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 126 $(top_builddir)/src/namestore/libgnunetnamestore.la \
126 libgnunetidentityprovider.la \ 127 libgnunetreclaim.la \
127 $(top_builddir)/src/identity/libgnunetidentity.la \ 128 $(top_builddir)/src/identity/libgnunetidentity.la \
128 $(top_builddir)/src/identity-attribute/libgnunetidentityattribute.la \ 129 $(top_builddir)/src/reclaim-attribute/libgnunetreclaimattribute.la \
129 $(GN_LIBINTL) 130 $(GN_LIBINTL)
130 131
131check_SCRIPTS = \ 132check_SCRIPTS = \
132 test_idp_attribute.sh \ 133 test_reclaim_attribute.sh \
133 test_idp_issue.sh \ 134 test_reclaim_issue.sh \
134 test_idp_consume.sh \ 135 test_reclaim_consume.sh \
135 test_idp_revoke.sh 136 test_reclaim_revoke.sh
136 137
137if ENABLE_TEST_RUN 138if ENABLE_TEST_RUN
138 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 139 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
diff --git a/src/identity-provider/gnunet-idp.c b/src/reclaim/gnunet-reclaim.c
index 79e4f8d27..677e9f49f 100644
--- a/src/identity-provider/gnunet-idp.c
+++ b/src/reclaim/gnunet-reclaim.c
@@ -17,7 +17,7 @@
17 */ 17 */
18/** 18/**
19 * @author Martin Schanzenbach 19 * @author Martin Schanzenbach
20 * @file src/identity-provider/gnunet-idp.c 20 * @file src/reclaim/gnunet-reclaim.c
21 * @brief Identity Provider utility 21 * @brief Identity Provider utility
22 * 22 *
23 */ 23 */
@@ -25,7 +25,7 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27#include "gnunet_namestore_service.h" 27#include "gnunet_namestore_service.h"
28#include "gnunet_identity_provider_service.h" 28#include "gnunet_reclaim_service.h"
29#include "gnunet_identity_service.h" 29#include "gnunet_identity_service.h"
30#include "gnunet_signatures.h" 30#include "gnunet_signatures.h"
31 31
@@ -85,19 +85,19 @@ static char* ego_name;
85static struct GNUNET_IDENTITY_Handle *identity_handle; 85static struct GNUNET_IDENTITY_Handle *identity_handle;
86 86
87/** 87/**
88 * IdP handle 88 * reclaim handle
89 */ 89 */
90static struct GNUNET_IDENTITY_PROVIDER_Handle *idp_handle; 90static struct GNUNET_RECLAIM_Handle *reclaim_handle;
91 91
92/** 92/**
93 * IdP operation 93 * reclaim operation
94 */ 94 */
95static struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op; 95static struct GNUNET_RECLAIM_Operation *reclaim_op;
96 96
97/** 97/**
98 * Attribute iterator 98 * Attribute iterator
99 */ 99 */
100static struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_iterator; 100static struct GNUNET_RECLAIM_AttributeIterator *attr_iterator;
101 101
102/** 102/**
103 * Master ABE key 103 * Master ABE key
@@ -117,12 +117,12 @@ static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key;
117/** 117/**
118 * Ticket to consume 118 * Ticket to consume
119 */ 119 */
120static struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 120static struct GNUNET_RECLAIM_Ticket ticket;
121 121
122/** 122/**
123 * Attribute list 123 * Attribute list
124 */ 124 */
125static struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attr_list; 125static struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
126 126
127/** 127/**
128 * Attribute expiration interval 128 * Attribute expiration interval
@@ -134,17 +134,28 @@ static struct GNUNET_TIME_Relative exp_interval;
134 */ 134 */
135static struct GNUNET_SCHEDULER_Task *timeout; 135static struct GNUNET_SCHEDULER_Task *timeout;
136 136
137/**
138 * Cleanup task
139 */
140static struct GNUNET_SCHEDULER_Task *cleanup_task;
141
142/**
143 * Claim to store
144 */
145struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
146
137static void 147static void
138do_cleanup(void *cls) 148do_cleanup(void *cls)
139{ 149{
150 cleanup_task = NULL;
140 if (NULL != timeout) 151 if (NULL != timeout)
141 GNUNET_SCHEDULER_cancel (timeout); 152 GNUNET_SCHEDULER_cancel (timeout);
142 if (NULL != idp_op) 153 if (NULL != reclaim_op)
143 GNUNET_IDENTITY_PROVIDER_cancel (idp_op); 154 GNUNET_RECLAIM_cancel (reclaim_op);
144 if (NULL != attr_iterator) 155 if (NULL != attr_iterator)
145 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator); 156 GNUNET_RECLAIM_get_attributes_stop (attr_iterator);
146 if (NULL != idp_handle) 157 if (NULL != reclaim_handle)
147 GNUNET_IDENTITY_PROVIDER_disconnect (idp_handle); 158 GNUNET_RECLAIM_disconnect (reclaim_handle);
148 if (NULL != identity_handle) 159 if (NULL != identity_handle)
149 GNUNET_IDENTITY_disconnect (identity_handle); 160 GNUNET_IDENTITY_disconnect (identity_handle);
150 if (NULL != abe_key) 161 if (NULL != abe_key)
@@ -155,18 +166,18 @@ do_cleanup(void *cls)
155 166
156static void 167static void
157ticket_issue_cb (void* cls, 168ticket_issue_cb (void* cls,
158 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket) 169 const struct GNUNET_RECLAIM_Ticket *ticket)
159{ 170{
160 char* ticket_str; 171 char* ticket_str;
161 idp_op = NULL; 172 reclaim_op = NULL;
162 if (NULL != ticket) { 173 if (NULL != ticket) {
163 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket, 174 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
164 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); 175 sizeof (struct GNUNET_RECLAIM_Ticket));
165 printf("%s\n", 176 printf("%s\n",
166 ticket_str); 177 ticket_str);
167 GNUNET_free (ticket_str); 178 GNUNET_free (ticket_str);
168 } 179 }
169 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 180 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
170} 181}
171 182
172static void 183static void
@@ -174,24 +185,26 @@ store_attr_cont (void *cls,
174 int32_t success, 185 int32_t success,
175 const char*emsg) 186 const char*emsg)
176{ 187{
177 idp_op = NULL; 188 reclaim_op = NULL;
178 if (GNUNET_SYSERR == success) { 189 if (GNUNET_SYSERR == success) {
179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 190 fprintf (stderr,
180 "%s\n", emsg); 191 "%s\n", emsg);
181 } 192 }
182 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 193 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
183} 194}
184 195
185static void 196static void
186process_attrs (void *cls, 197process_attrs (void *cls,
187 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 198 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
188 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 199 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
189{ 200{
190 char *value_str; 201 char *value_str;
202 const char* attr_type;
203
191 if (NULL == identity) 204 if (NULL == identity)
192 { 205 {
193 idp_op = NULL; 206 reclaim_op = NULL;
194 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 207 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
195 return; 208 return;
196 } 209 }
197 if (NULL == attr) 210 if (NULL == attr)
@@ -199,11 +212,12 @@ process_attrs (void *cls,
199 ret = 1; 212 ret = 1;
200 return; 213 return;
201 } 214 }
202 value_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (attr->type, 215 value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
203 attr->data, 216 attr->data,
204 attr->data_size); 217 attr->data_size);
205 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 218 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
206 "%s: %s\n", attr->name, value_str); 219 fprintf (stdout,
220 "%s: %s [%s,v%u]\n", attr->name, value_str, attr_type, attr->version);
207} 221}
208 222
209 223
@@ -211,9 +225,9 @@ static void
211iter_error (void *cls) 225iter_error (void *cls)
212{ 226{
213 attr_iterator = NULL; 227 attr_iterator = NULL;
214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 228 fprintf (stderr,
215 "Failed to iterate over attributes\n"); 229 "Failed to iterate over attributes\n");
216 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 230 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
217} 231}
218 232
219static void 233static void
@@ -221,28 +235,28 @@ timeout_task (void *cls)
221{ 235{
222 timeout = NULL; 236 timeout = NULL;
223 ret = 1; 237 ret = 1;
224 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 238 fprintf (stderr,
225 "Timeout\n"); 239 "Timeout\n");
226 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 240 if (NULL == cleanup_task)
241 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
227} 242}
228 243
229static void 244static void
230process_rvk (void *cls, int success, const char* msg) 245process_rvk (void *cls, int success, const char* msg)
231{ 246{
232 idp_op = NULL; 247 reclaim_op = NULL;
233 if (GNUNET_OK != success) 248 if (GNUNET_OK != success)
234 { 249 {
235 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 250 fprintf (stderr,
236 "Revocation failed.\n"); 251 "Revocation failed.\n");
237 ret = 1; 252 ret = 1;
238 } 253 }
239 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 254 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
240} 255}
241 256
242static void 257static void
243iter_finished (void *cls) 258iter_finished (void *cls)
244{ 259{
245 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim;
246 char *data; 260 char *data;
247 size_t data_size; 261 size_t data_size;
248 int type; 262 int type;
@@ -250,27 +264,27 @@ iter_finished (void *cls)
250 attr_iterator = NULL; 264 attr_iterator = NULL;
251 if (list) 265 if (list)
252 { 266 {
253 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 267 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
254 return; 268 return;
255 } 269 }
256 270
257 if (issue_attrs) 271 if (issue_attrs)
258 { 272 {
259 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (idp_handle, 273 reclaim_op = GNUNET_RECLAIM_ticket_issue (reclaim_handle,
260 pkey, 274 pkey,
261 &rp_key, 275 &rp_key,
262 attr_list, 276 attr_list,
263 &ticket_issue_cb, 277 &ticket_issue_cb,
264 NULL); 278 NULL);
265 return; 279 return;
266 } 280 }
267 if (consume_ticket) 281 if (consume_ticket)
268 { 282 {
269 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (idp_handle, 283 reclaim_op = GNUNET_RECLAIM_ticket_consume (reclaim_handle,
270 pkey, 284 pkey,
271 &ticket, 285 &ticket,
272 &process_attrs, 286 &process_attrs,
273 NULL); 287 NULL);
274 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), 288 timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
275 &timeout_task, 289 &timeout_task,
276 NULL); 290 NULL);
@@ -278,82 +292,112 @@ iter_finished (void *cls)
278 } 292 }
279 if (revoke_ticket) 293 if (revoke_ticket)
280 { 294 {
281 idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (idp_handle, 295 reclaim_op = GNUNET_RECLAIM_ticket_revoke (reclaim_handle,
282 pkey, 296 pkey,
283 &ticket, 297 &ticket,
284 &process_rvk, 298 &process_rvk,
285 NULL); 299 NULL);
286 return; 300 return;
287 } 301 }
288 if (attr_name) 302 if (attr_name)
289 { 303 {
290 if (NULL == type_str) 304 if (NULL == type_str)
291 type = GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING; 305 type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
292 else 306 else
293 type = GNUNET_IDENTITY_ATTRIBUTE_typename_to_number (type_str); 307 type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str);
294 308
295 GNUNET_assert (GNUNET_SYSERR != GNUNET_IDENTITY_ATTRIBUTE_string_to_value (type, 309 GNUNET_assert (GNUNET_SYSERR != GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type,
296 attr_value, 310 attr_value,
297 (void**)&data, 311 (void**)&data,
298 &data_size)); 312 &data_size));
299 claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name, 313 if (NULL != claim)
300 type, 314 {
301 data, 315 claim->type = type;
302 data_size); 316 claim->data = data;
303 idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle, 317 claim->data_size = data_size;
304 pkey, 318 }
305 claim, 319 else
306 &exp_interval, 320 {
307 &store_attr_cont, 321 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
308 NULL); 322 type,
323 data,
324 data_size);
325 }
326 reclaim_op = GNUNET_RECLAIM_attribute_store (reclaim_handle,
327 pkey,
328 claim,
329 &exp_interval,
330 &store_attr_cont,
331 NULL);
332 GNUNET_free (data);
333 GNUNET_free (claim);
309 return; 334 return;
310 } 335 }
311 GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); 336 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
312} 337}
313 338
314static void 339static void
315iter_cb (void *cls, 340iter_cb (void *cls,
316 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 341 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
317 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 342 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
318{ 343{
319 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 344 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
320 char *attrs_tmp; 345 char *attrs_tmp;
321 char *attr_str; 346 char *attr_str;
347 const char *attr_type;
322 348
323 if (issue_attrs) 349 if ((NULL != attr_name) && (NULL != claim))
350 {
351 if (0 == strcasecmp (attr_name, attr->name))
352 {
353 claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
354 attr->type,
355 attr->data,
356 attr->data_size);
357 }
358 }
359 else if (issue_attrs)
324 { 360 {
325 attrs_tmp = GNUNET_strdup (issue_attrs); 361 attrs_tmp = GNUNET_strdup (issue_attrs);
326 attr_str = strtok (attrs_tmp, ","); 362 attr_str = strtok (attrs_tmp, ",");
327 while (NULL != attr_str) { 363 while (NULL != attr_str) {
328 if (0 != strcmp (attr_str, attr->name)) { 364 if (0 != strcasecmp (attr_str, attr->name)) {
329 attr_str = strtok (NULL, ","); 365 attr_str = strtok (NULL, ",");
330 continue; 366 continue;
331 } 367 }
332 le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); 368 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
333 le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr->name, 369 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name,
334 attr->type, 370 attr->type,
335 attr->data, 371 attr->data,
336 attr->data_size); 372 attr->data_size);
373 le->claim->version = attr->version;
337 GNUNET_CONTAINER_DLL_insert (attr_list->list_head, 374 GNUNET_CONTAINER_DLL_insert (attr_list->list_head,
338 attr_list->list_tail, 375 attr_list->list_tail,
339 le); 376 le);
340 break; 377 break;
341 } 378 }
342 GNUNET_free (attrs_tmp); 379 GNUNET_free (attrs_tmp);
343 } else if (list) { 380 }
344 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 381 else if (list)
345 "%s: %s\n", attr->name, (char*)attr->data); 382 {
383 attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
384 attr->data,
385 attr->data_size);
386 attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
387 fprintf (stdout,
388 "%s: %s [%s,v%u]\n", attr->name, attr_str, attr_type, attr->version);
346 } 389 }
347 GNUNET_IDENTITY_PROVIDER_get_attributes_next (attr_iterator); 390 GNUNET_RECLAIM_get_attributes_next (attr_iterator);
348} 391}
349 392
350static void 393static void
351ego_iter_finished (void *cls) 394start_get_attributes ()
352{ 395{
353 if (NULL == pkey) 396 if (NULL == pkey)
354 { 397 {
355 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 398 fprintf (stderr,
356 "Ego %s not found\n", ego_name); 399 "Ego %s not found\n", ego_name);
400 cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
357 return; 401 return;
358 } 402 }
359 403
@@ -365,24 +409,23 @@ ego_iter_finished (void *cls)
365 GNUNET_STRINGS_string_to_data (consume_ticket, 409 GNUNET_STRINGS_string_to_data (consume_ticket,
366 strlen (consume_ticket), 410 strlen (consume_ticket),
367 &ticket, 411 &ticket,
368 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); 412 sizeof (struct GNUNET_RECLAIM_Ticket));
369 if (NULL != revoke_ticket) 413 if (NULL != revoke_ticket)
370 GNUNET_STRINGS_string_to_data (revoke_ticket, 414 GNUNET_STRINGS_string_to_data (revoke_ticket,
371 strlen (revoke_ticket), 415 strlen (revoke_ticket),
372 &ticket, 416 &ticket,
373 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); 417 sizeof (struct GNUNET_RECLAIM_Ticket));
374
375
376 attr_list = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList);
377 418
378 attr_iterator = GNUNET_IDENTITY_PROVIDER_get_attributes_start (idp_handle, 419 attr_list = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
379 pkey, 420 claim = NULL;
380 &iter_error, 421 attr_iterator = GNUNET_RECLAIM_get_attributes_start (reclaim_handle,
381 NULL, 422 pkey,
382 &iter_cb, 423 &iter_error,
383 NULL, 424 NULL,
384 &iter_finished, 425 &iter_cb,
385 NULL); 426 NULL,
427 &iter_finished,
428 NULL);
386 429
387 430
388} 431}
@@ -398,7 +441,7 @@ ego_cb (void *cls,
398 if (NULL == name) { 441 if (NULL == name) {
399 if (GNUNET_YES == init) { 442 if (GNUNET_YES == init) {
400 init = GNUNET_NO; 443 init = GNUNET_NO;
401 GNUNET_SCHEDULER_add_now (&ego_iter_finished, NULL); 444 start_get_attributes();
402 } 445 }
403 return; 446 return;
404 } 447 }
@@ -418,28 +461,28 @@ run (void *cls,
418 if (NULL == ego_name) 461 if (NULL == ego_name)
419 { 462 {
420 ret = 1; 463 ret = 1;
421 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 464 fprintf (stderr,
422 _("Ego is required\n")); 465 _("Ego is required\n"));
423 return; 466 return;
424 } 467 }
425 468
426 if ( (NULL == attr_value) && (NULL != attr_name) ) 469 if ( (NULL == attr_value) && (NULL != attr_name) )
427 { 470 {
428 ret = 1; 471 ret = 1;
429 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 472 fprintf (stderr,
430 _("Attribute value missing!\n")); 473 _("Attribute value missing!\n"));
431 return; 474 return;
432 } 475 }
433 476
434 if ( (NULL == rp) && (NULL != issue_attrs) ) 477 if ( (NULL == rp) && (NULL != issue_attrs) )
435 { 478 {
436 ret = 1; 479 ret = 1;
437 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 480 fprintf (stderr,
438 _("Requesting party key is required!\n")); 481 _("Requesting party key is required!\n"));
439 return; 482 return;
440 } 483 }
441 484
442 idp_handle = GNUNET_IDENTITY_PROVIDER_connect (c); 485 reclaim_handle = GNUNET_RECLAIM_connect (c);
443 //Get Ego 486 //Get Ego
444 identity_handle = GNUNET_IDENTITY_connect (c, 487 identity_handle = GNUNET_IDENTITY_connect (c,
445 &ego_cb, 488 &ego_cb,
diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/reclaim/gnunet-service-reclaim.c
index c53e72477..3321a79d8 100644
--- a/src/identity-provider/gnunet-service-identity-provider.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -17,8 +17,8 @@
17 */ 17 */
18/** 18/**
19 * @author Martin Schanzenbach 19 * @author Martin Schanzenbach
20 * @file src/identity-provider/gnunet-service-identity-provider.c 20 * @file src/reclaim/gnunet-service-reclaim.c
21 * @brief Identity Token Service 21 * @brief reclaim Service
22 * 22 *
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
@@ -32,10 +32,10 @@
32#include "gnunet_credential_service.h" 32#include "gnunet_credential_service.h"
33#include "gnunet_statistics_service.h" 33#include "gnunet_statistics_service.h"
34#include "gnunet_gns_service.h" 34#include "gnunet_gns_service.h"
35#include "gnunet_identity_provider_plugin.h" 35#include "gnunet_reclaim_plugin.h"
36#include "gnunet_identity_attribute_lib.h" 36#include "gnunet_reclaim_attribute_lib.h"
37#include "gnunet_signatures.h" 37#include "gnunet_signatures.h"
38#include "identity_provider.h" 38#include "reclaim.h"
39 39
40/** 40/**
41 * First pass state 41 * First pass state
@@ -65,7 +65,7 @@ static struct GNUNET_IDENTITY_Handle *identity_handle;
65/** 65/**
66 * Database handle 66 * Database handle
67 */ 67 */
68static struct GNUNET_IDENTITY_PROVIDER_PluginFunctions *TKT_database; 68static struct GNUNET_RECLAIM_PluginFunctions *TKT_database;
69 69
70/** 70/**
71 * Name of DB plugin 71 * Name of DB plugin
@@ -396,7 +396,7 @@ struct AttributeStoreHandle
396 /** 396 /**
397 * The attribute to store 397 * The attribute to store
398 */ 398 */
399 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *claim; 399 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
400 400
401 /** 401 /**
402 * The attribute expiration interval 402 * The attribute expiration interval
@@ -433,7 +433,7 @@ struct ConsumeTicketHandle
433 /** 433 /**
434 * Ticket 434 * Ticket
435 */ 435 */
436 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 436 struct GNUNET_RECLAIM_Ticket ticket;
437 437
438 /** 438 /**
439 * LookupRequest 439 * LookupRequest
@@ -473,7 +473,7 @@ struct ConsumeTicketHandle
473 /** 473 /**
474 * Attributes 474 * Attributes
475 */ 475 */
476 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; 476 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
477 477
478 /** 478 /**
479 * Lookup time 479 * Lookup time
@@ -535,12 +535,12 @@ struct TicketRevocationHandle
535 /** 535 /**
536 * Attributes to reissue 536 * Attributes to reissue
537 */ 537 */
538 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; 538 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
539 539
540 /** 540 /**
541 * Attributes to revoke 541 * Attributes to revoke
542 */ 542 */
543 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *rvk_attrs; 543 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *rvk_attrs;
544 544
545 /** 545 /**
546 * Issuer Key 546 * Issuer Key
@@ -550,7 +550,7 @@ struct TicketRevocationHandle
550 /** 550 /**
551 * Ticket to issue 551 * Ticket to issue
552 */ 552 */
553 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 553 struct GNUNET_RECLAIM_Ticket ticket;
554 554
555 /** 555 /**
556 * QueueEntry 556 * QueueEntry
@@ -603,7 +603,7 @@ struct TicketIssueHandle
603 /** 603 /**
604 * Attributes to issue 604 * Attributes to issue
605 */ 605 */
606 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; 606 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
607 607
608 /** 608 /**
609 * Issuer Key 609 * Issuer Key
@@ -613,7 +613,7 @@ struct TicketIssueHandle
613 /** 613 /**
614 * Ticket to issue 614 * Ticket to issue
615 */ 615 */
616 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 616 struct GNUNET_RECLAIM_Ticket ticket;
617 617
618 /** 618 /**
619 * QueueEntry 619 * QueueEntry
@@ -861,7 +861,7 @@ static void
861cleanup_ticket_issue_handle (struct TicketIssueHandle *handle) 861cleanup_ticket_issue_handle (struct TicketIssueHandle *handle)
862{ 862{
863 if (NULL != handle->attrs) 863 if (NULL != handle->attrs)
864 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs); 864 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (handle->attrs);
865 if (NULL != handle->ns_qe) 865 if (NULL != handle->ns_qe)
866 GNUNET_NAMESTORE_cancel (handle->ns_qe); 866 GNUNET_NAMESTORE_cancel (handle->ns_qe);
867 GNUNET_free (handle); 867 GNUNET_free (handle);
@@ -871,12 +871,12 @@ cleanup_ticket_issue_handle (struct TicketIssueHandle *handle)
871static void 871static void
872send_ticket_result (struct IdpClient *client, 872send_ticket_result (struct IdpClient *client,
873 uint32_t r_id, 873 uint32_t r_id,
874 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 874 const struct GNUNET_RECLAIM_Ticket *ticket,
875 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 875 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
876{ 876{
877 struct TicketResultMessage *irm; 877 struct TicketResultMessage *irm;
878 struct GNUNET_MQ_Envelope *env; 878 struct GNUNET_MQ_Envelope *env;
879 struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket_buf; 879 struct GNUNET_RECLAIM_Ticket *ticket_buf;
880 880
881 /* store ticket in DB */ 881 /* store ticket in DB */
882 if (GNUNET_OK != TKT_database->store_ticket (TKT_database->cls, 882 if (GNUNET_OK != TKT_database->store_ticket (TKT_database->cls,
@@ -889,9 +889,9 @@ send_ticket_result (struct IdpClient *client,
889 } 889 }
890 890
891 env = GNUNET_MQ_msg_extra (irm, 891 env = GNUNET_MQ_msg_extra (irm,
892 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket), 892 sizeof (struct GNUNET_RECLAIM_Ticket),
893 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT); 893 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
894 ticket_buf = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&irm[1]; 894 ticket_buf = (struct GNUNET_RECLAIM_Ticket *)&irm[1];
895 *ticket_buf = *ticket; 895 *ticket_buf = *ticket;
896 irm->id = htonl (r_id); 896 irm->id = htonl (r_id);
897 GNUNET_MQ_send (client->mq, 897 GNUNET_MQ_send (client->mq,
@@ -927,14 +927,14 @@ store_ticket_issue_cont (void *cls,
927 927
928 928
929int 929int
930serialize_abe_keyinfo2 (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 930serialize_abe_keyinfo2 (const struct GNUNET_RECLAIM_Ticket *ticket,
931 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 931 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
932 const struct GNUNET_ABE_AbeKey *rp_key, 932 const struct GNUNET_ABE_AbeKey *rp_key,
933 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey, 933 struct GNUNET_CRYPTO_EcdhePrivateKey **ecdh_privkey,
934 char **result) 934 char **result)
935{ 935{
936 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey; 936 struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pubkey;
937 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 937 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
938 char *enc_keyinfo; 938 char *enc_keyinfo;
939 char *serialized_key; 939 char *serialized_key;
940 char *buf; 940 char *buf;
@@ -1009,7 +1009,7 @@ issue_ticket_after_abe_bootstrap (void *cls,
1009 struct GNUNET_ABE_AbeMasterKey *abe_key) 1009 struct GNUNET_ABE_AbeMasterKey *abe_key)
1010{ 1010{
1011 struct TicketIssueHandle *ih = cls; 1011 struct TicketIssueHandle *ih = cls;
1012 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 1012 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
1013 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; 1013 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
1014 struct GNUNET_GNSRECORD_Data code_record[1]; 1014 struct GNUNET_GNSRECORD_Data code_record[1];
1015 struct GNUNET_ABE_AbeKey *rp_key; 1015 struct GNUNET_ABE_AbeKey *rp_key;
@@ -1101,7 +1101,7 @@ handle_issue_ticket_message (void *cls,
1101 1101
1102 ih = GNUNET_new (struct TicketIssueHandle); 1102 ih = GNUNET_new (struct TicketIssueHandle);
1103 attrs_len = ntohs (im->attr_len); 1103 attrs_len = ntohs (im->attr_len);
1104 ih->attrs = GNUNET_IDENTITY_ATTRIBUTE_list_deserialize ((char*)&im[1], attrs_len); 1104 ih->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char*)&im[1], attrs_len);
1105 ih->r_id = ntohl (im->id); 1105 ih->r_id = ntohl (im->id);
1106 ih->client = idp; 1106 ih->client = idp;
1107 ih->identity = im->identity; 1107 ih->identity = im->identity;
@@ -1132,9 +1132,9 @@ static void
1132cleanup_revoke_ticket_handle (struct TicketRevocationHandle *rh) 1132cleanup_revoke_ticket_handle (struct TicketRevocationHandle *rh)
1133{ 1133{
1134 if (NULL != rh->attrs) 1134 if (NULL != rh->attrs)
1135 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (rh->attrs); 1135 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->attrs);
1136 if (NULL != rh->rvk_attrs) 1136 if (NULL != rh->rvk_attrs)
1137 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (rh->rvk_attrs); 1137 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (rh->rvk_attrs);
1138 if (NULL != rh->abe_key) 1138 if (NULL != rh->abe_key)
1139 GNUNET_ABE_cpabe_delete_master_key (rh->abe_key); 1139 GNUNET_ABE_cpabe_delete_master_key (rh->abe_key);
1140 if (NULL != rh->ns_qe) 1140 if (NULL != rh->ns_qe)
@@ -1157,9 +1157,12 @@ send_revocation_finished (struct TicketRevocationHandle *rh,
1157{ 1157{
1158 struct GNUNET_MQ_Envelope *env; 1158 struct GNUNET_MQ_Envelope *env;
1159 struct RevokeTicketResultMessage *trm; 1159 struct RevokeTicketResultMessage *trm;
1160
1161 GNUNET_break(TKT_database->delete_ticket (TKT_database->cls,
1162 &rh->ticket));
1160 1163
1161 env = GNUNET_MQ_msg (trm, 1164 env = GNUNET_MQ_msg (trm,
1162 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT); 1165 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT);
1163 trm->id = htonl (rh->r_id); 1166 trm->id = htonl (rh->r_id);
1164 trm->success = htonl (success); 1167 trm->success = htonl (success);
1165 GNUNET_MQ_send (rh->client->mq, 1168 GNUNET_MQ_send (rh->client->mq,
@@ -1179,8 +1182,8 @@ send_revocation_finished (struct TicketRevocationHandle *rh,
1179 */ 1182 */
1180static void 1183static void
1181ticket_reissue_proc (void *cls, 1184ticket_reissue_proc (void *cls,
1182 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 1185 const struct GNUNET_RECLAIM_Ticket *ticket,
1183 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs); 1186 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs);
1184 1187
1185static void 1188static void
1186revocation_reissue_tickets (struct TicketRevocationHandle *rh); 1189revocation_reissue_tickets (struct TicketRevocationHandle *rh);
@@ -1206,9 +1209,6 @@ reissue_ticket_cont (void *cls,
1206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", 1209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n",
1207 "Unknown Error\n"); 1210 "Unknown Error\n");
1208 send_revocation_finished (rh, GNUNET_SYSERR); 1211 send_revocation_finished (rh, GNUNET_SYSERR);
1209 GNUNET_CONTAINER_DLL_remove (rh->client->revoke_op_head,
1210 rh->client->revoke_op_tail,
1211 rh);
1212 cleanup_revoke_ticket_handle (rh); 1212 cleanup_revoke_ticket_handle (rh);
1213 return; 1213 return;
1214 } 1214 }
@@ -1226,12 +1226,12 @@ reissue_ticket_cont (void *cls,
1226 */ 1226 */
1227static void 1227static void
1228ticket_reissue_proc (void *cls, 1228ticket_reissue_proc (void *cls,
1229 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 1229 const struct GNUNET_RECLAIM_Ticket *ticket,
1230 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 1230 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
1231{ 1231{
1232 struct TicketRevocationHandle *rh = cls; 1232 struct TicketRevocationHandle *rh = cls;
1233 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 1233 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
1234 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le_rollover; 1234 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le_rollover;
1235 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; 1235 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
1236 struct GNUNET_GNSRECORD_Data code_record[1]; 1236 struct GNUNET_GNSRECORD_Data code_record[1];
1237 struct GNUNET_ABE_AbeKey *rp_key; 1237 struct GNUNET_ABE_AbeKey *rp_key;
@@ -1258,9 +1258,18 @@ ticket_reissue_proc (void *cls,
1258 { 1258 {
1259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1260 "Do not reissue for this identity.!\n"); 1260 "Do not reissue for this identity.!\n");
1261 1261 label = GNUNET_STRINGS_data_to_string_alloc (&rh->ticket.rnd,
1262 rh->offset++; 1262 sizeof (uint64_t));
1263 GNUNET_SCHEDULER_add_now (&reissue_next, rh); 1263 //Delete record
1264 rh->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
1265 &rh->identity,
1266 label,
1267 0,
1268 NULL,
1269 &reissue_ticket_cont,
1270 rh);
1271
1272 GNUNET_free (label);
1264 return; 1273 return;
1265 } 1274 }
1266 1275
@@ -1374,9 +1383,6 @@ revocation_reissue_tickets (struct TicketRevocationHandle *rh)
1374 if (GNUNET_NO == ret) 1383 if (GNUNET_NO == ret)
1375 { 1384 {
1376 send_revocation_finished (rh, GNUNET_OK); 1385 send_revocation_finished (rh, GNUNET_OK);
1377 GNUNET_CONTAINER_DLL_remove (rh->client->revoke_op_head,
1378 rh->client->revoke_op_tail,
1379 rh);
1380 cleanup_revoke_ticket_handle (rh); 1386 cleanup_revoke_ticket_handle (rh);
1381 return; 1387 return;
1382 } 1388 }
@@ -1391,10 +1397,8 @@ check_attr_error (void *cls)
1391 struct TicketRevocationHandle *rh = cls; 1397 struct TicketRevocationHandle *rh = cls;
1392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1398 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1393 "Unable to check for existing attribute\n"); 1399 "Unable to check for existing attribute\n");
1400 rh->ns_qe = NULL;
1394 send_revocation_finished (rh, GNUNET_SYSERR); 1401 send_revocation_finished (rh, GNUNET_SYSERR);
1395 GNUNET_CONTAINER_DLL_remove (rh->client->revoke_op_head,
1396 rh->client->revoke_op_tail,
1397 rh);
1398 cleanup_revoke_ticket_handle (rh); 1402 cleanup_revoke_ticket_handle (rh);
1399} 1403}
1400 1404
@@ -1426,17 +1430,18 @@ check_attr_cb (void *cls,
1426 char* policy; 1430 char* policy;
1427 uint32_t attr_ver; 1431 uint32_t attr_ver;
1428 1432
1433 rh->ns_qe = NULL;
1429 if (1 != rd_count) { 1434 if (1 != rd_count) {
1430 GNUNET_SCHEDULER_add_now (&reenc_next_attribute, 1435 GNUNET_SCHEDULER_add_now (&reenc_next_attribute,
1431 rh); 1436 rh);
1432 return; 1437 return;
1433 } 1438 }
1434 1439
1435 buf_size = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (rh->attrs->list_head->claim); 1440 buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (rh->attrs->list_head->claim);
1436 buf = GNUNET_malloc (buf_size); 1441 buf = GNUNET_malloc (buf_size);
1437 GNUNET_IDENTITY_ATTRIBUTE_serialize (rh->attrs->list_head->claim,
1438 buf);
1439 rh->attrs->list_head->claim->version++; 1442 rh->attrs->list_head->claim->version++;
1443 GNUNET_RECLAIM_ATTRIBUTE_serialize (rh->attrs->list_head->claim,
1444 buf);
1440 GNUNET_asprintf (&policy, "%s_%lu", 1445 GNUNET_asprintf (&policy, "%s_%lu",
1441 rh->attrs->list_head->claim->name, 1446 rh->attrs->list_head->claim->name,
1442 rh->attrs->list_head->claim->version); 1447 rh->attrs->list_head->claim->version);
@@ -1458,9 +1463,6 @@ check_attr_cb (void *cls,
1458 policy); 1463 policy);
1459 GNUNET_free (policy); 1464 GNUNET_free (policy);
1460 send_revocation_finished (rh, GNUNET_SYSERR); 1465 send_revocation_finished (rh, GNUNET_SYSERR);
1461 GNUNET_CONTAINER_DLL_remove (rh->client->revoke_op_head,
1462 rh->client->revoke_op_tail,
1463 rh);
1464 cleanup_revoke_ticket_handle (rh); 1466 cleanup_revoke_ticket_handle (rh);
1465 return; 1467 return;
1466 } 1468 }
@@ -1525,8 +1527,9 @@ attr_reenc_cont (void *cls,
1525 const char *emsg) 1527 const char *emsg)
1526{ 1528{
1527 struct TicketRevocationHandle *rh = cls; 1529 struct TicketRevocationHandle *rh = cls;
1528 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 1530 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
1529 1531
1532 rh->ns_qe = NULL;
1530 if (GNUNET_SYSERR == success) 1533 if (GNUNET_SYSERR == success)
1531 { 1534 {
1532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1535 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1558,12 +1561,12 @@ attr_reenc_cont (void *cls,
1558 1561
1559static void 1562static void
1560process_attributes_to_update (void *cls, 1563process_attributes_to_update (void *cls,
1561 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 1564 const struct GNUNET_RECLAIM_Ticket *ticket,
1562 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 1565 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
1563{ 1566{
1564 struct TicketRevocationHandle *rh = cls; 1567 struct TicketRevocationHandle *rh = cls;
1565 1568
1566 rh->attrs = GNUNET_IDENTITY_ATTRIBUTE_list_dup (attrs); 1569 rh->attrs = GNUNET_RECLAIM_ATTRIBUTE_list_dup (attrs);
1567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1568 "Revocation Phase I: Collecting attributes\n"); 1571 "Revocation Phase I: Collecting attributes\n");
1569 /* Reencrypt all attributes with new key */ 1572 /* Reencrypt all attributes with new key */
@@ -1571,9 +1574,6 @@ process_attributes_to_update (void *cls,
1571 { 1574 {
1572 /* No attributes to reencrypt */ 1575 /* No attributes to reencrypt */
1573 send_revocation_finished (rh, GNUNET_OK); 1576 send_revocation_finished (rh, GNUNET_OK);
1574 GNUNET_CONTAINER_DLL_remove (rh->client->revoke_op_head,
1575 rh->client->revoke_op_tail,
1576 rh);
1577 cleanup_revoke_ticket_handle (rh); 1577 cleanup_revoke_ticket_handle (rh);
1578 return; 1578 return;
1579 } else { 1579 } else {
@@ -1621,11 +1621,11 @@ handle_revoke_ticket_message (void *cls,
1621{ 1621{
1622 struct TicketRevocationHandle *rh; 1622 struct TicketRevocationHandle *rh;
1623 struct IdpClient *idp = cls; 1623 struct IdpClient *idp = cls;
1624 struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket; 1624 struct GNUNET_RECLAIM_Ticket *ticket;
1625 1625
1626 rh = GNUNET_new (struct TicketRevocationHandle); 1626 rh = GNUNET_new (struct TicketRevocationHandle);
1627 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket*)&rm[1]; 1627 ticket = (struct GNUNET_RECLAIM_Ticket*)&rm[1];
1628 rh->rvk_attrs = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); 1628 rh->rvk_attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
1629 rh->ticket = *ticket; 1629 rh->ticket = *ticket;
1630 rh->r_id = ntohl (rm->id); 1630 rh->r_id = ntohl (rm->id);
1631 rh->client = idp; 1631 rh->client = idp;
@@ -1667,7 +1667,7 @@ cleanup_consume_ticket_handle (struct ConsumeTicketHandle *handle)
1667 GNUNET_ABE_cpabe_delete_key (handle->key, 1667 GNUNET_ABE_cpabe_delete_key (handle->key,
1668 GNUNET_YES); 1668 GNUNET_YES);
1669 if (NULL != handle->attrs) 1669 if (NULL != handle->attrs)
1670 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (handle->attrs); 1670 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (handle->attrs);
1671 GNUNET_free (handle); 1671 GNUNET_free (handle);
1672} 1672}
1673 1673
@@ -1698,7 +1698,7 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
1698 struct ConsumeTicketHandle *handle = parallel_lookup->handle; 1698 struct ConsumeTicketHandle *handle = parallel_lookup->handle;
1699 struct ConsumeTicketResultMessage *crm; 1699 struct ConsumeTicketResultMessage *crm;
1700 struct GNUNET_MQ_Envelope *env; 1700 struct GNUNET_MQ_Envelope *env;
1701 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *attr_le; 1701 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le;
1702 struct GNUNET_TIME_Absolute decrypt_duration; 1702 struct GNUNET_TIME_Absolute decrypt_duration;
1703 char *data; 1703 char *data;
1704 char *data_tmp; 1704 char *data_tmp;
@@ -1741,8 +1741,8 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
1741 1, 1741 1,
1742 GNUNET_YES); 1742 GNUNET_YES);
1743 1743
1744 attr_le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); 1744 attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
1745 attr_le->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize (data, 1745 attr_le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (data,
1746 attr_len); 1746 attr_len);
1747 attr_le->claim->version = ntohl(*(uint32_t*)rd->data); 1747 attr_le->claim->version = ntohl(*(uint32_t*)rd->data);
1748 GNUNET_CONTAINER_DLL_insert (handle->attrs->list_head, 1748 GNUNET_CONTAINER_DLL_insert (handle->attrs->list_head,
@@ -1766,15 +1766,15 @@ process_parallel_lookup2 (void *cls, uint32_t rd_count,
1766 } 1766 }
1767 1767
1768 GNUNET_SCHEDULER_cancel (handle->kill_task); 1768 GNUNET_SCHEDULER_cancel (handle->kill_task);
1769 attrs_len = GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (handle->attrs); 1769 attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (handle->attrs);
1770 env = GNUNET_MQ_msg_extra (crm, 1770 env = GNUNET_MQ_msg_extra (crm,
1771 attrs_len, 1771 attrs_len,
1772 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT); 1772 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT);
1773 crm->id = htonl (handle->r_id); 1773 crm->id = htonl (handle->r_id);
1774 crm->attrs_len = htons (attrs_len); 1774 crm->attrs_len = htons (attrs_len);
1775 crm->identity = handle->ticket.identity; 1775 crm->identity = handle->ticket.identity;
1776 data_tmp = (char *) &crm[1]; 1776 data_tmp = (char *) &crm[1];
1777 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (handle->attrs, 1777 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (handle->attrs,
1778 data_tmp); 1778 data_tmp);
1779 GNUNET_MQ_send (handle->client->mq, env); 1779 GNUNET_MQ_send (handle->client->mq, env);
1780 GNUNET_CONTAINER_DLL_remove (handle->client->consume_op_head, 1780 GNUNET_CONTAINER_DLL_remove (handle->client->consume_op_head,
@@ -1805,7 +1805,7 @@ abort_parallel_lookups2 (void *cls)
1805 lu = tmp; 1805 lu = tmp;
1806 } 1806 }
1807 env = GNUNET_MQ_msg (arm, 1807 env = GNUNET_MQ_msg (arm,
1808 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT); 1808 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
1809 arm->id = htonl (handle->r_id); 1809 arm->id = htonl (handle->r_id);
1810 arm->attr_len = htons (0); 1810 arm->attr_len = htons (0);
1811 GNUNET_MQ_send (handle->client->mq, env); 1811 GNUNET_MQ_send (handle->client->mq, env);
@@ -1918,10 +1918,10 @@ handle_consume_ticket_message (void *cls,
1918 ch->r_id = ntohl (cm->id); 1918 ch->r_id = ntohl (cm->id);
1919 ch->client = idp; 1919 ch->client = idp;
1920 ch->identity = cm->identity; 1920 ch->identity = cm->identity;
1921 ch->attrs = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); 1921 ch->attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
1922 GNUNET_CRYPTO_ecdsa_key_get_public (&ch->identity, 1922 GNUNET_CRYPTO_ecdsa_key_get_public (&ch->identity,
1923 &ch->identity_pub); 1923 &ch->identity_pub);
1924 ch->ticket = *((struct GNUNET_IDENTITY_PROVIDER_Ticket*)&cm[1]); 1924 ch->ticket = *((struct GNUNET_RECLAIM_Ticket*)&cm[1]);
1925 rnd_label = GNUNET_STRINGS_data_to_string_alloc (&ch->ticket.rnd, 1925 rnd_label = GNUNET_STRINGS_data_to_string_alloc (&ch->ticket.rnd,
1926 sizeof (uint64_t)); 1926 sizeof (uint64_t));
1927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1967,7 +1967,7 @@ attr_store_cont (void *cls,
1967 struct AttributeStoreHandle *as_handle = cls; 1967 struct AttributeStoreHandle *as_handle = cls;
1968 struct GNUNET_MQ_Envelope *env; 1968 struct GNUNET_MQ_Envelope *env;
1969 struct AttributeStoreResultMessage *acr_msg; 1969 struct AttributeStoreResultMessage *acr_msg;
1970 1970
1971 as_handle->ns_qe = NULL; 1971 as_handle->ns_qe = NULL;
1972 GNUNET_CONTAINER_DLL_remove (as_handle->client->store_op_head, 1972 GNUNET_CONTAINER_DLL_remove (as_handle->client->store_op_head,
1973 as_handle->client->store_op_tail, 1973 as_handle->client->store_op_tail,
@@ -1986,7 +1986,7 @@ attr_store_cont (void *cls,
1986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1987 "Sending ATTRIBUTE_STORE_RESPONSE message\n"); 1987 "Sending ATTRIBUTE_STORE_RESPONSE message\n");
1988 env = GNUNET_MQ_msg (acr_msg, 1988 env = GNUNET_MQ_msg (acr_msg,
1989 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE); 1989 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE_RESPONSE);
1990 acr_msg->id = htonl (as_handle->r_id); 1990 acr_msg->id = htonl (as_handle->r_id);
1991 acr_msg->op_result = htonl (GNUNET_OK); 1991 acr_msg->op_result = htonl (GNUNET_OK);
1992 GNUNET_MQ_send (as_handle->client->mq, 1992 GNUNET_MQ_send (as_handle->client->mq,
@@ -2009,10 +2009,10 @@ attr_store_task (void *cls)
2009 2009
2010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2011 "Storing attribute\n"); 2011 "Storing attribute\n");
2012 buf_size = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (as_handle->claim); 2012 buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (as_handle->claim);
2013 buf = GNUNET_malloc (buf_size); 2013 buf = GNUNET_malloc (buf_size);
2014 2014
2015 GNUNET_IDENTITY_ATTRIBUTE_serialize (as_handle->claim, 2015 GNUNET_RECLAIM_ATTRIBUTE_serialize (as_handle->claim,
2016 buf); 2016 buf);
2017 2017
2018 GNUNET_asprintf (&policy, 2018 GNUNET_asprintf (&policy,
@@ -2111,7 +2111,7 @@ handle_attribute_store_message (void *cls,
2111 data_len = ntohs (sam->attr_len); 2111 data_len = ntohs (sam->attr_len);
2112 2112
2113 as_handle = GNUNET_new (struct AttributeStoreHandle); 2113 as_handle = GNUNET_new (struct AttributeStoreHandle);
2114 as_handle->claim = GNUNET_IDENTITY_ATTRIBUTE_deserialize ((char*)&sam[1], 2114 as_handle->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char*)&sam[1],
2115 data_len); 2115 data_len);
2116 2116
2117 as_handle->r_id = ntohl (sam->id); 2117 as_handle->r_id = ntohl (sam->id);
@@ -2158,7 +2158,7 @@ attr_iter_finished (void *cls)
2158 struct AttributeResultMessage *arm; 2158 struct AttributeResultMessage *arm;
2159 2159
2160 env = GNUNET_MQ_msg (arm, 2160 env = GNUNET_MQ_msg (arm,
2161 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT); 2161 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
2162 arm->id = htonl (ai->request_id); 2162 arm->id = htonl (ai->request_id);
2163 arm->attr_len = htons (0); 2163 arm->attr_len = htons (0);
2164 GNUNET_MQ_send (ai->client->mq, env); 2164 GNUNET_MQ_send (ai->client->mq, env);
@@ -2189,14 +2189,14 @@ attr_iter_cb (void *cls,
2189 if (rd_count != 1) 2189 if (rd_count != 1)
2190 { 2190 {
2191 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 2191 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it,
2192 1); 2192 1);
2193 return; 2193 return;
2194 } 2194 }
2195 2195
2196 if (GNUNET_GNSRECORD_TYPE_ID_ATTR != rd->record_type) 2196 if (GNUNET_GNSRECORD_TYPE_ID_ATTR != rd->record_type)
2197 { 2197 {
2198 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 2198 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it,
2199 1); 2199 1);
2200 return; 2200 return;
2201 } 2201 }
2202 attr_ver = ntohl(*((uint32_t*)rd->data)); 2202 attr_ver = ntohl(*((uint32_t*)rd->data));
@@ -2213,7 +2213,7 @@ attr_iter_cb (void *cls,
2213 if (GNUNET_SYSERR == msg_extra_len) 2213 if (GNUNET_SYSERR == msg_extra_len)
2214 { 2214 {
2215 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 2215 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it,
2216 1); 2216 1);
2217 return; 2217 return;
2218 } 2218 }
2219 2219
@@ -2224,7 +2224,7 @@ attr_iter_cb (void *cls,
2224 "Found attribute: %s\n", label); 2224 "Found attribute: %s\n", label);
2225 env = GNUNET_MQ_msg_extra (arm, 2225 env = GNUNET_MQ_msg_extra (arm,
2226 msg_extra_len, 2226 msg_extra_len,
2227 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT); 2227 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
2228 arm->id = htonl (ai->request_id); 2228 arm->id = htonl (ai->request_id);
2229 arm->attr_len = htons (msg_extra_len); 2229 arm->attr_len = htons (msg_extra_len);
2230 GNUNET_CRYPTO_ecdsa_key_get_public (zone, 2230 GNUNET_CRYPTO_ecdsa_key_get_public (zone,
@@ -2264,7 +2264,7 @@ iterate_next_after_abe_bootstrap (void *cls,
2264 struct AttributeIterator *ai = cls; 2264 struct AttributeIterator *ai = cls;
2265 ai->abe_key = abe_key; 2265 ai->abe_key = abe_key;
2266 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 2266 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it,
2267 1); 2267 1);
2268} 2268}
2269 2269
2270 2270
@@ -2406,8 +2406,8 @@ cleanup_ticket_iter_handle (struct TicketIteration *ti)
2406 */ 2406 */
2407static void 2407static void
2408ticket_iterate_proc (void *cls, 2408ticket_iterate_proc (void *cls,
2409 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 2409 const struct GNUNET_RECLAIM_Ticket *ticket,
2410 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 2410 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
2411{ 2411{
2412 struct TicketIterationProcResult *proc = cls; 2412 struct TicketIterationProcResult *proc = cls;
2413 2413
@@ -2467,7 +2467,7 @@ run_ticket_iteration_round (struct TicketIteration *ti)
2467 } 2467 }
2468 /* send empty response to indicate end of list */ 2468 /* send empty response to indicate end of list */
2469 env = GNUNET_MQ_msg (trm, 2469 env = GNUNET_MQ_msg (trm,
2470 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT); 2470 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
2471 trm->id = htonl (ti->r_id); 2471 trm->id = htonl (ti->r_id);
2472 GNUNET_MQ_send (ti->client->mq, 2472 GNUNET_MQ_send (ti->client->mq,
2473 env); 2473 env);
@@ -2572,7 +2572,7 @@ run (void *cls,
2572 char *database; 2572 char *database;
2573 cfg = c; 2573 cfg = c;
2574 2574
2575 stats = GNUNET_STATISTICS_create ("identity-provider", cfg); 2575 stats = GNUNET_STATISTICS_create ("reclaim", cfg);
2576 2576
2577 //Connect to identity and namestore services 2577 //Connect to identity and namestore services
2578 ns_handle = GNUNET_NAMESTORE_connect (cfg); 2578 ns_handle = GNUNET_NAMESTORE_connect (cfg);
@@ -2597,13 +2597,13 @@ run (void *cls,
2597 /* Loading DB plugin */ 2597 /* Loading DB plugin */
2598 if (GNUNET_OK != 2598 if (GNUNET_OK !=
2599 GNUNET_CONFIGURATION_get_value_string (cfg, 2599 GNUNET_CONFIGURATION_get_value_string (cfg,
2600 "identity-provider", 2600 "reclaim",
2601 "database", 2601 "database",
2602 &database)) 2602 &database))
2603 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2603 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2604 "No database backend configured\n"); 2604 "No database backend configured\n");
2605 GNUNET_asprintf (&db_lib_name, 2605 GNUNET_asprintf (&db_lib_name,
2606 "libgnunet_plugin_identity_provider_%s", 2606 "libgnunet_plugin_reclaim_%s",
2607 database); 2607 database);
2608 TKT_database = GNUNET_PLUGIN_load (db_lib_name, 2608 TKT_database = GNUNET_PLUGIN_load (db_lib_name,
2609 (void *) cfg); 2609 (void *) cfg);
@@ -2619,7 +2619,7 @@ run (void *cls,
2619 2619
2620 if (GNUNET_OK == 2620 if (GNUNET_OK ==
2621 GNUNET_CONFIGURATION_get_value_time (cfg, 2621 GNUNET_CONFIGURATION_get_value_time (cfg,
2622 "identity-provider", 2622 "reclaim",
2623 "TOKEN_EXPIRATION_INTERVAL", 2623 "TOKEN_EXPIRATION_INTERVAL",
2624 &token_expiration_interval)) 2624 &token_expiration_interval))
2625 { 2625 {
@@ -2736,51 +2736,51 @@ client_connect_cb (void *cls,
2736 * Define "main" method using service macro. 2736 * Define "main" method using service macro.
2737 */ 2737 */
2738GNUNET_SERVICE_MAIN 2738GNUNET_SERVICE_MAIN
2739("identity-provider", 2739("reclaim",
2740 GNUNET_SERVICE_OPTION_NONE, 2740 GNUNET_SERVICE_OPTION_NONE,
2741 &run, 2741 &run,
2742 &client_connect_cb, 2742 &client_connect_cb,
2743 &client_disconnect_cb, 2743 &client_disconnect_cb,
2744 NULL, 2744 NULL,
2745 GNUNET_MQ_hd_var_size (attribute_store_message, 2745 GNUNET_MQ_hd_var_size (attribute_store_message,
2746 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE, 2746 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE,
2747 struct AttributeStoreMessage, 2747 struct AttributeStoreMessage,
2748 NULL), 2748 NULL),
2749 GNUNET_MQ_hd_fixed_size (iteration_start, 2749 GNUNET_MQ_hd_fixed_size (iteration_start,
2750 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_START, 2750 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START,
2751 struct AttributeIterationStartMessage, 2751 struct AttributeIterationStartMessage,
2752 NULL), 2752 NULL),
2753 GNUNET_MQ_hd_fixed_size (iteration_next, 2753 GNUNET_MQ_hd_fixed_size (iteration_next,
2754 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_NEXT, 2754 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT,
2755 struct AttributeIterationNextMessage, 2755 struct AttributeIterationNextMessage,
2756 NULL), 2756 NULL),
2757 GNUNET_MQ_hd_fixed_size (iteration_stop, 2757 GNUNET_MQ_hd_fixed_size (iteration_stop,
2758 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_STOP, 2758 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP,
2759 struct AttributeIterationStopMessage, 2759 struct AttributeIterationStopMessage,
2760 NULL), 2760 NULL),
2761 GNUNET_MQ_hd_var_size (issue_ticket_message, 2761 GNUNET_MQ_hd_var_size (issue_ticket_message,
2762 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET, 2762 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET,
2763 struct IssueTicketMessage, 2763 struct IssueTicketMessage,
2764 NULL), 2764 NULL),
2765 GNUNET_MQ_hd_var_size (consume_ticket_message, 2765 GNUNET_MQ_hd_var_size (consume_ticket_message,
2766 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET, 2766 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET,
2767 struct ConsumeTicketMessage, 2767 struct ConsumeTicketMessage,
2768 NULL), 2768 NULL),
2769 GNUNET_MQ_hd_fixed_size (ticket_iteration_start, 2769 GNUNET_MQ_hd_fixed_size (ticket_iteration_start,
2770 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START, 2770 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START,
2771 struct TicketIterationStartMessage, 2771 struct TicketIterationStartMessage,
2772 NULL), 2772 NULL),
2773 GNUNET_MQ_hd_fixed_size (ticket_iteration_next, 2773 GNUNET_MQ_hd_fixed_size (ticket_iteration_next,
2774 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT, 2774 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT,
2775 struct TicketIterationNextMessage, 2775 struct TicketIterationNextMessage,
2776 NULL), 2776 NULL),
2777 GNUNET_MQ_hd_fixed_size (ticket_iteration_stop, 2777 GNUNET_MQ_hd_fixed_size (ticket_iteration_stop,
2778 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP, 2778 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP,
2779 struct TicketIterationStopMessage, 2779 struct TicketIterationStopMessage,
2780 NULL), 2780 NULL),
2781 GNUNET_MQ_hd_var_size (revoke_ticket_message, 2781 GNUNET_MQ_hd_var_size (revoke_ticket_message,
2782 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET, 2782 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET,
2783 struct RevokeTicketMessage, 2783 struct RevokeTicketMessage,
2784 NULL), 2784 NULL),
2785 GNUNET_MQ_handler_end()); 2785 GNUNET_MQ_handler_end());
2786/* end of gnunet-service-identity-provider.c */ 2786/* end of gnunet-service-reclaim.c */
diff --git a/src/reclaim/jwt.c b/src/reclaim/jwt.c
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/src/reclaim/jwt.c
@@ -0,0 +1 @@
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c
new file mode 100644
index 000000000..1e9e64fec
--- /dev/null
+++ b/src/reclaim/oidc_helper.c
@@ -0,0 +1,440 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17 */
18
19/**
20 * @file reclaim/oidc_helper.c
21 * @brief helper library for OIDC related functions
22 * @author Martin Schanzenbach
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_signatures.h"
27#include "gnunet_reclaim_service.h"
28#include "gnunet_reclaim_attribute_lib.h"
29#include <jansson.h>
30#include <inttypes.h>
31#include "oidc_helper.h"
32
33static char*
34create_jwt_header(void)
35{
36 json_t *root;
37 char *json_str;
38
39 root = json_object ();
40 json_object_set_new (root, JWT_ALG, json_string (JWT_ALG_VALUE));
41 json_object_set_new (root, JWT_TYP, json_string (JWT_TYP_VALUE));
42
43 json_str = json_dumps (root, JSON_INDENT(0) | JSON_COMPACT);
44 json_decref (root);
45 return json_str;
46}
47
48static void
49replace_char(char* str, char find, char replace){
50 char *current_pos = strchr(str,find);
51 while (current_pos){
52 *current_pos = replace;
53 current_pos = strchr(current_pos,find);
54 }
55}
56
57//RFC4648
58static void
59fix_base64(char* str) {
60 char *padding;
61 //First, remove trailing padding '='
62 padding = strtok(str, "=");
63 while (NULL != padding)
64 padding = strtok(NULL, "=");
65
66 //Replace + with -
67 replace_char (str, '+', '-');
68
69 //Replace / with _
70 replace_char (str, '/', '_');
71
72}
73
74/**
75 * Create a JWT from attributes
76 *
77 * @param aud_key the public of the audience
78 * @param sub_key the public key of the subject
79 * @param attrs the attribute list
80 * @param expiration_time the validity of the token
81 * @param secret_key the key used to sign the JWT
82 * @return a new base64-encoded JWT string.
83 */
84char*
85OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
86 const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
87 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
88 const struct GNUNET_TIME_Relative *expiration_time,
89 const char *nonce,
90 const char *secret_key)
91{
92 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
93 struct GNUNET_HashCode signature;
94 struct GNUNET_TIME_Absolute exp_time;
95 struct GNUNET_TIME_Absolute time_now;
96 char* audience;
97 char* subject;
98 char* header;
99 char* body_str;
100 char* result;
101 char* header_base64;
102 char* body_base64;
103 char* signature_target;
104 char* signature_base64;
105 char* attr_val_str;
106 json_t* body;
107
108 //iat REQUIRED time now
109 time_now = GNUNET_TIME_absolute_get();
110 //exp REQUIRED time expired from config
111 exp_time = GNUNET_TIME_absolute_add (time_now, *expiration_time);
112 //auth_time only if max_age
113 //nonce only if nonce
114 // OPTIONAL acr,amr,azp
115 subject = GNUNET_STRINGS_data_to_string_alloc (sub_key,
116 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
117 audience = GNUNET_STRINGS_data_to_string_alloc (aud_key,
118 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
119 header = create_jwt_header ();
120 body = json_object ();
121
122 //iss REQUIRED case sensitive server uri with https
123 //The issuer is the local reclaim instance (e.g. https://reclaim.id/api/openid)
124 json_object_set_new (body,
125 "iss", json_string (SERVER_ADDRESS));
126 //sub REQUIRED public key identity, not exceed 255 ASCII length
127 json_object_set_new (body,
128 "sub", json_string (subject));
129 //aud REQUIRED public key client_id must be there
130 json_object_set_new (body,
131 "aud", json_string (audience));
132 //iat
133 json_object_set_new (body,
134 "iat", json_integer (time_now.abs_value_us / (1000*1000)));
135 //exp
136 json_object_set_new (body,
137 "exp", json_integer (exp_time.abs_value_us / (1000*1000)));
138 //nbf
139 json_object_set_new (body,
140 "nbf", json_integer (time_now.abs_value_us / (1000*1000)));
141 //nonce
142 if (NULL != nonce)
143 json_object_set_new (body,
144 "nonce", json_string (nonce));
145
146 for (le = attrs->list_head; NULL != le; le = le->next)
147 {
148 attr_val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (le->claim->type,
149 le->claim->data,
150 le->claim->data_size);
151 json_object_set_new (body,
152 le->claim->name,
153 json_string (attr_val_str));
154 GNUNET_free (attr_val_str);
155 }
156 body_str = json_dumps (body, JSON_INDENT(0) | JSON_COMPACT);
157 json_decref (body);
158
159 GNUNET_STRINGS_base64_encode (header,
160 strlen (header),
161 &header_base64);
162 fix_base64(header_base64);
163
164 GNUNET_STRINGS_base64_encode (body_str,
165 strlen (body_str),
166 &body_base64);
167 fix_base64(body_base64);
168
169 GNUNET_free (subject);
170 GNUNET_free (audience);
171
172 /**
173 * Creating the JWT signature. This might not be
174 * standards compliant, check.
175 */
176 GNUNET_asprintf (&signature_target, "%s.%s", header_base64, body_base64);
177 GNUNET_CRYPTO_hmac_raw (secret_key, strlen (secret_key), signature_target, strlen (signature_target), &signature);
178 GNUNET_STRINGS_base64_encode ((const char*)&signature,
179 sizeof (struct GNUNET_HashCode),
180 &signature_base64);
181 fix_base64(signature_base64);
182
183 GNUNET_asprintf (&result, "%s.%s.%s",
184 header_base64, body_base64, signature_base64);
185
186 GNUNET_free (signature_target);
187 GNUNET_free (header);
188 GNUNET_free (body_str);
189 GNUNET_free (signature_base64);
190 GNUNET_free (body_base64);
191 GNUNET_free (header_base64);
192 return result;
193}
194/**
195 * Builds an OIDC authorization code including
196 * a reclaim ticket and nonce
197 *
198 * @param issuer the issuer of the ticket, used to sign the ticket and nonce
199 * @param ticket the ticket to include in the code
200 * @param nonce the nonce to include in the code
201 * @return a new authorization code (caller must free)
202 */
203char*
204OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
205 const struct GNUNET_RECLAIM_Ticket *ticket,
206 const char* nonce)
207{
208 char *ticket_str;
209 json_t *code_json;
210 char *signature_payload;
211 char *signature_str;
212 char *authz_code;
213 size_t signature_payload_len;
214 struct GNUNET_CRYPTO_EcdsaSignature signature;
215 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
216
217 signature_payload_len = sizeof (struct GNUNET_RECLAIM_Ticket);
218 if (NULL != nonce)
219 signature_payload_len += strlen (nonce);
220
221 signature_payload = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + signature_payload_len);
222 purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose *)signature_payload;
223 purpose->size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + signature_payload_len);
224 purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN);
225 memcpy (&purpose[1],
226 ticket,
227 sizeof (struct GNUNET_RECLAIM_Ticket));
228 if (NULL != nonce)
229 memcpy (((char*)&purpose[1]) + sizeof (struct GNUNET_RECLAIM_Ticket),
230 nonce,
231 strlen (nonce));
232 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (issuer,
233 purpose,
234 &signature))
235 {
236 GNUNET_free (signature_payload);
237 return NULL;
238 }
239 signature_str = GNUNET_STRINGS_data_to_string_alloc (&signature,
240 sizeof (signature));
241 ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
242 sizeof (struct GNUNET_RECLAIM_Ticket));
243
244 code_json = json_object ();
245 json_object_set_new (code_json,
246 "ticket",
247 json_string (ticket_str));
248 if (NULL != nonce)
249 json_object_set_new (code_json,
250 "nonce",
251 json_string (nonce));
252 json_object_set_new (code_json,
253 "signature",
254 json_string (signature_str));
255 authz_code = json_dumps (code_json,
256 JSON_INDENT(0) | JSON_COMPACT);
257 GNUNET_free (signature_payload);
258 GNUNET_free (signature_str);
259 GNUNET_free (ticket_str);
260 json_decref (code_json);
261 return authz_code;
262}
263
264
265
266
267/**
268 * Parse reclaim ticket and nonce from
269 * authorization code.
270 * This also verifies the signature in the code.
271 *
272 * @param audience the expected audience of the code
273 * @param code the string representation of the code
274 * @param ticket where to store the ticket
275 * @param nonce where to store the nonce
276 * @return GNUNET_OK if successful, else GNUNET_SYSERR
277 */
278int
279OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
280 const char* code,
281 struct GNUNET_RECLAIM_Ticket **ticket,
282 char **nonce)
283{
284 json_error_t error;
285 json_t *code_json;
286 json_t *ticket_json;
287 json_t *nonce_json;
288 json_t *signature_json;
289 const char *ticket_str;
290 const char *signature_str;
291 const char *nonce_str;
292 char *code_output;
293 struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
294 struct GNUNET_CRYPTO_EcdsaSignature signature;
295 size_t signature_payload_len;
296
297 code_output = NULL;
298 GNUNET_STRINGS_base64_decode (code,
299 strlen(code),
300 (void**)&code_output);
301 code_json = json_loads (code_output, 0 , &error);
302 GNUNET_free (code_output);
303 ticket_json = json_object_get (code_json, "ticket");
304 nonce_json = json_object_get (code_json, "nonce");
305 signature_json = json_object_get (code_json, "signature");
306 *ticket = NULL;
307 *nonce = NULL;
308
309 if ((NULL == ticket_json || !json_is_string (ticket_json)) ||
310 (NULL == signature_json || !json_is_string (signature_json)))
311 {
312 json_decref (code_json);
313 return GNUNET_SYSERR;
314 }
315 ticket_str = json_string_value (ticket_json);
316 signature_str = json_string_value (signature_json);
317 nonce_str = NULL;
318 if (NULL != nonce_json)
319 nonce_str = json_string_value (nonce_json);
320 signature_payload_len = sizeof (struct GNUNET_RECLAIM_Ticket);
321 if (NULL != nonce_str)
322 signature_payload_len += strlen (nonce_str);
323 purpose = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
324 signature_payload_len);
325 purpose->size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + signature_payload_len);
326 purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN);
327 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (ticket_str,
328 strlen (ticket_str),
329 &purpose[1],
330 sizeof (struct GNUNET_RECLAIM_Ticket)))
331 {
332 GNUNET_free (purpose);
333 json_decref (code_json);
334 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
335 "Cannot parse ticket!\n");
336 return GNUNET_SYSERR;
337 }
338 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (signature_str,
339 strlen (signature_str),
340 &signature,
341 sizeof (struct GNUNET_CRYPTO_EcdsaSignature)))
342 {
343 GNUNET_free (purpose);
344 json_decref (code_json);
345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
346 "Cannot parse signature!\n");
347 return GNUNET_SYSERR;
348 }
349 *ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
350 memcpy (*ticket,
351 &purpose[1],
352 sizeof (struct GNUNET_RECLAIM_Ticket));
353 if (0 != memcmp (audience,
354 &(*ticket)->audience,
355 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
356 {
357 GNUNET_free (purpose);
358 GNUNET_free (*ticket);
359 json_decref (code_json);
360 *ticket = NULL;
361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
362 "Audience in ticket does not match client!\n");
363 return GNUNET_SYSERR;
364
365 }
366 if (NULL != nonce_str)
367 memcpy (((char*)&purpose[1]) + sizeof (struct GNUNET_RECLAIM_Ticket),
368 nonce_str,
369 strlen (nonce_str));
370 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN,
371 purpose,
372 &signature,
373 &(*ticket)->identity))
374 {
375 GNUNET_free (purpose);
376 GNUNET_free (*ticket);
377 json_decref (code_json);
378 *ticket = NULL;
379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
380 "Signature of authZ code invalid!\n");
381 return GNUNET_SYSERR;
382 }
383 *nonce = GNUNET_strdup (nonce_str);
384 return GNUNET_OK;
385}
386
387/**
388 * Build a token response for a token request
389 * TODO: Maybe we should add the scope here?
390 *
391 * @param access_token the access token to include
392 * @param id_token the id_token to include
393 * @param expiration_time the expiration time of the token(s)
394 * @param token_response where to store the response
395 */
396void
397OIDC_build_token_response (const char *access_token,
398 const char *id_token,
399 const struct GNUNET_TIME_Relative *expiration_time,
400 char **token_response)
401{
402 json_t *root_json;
403
404 root_json = json_object ();
405
406 GNUNET_assert (NULL != access_token);
407 GNUNET_assert (NULL != id_token);
408 GNUNET_assert (NULL != expiration_time);
409 json_object_set_new (root_json,
410 "access_token",
411 json_string (access_token));
412 json_object_set_new (root_json,
413 "token_type",
414 json_string ("Bearer"));
415 json_object_set_new (root_json,
416 "expires_in",
417 json_integer (expiration_time->rel_value_us / (1000 * 1000)));
418 json_object_set_new (root_json,
419 "id_token",
420 json_string (id_token));
421 *token_response = json_dumps (root_json,
422 JSON_INDENT(0) | JSON_COMPACT);
423 json_decref (root_json);
424}
425
426/**
427 * Generate a new access token
428 */
429char*
430OIDC_access_token_new ()
431{
432 char* access_token_number;
433 char* access_token;
434 uint64_t random_number;
435
436 random_number = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
437 GNUNET_asprintf (&access_token_number, "%" PRIu64, random_number);
438 GNUNET_STRINGS_base64_encode(access_token_number,strlen(access_token_number),&access_token);
439 return access_token;
440}
diff --git a/src/reclaim/oidc_helper.h b/src/reclaim/oidc_helper.h
new file mode 100644
index 000000000..7a0f45bf9
--- /dev/null
+++ b/src/reclaim/oidc_helper.h
@@ -0,0 +1,109 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17 */
18
19/**
20 * @file reclaim/oidc_helper.h
21 * @brief helper library for OIDC related functions
22 * @author Martin Schanzenbach
23 */
24
25#ifndef JWT_H
26#define JWT_H
27
28#define JWT_ALG "alg"
29
30/* Use 512bit HMAC */
31#define JWT_ALG_VALUE "HS512"
32
33#define JWT_TYP "typ"
34
35#define JWT_TYP_VALUE "jwt"
36
37#define SERVER_ADDRESS "https://reclaim.id"
38
39/**
40 * Create a JWT from attributes
41 *
42 * @param aud_key the public of the audience
43 * @param sub_key the public key of the subject
44 * @param attrs the attribute list
45 * @param expiration_time the validity of the token
46 * @param secret_key the key used to sign the JWT
47 * @return a new base64-encoded JWT string.
48 */
49char*
50OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
51 const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
52 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
53 const struct GNUNET_TIME_Relative *expiration_time,
54 const char *nonce,
55 const char *secret_key);
56
57/**
58 * Builds an OIDC authorization code including
59 * a reclaim ticket and nonce
60 *
61 * @param issuer the issuer of the ticket, used to sign the ticket and nonce
62 * @param ticket the ticket to include in the code
63 * @param nonce the nonce to include in the code
64 * @return a new authorization code (caller must free)
65 */
66char*
67OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
68 const struct GNUNET_RECLAIM_Ticket *ticket,
69 const char* nonce);
70
71/**
72 * Parse reclaim ticket and nonce from
73 * authorization code.
74 * This also verifies the signature in the code.
75 *
76 * @param audience the expected audience of the code
77 * @param code the string representation of the code
78 * @param ticket where to store the ticket
79 * @param nonce where to store the nonce
80 * @return GNUNET_OK if successful, else GNUNET_SYSERR
81 */
82int
83OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
84 const char* code,
85 struct GNUNET_RECLAIM_Ticket **ticket,
86 char **nonce);
87
88/**
89 * Build a token response for a token request
90 * TODO: Maybe we should add the scope here?
91 *
92 * @param access_token the access token to include
93 * @param id_token the id_token to include
94 * @param expiration_time the expiration time of the token(s)
95 * @param token_response where to store the response
96 */
97void
98OIDC_build_token_response (const char *access_token,
99 const char *id_token,
100 const struct GNUNET_TIME_Relative *expiration_time,
101 char **token_response);
102/**
103 * Generate a new access token
104 */
105char*
106OIDC_access_token_new ();
107
108
109#endif
diff --git a/src/identity-provider/plugin_gnsrecord_identity_provider.c b/src/reclaim/plugin_gnsrecord_reclaim.c
index f0dc563dc..781b88abc 100644
--- a/src/identity-provider/plugin_gnsrecord_identity_provider.c
+++ b/src/reclaim/plugin_gnsrecord_reclaim.c
@@ -17,7 +17,7 @@
17*/ 17*/
18 18
19/** 19/**
20 * @file identity-provider/plugin_gnsrecord_identity_provider.c 20 * @file reclaim/plugin_gnsrecord_reclaim.c
21 * @brief gnsrecord plugin to provide the API for identity records 21 * @brief gnsrecord plugin to provide the API for identity records
22 * @author Martin Schanzenbach 22 * @author Martin Schanzenbach
23 */ 23 */
@@ -54,6 +54,8 @@ value_to_string (void *cls,
54 case GNUNET_GNSRECORD_TYPE_ID_ATTR: 54 case GNUNET_GNSRECORD_TYPE_ID_ATTR:
55 return GNUNET_STRINGS_data_to_string_alloc (data, data_size); 55 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
56 case GNUNET_GNSRECORD_TYPE_ID_TOKEN: //DEPRECATED 56 case GNUNET_GNSRECORD_TYPE_ID_TOKEN: //DEPRECATED
57 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT:
58 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT:
57 return GNUNET_strndup (data, data_size); 59 return GNUNET_strndup (data, data_size);
58 case GNUNET_GNSRECORD_TYPE_ABE_KEY: 60 case GNUNET_GNSRECORD_TYPE_ABE_KEY:
59 case GNUNET_GNSRECORD_TYPE_ABE_MASTER: 61 case GNUNET_GNSRECORD_TYPE_ABE_MASTER:
@@ -113,6 +115,8 @@ string_to_value (void *cls,
113 *data, 115 *data,
114 *data_size); 116 *data_size);
115 case GNUNET_GNSRECORD_TYPE_ID_TOKEN: 117 case GNUNET_GNSRECORD_TYPE_ID_TOKEN:
118 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT:
119 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT:
116 *data = GNUNET_strdup (s); 120 *data = GNUNET_strdup (s);
117 *data_size = strlen (s); 121 *data_size = strlen (s);
118 return GNUNET_OK; 122 return GNUNET_OK;
@@ -181,6 +185,8 @@ static struct {
181 { "ABE_KEY", GNUNET_GNSRECORD_TYPE_ABE_KEY }, 185 { "ABE_KEY", GNUNET_GNSRECORD_TYPE_ABE_KEY },
182 { "ABE_MASTER", GNUNET_GNSRECORD_TYPE_ABE_MASTER }, 186 { "ABE_MASTER", GNUNET_GNSRECORD_TYPE_ABE_MASTER },
183 { "ID_TOKEN_METADATA", GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA }, 187 { "ID_TOKEN_METADATA", GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA },
188 { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT },
189 { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT },
184 { NULL, UINT32_MAX } 190 { NULL, UINT32_MAX }
185}; 191};
186 192
@@ -234,7 +240,7 @@ number_to_typename (void *cls,
234 * @return the exported block API 240 * @return the exported block API
235 */ 241 */
236void * 242void *
237libgnunet_plugin_gnsrecord_identity_provider_init (void *cls) 243libgnunet_plugin_gnsrecord_reclaim_init (void *cls)
238{ 244{
239 struct GNUNET_GNSRECORD_PluginFunctions *api; 245 struct GNUNET_GNSRECORD_PluginFunctions *api;
240 246
@@ -254,7 +260,7 @@ libgnunet_plugin_gnsrecord_identity_provider_init (void *cls)
254 * @return NULL 260 * @return NULL
255 */ 261 */
256void * 262void *
257libgnunet_plugin_gnsrecord_identity_provider_done (void *cls) 263libgnunet_plugin_gnsrecord_reclaim_done (void *cls)
258{ 264{
259 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 265 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
260 266
diff --git a/src/identity-provider/plugin_identity_provider_sqlite.c b/src/reclaim/plugin_reclaim_sqlite.c
index f2a8b7b54..b545a94e8 100644
--- a/src/identity-provider/plugin_identity_provider_sqlite.c
+++ b/src/reclaim/plugin_reclaim_sqlite.c
@@ -17,15 +17,15 @@
17 */ 17 */
18 18
19/** 19/**
20 * @file identity-provider/plugin_identity_provider_sqlite.c 20 * @file reclaim/plugin_reclaim_sqlite.c
21 * @brief sqlite-based idp backend 21 * @brief sqlite-based idp backend
22 * @author Martin Schanzenbach 22 * @author Martin Schanzenbach
23 */ 23 */
24 24
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_identity_provider_service.h" 26#include "gnunet_reclaim_service.h"
27#include "gnunet_identity_provider_plugin.h" 27#include "gnunet_reclaim_plugin.h"
28#include "gnunet_identity_attribute_lib.h" 28#include "gnunet_reclaim_attribute_lib.h"
29#include "gnunet_sq_lib.h" 29#include "gnunet_sq_lib.h"
30#include <sqlite3.h> 30#include <sqlite3.h>
31 31
@@ -47,9 +47,9 @@
47 * a failure of the command 'cmd' on file 'filename' 47 * a failure of the command 'cmd' on file 'filename'
48 * with the message given by strerror(errno). 48 * with the message given by strerror(errno).
49 */ 49 */
50#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "identity-provider", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0) 50#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "reclaim", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
51 51
52#define LOG(kind,...) GNUNET_log_from (kind, "identity-provider-sqlite", __VA_ARGS__) 52#define LOG(kind,...) GNUNET_log_from (kind, "reclaim-sqlite", __VA_ARGS__)
53 53
54 54
55/** 55/**
@@ -180,12 +180,12 @@ database_setup (struct Plugin *plugin)
180 180
181 if (GNUNET_OK != 181 if (GNUNET_OK !=
182 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, 182 GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
183 "identity-provider-sqlite", 183 "reclaim-sqlite",
184 "FILENAME", 184 "FILENAME",
185 &afsdir)) 185 &afsdir))
186 { 186 {
187 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 187 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
188 "identity-provider-sqlite", 188 "reclaim-sqlite",
189 "FILENAME"); 189 "FILENAME");
190 return GNUNET_SYSERR; 190 return GNUNET_SYSERR;
191 } 191 }
@@ -370,9 +370,9 @@ database_shutdown (struct Plugin *plugin)
370 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 370 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
371 */ 371 */
372static int 372static int
373identity_provider_sqlite_store_ticket (void *cls, 373reclaim_sqlite_store_ticket (void *cls,
374 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 374 const struct GNUNET_RECLAIM_Ticket *ticket,
375 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) 375 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
376{ 376{
377 struct Plugin *plugin = cls; 377 struct Plugin *plugin = cls;
378 size_t attrs_len; 378 size_t attrs_len;
@@ -401,9 +401,9 @@ identity_provider_sqlite_store_ticket (void *cls,
401 GNUNET_SQ_reset (plugin->dbh, 401 GNUNET_SQ_reset (plugin->dbh,
402 plugin->delete_ticket); 402 plugin->delete_ticket);
403 403
404 attrs_len = GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (attrs); 404 attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
405 attrs_ser = GNUNET_malloc (attrs_len); 405 attrs_ser = GNUNET_malloc (attrs_len);
406 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (attrs, 406 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs,
407 attrs_ser); 407 attrs_ser);
408 struct GNUNET_SQ_QueryParam sparams[] = { 408 struct GNUNET_SQ_QueryParam sparams[] = {
409 GNUNET_SQ_query_param_auto_from_type (&ticket->identity), 409 GNUNET_SQ_query_param_auto_from_type (&ticket->identity),
@@ -458,8 +458,8 @@ identity_provider_sqlite_store_ticket (void *cls,
458 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 458 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
459 */ 459 */
460static int 460static int
461identity_provider_sqlite_delete_ticket (void *cls, 461reclaim_sqlite_delete_ticket (void *cls,
462 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket) 462 const struct GNUNET_RECLAIM_Ticket *ticket)
463{ 463{
464 struct Plugin *plugin = cls; 464 struct Plugin *plugin = cls;
465 int n; 465 int n;
@@ -521,11 +521,11 @@ identity_provider_sqlite_delete_ticket (void *cls,
521static int 521static int
522get_ticket_and_call_iterator (struct Plugin *plugin, 522get_ticket_and_call_iterator (struct Plugin *plugin,
523 sqlite3_stmt *stmt, 523 sqlite3_stmt *stmt,
524 GNUNET_IDENTITY_PROVIDER_TicketIterator iter, 524 GNUNET_RECLAIM_TicketIterator iter,
525 void *iter_cls) 525 void *iter_cls)
526{ 526{
527 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 527 struct GNUNET_RECLAIM_Ticket ticket;
528 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; 528 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
529 int ret; 529 int ret;
530 int sret; 530 int sret;
531 size_t attrs_len; 531 size_t attrs_len;
@@ -552,13 +552,13 @@ get_ticket_and_call_iterator (struct Plugin *plugin,
552 } 552 }
553 else 553 else
554 { 554 {
555 attrs = GNUNET_IDENTITY_ATTRIBUTE_list_deserialize (attrs_ser, 555 attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (attrs_ser,
556 attrs_len); 556 attrs_len);
557 if (NULL != iter) 557 if (NULL != iter)
558 iter (iter_cls, 558 iter (iter_cls,
559 &ticket, 559 &ticket,
560 attrs); 560 attrs);
561 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (attrs); 561 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs);
562 ret = GNUNET_YES; 562 ret = GNUNET_YES;
563 } 563 }
564 GNUNET_SQ_cleanup_result (rs); 564 GNUNET_SQ_cleanup_result (rs);
@@ -586,9 +586,9 @@ get_ticket_and_call_iterator (struct Plugin *plugin,
586 * @return #GNUNET_OK on success, else #GNUNET_SYSERR 586 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
587 */ 587 */
588static int 588static int
589identity_provider_sqlite_ticket_get_attrs (void *cls, 589reclaim_sqlite_ticket_get_attrs (void *cls,
590 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 590 const struct GNUNET_RECLAIM_Ticket *ticket,
591 GNUNET_IDENTITY_PROVIDER_TicketIterator iter, 591 GNUNET_RECLAIM_TicketIterator iter,
592 void *iter_cls) 592 void *iter_cls)
593{ 593{
594 struct Plugin *plugin = cls; 594 struct Plugin *plugin = cls;
@@ -628,11 +628,11 @@ identity_provider_sqlite_ticket_get_attrs (void *cls,
628 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error 628 * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error
629 */ 629 */
630static int 630static int
631identity_provider_sqlite_iterate_tickets (void *cls, 631reclaim_sqlite_iterate_tickets (void *cls,
632 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 632 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
633 int audience, 633 int audience,
634 uint64_t offset, 634 uint64_t offset,
635 GNUNET_IDENTITY_PROVIDER_TicketIterator iter, 635 GNUNET_RECLAIM_TicketIterator iter,
636 void *iter_cls) 636 void *iter_cls)
637{ 637{
638 struct Plugin *plugin = cls; 638 struct Plugin *plugin = cls;
@@ -680,15 +680,15 @@ identity_provider_sqlite_iterate_tickets (void *cls,
680/** 680/**
681 * Entry point for the plugin. 681 * Entry point for the plugin.
682 * 682 *
683 * @param cls the "struct GNUNET_IDENTITY_PROVIDER_PluginEnvironment*" 683 * @param cls the "struct GNUNET_RECLAIM_PluginEnvironment*"
684 * @return NULL on error, otherwise the plugin context 684 * @return NULL on error, otherwise the plugin context
685 */ 685 */
686void * 686void *
687libgnunet_plugin_identity_provider_sqlite_init (void *cls) 687libgnunet_plugin_reclaim_sqlite_init (void *cls)
688{ 688{
689 static struct Plugin plugin; 689 static struct Plugin plugin;
690 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 690 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
691 struct GNUNET_IDENTITY_PROVIDER_PluginFunctions *api; 691 struct GNUNET_RECLAIM_PluginFunctions *api;
692 692
693 if (NULL != plugin.cfg) 693 if (NULL != plugin.cfg)
694 return NULL; /* can only initialize once! */ 694 return NULL; /* can only initialize once! */
@@ -699,12 +699,12 @@ libgnunet_plugin_identity_provider_sqlite_init (void *cls)
699 database_shutdown (&plugin); 699 database_shutdown (&plugin);
700 return NULL; 700 return NULL;
701 } 701 }
702 api = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_PluginFunctions); 702 api = GNUNET_new (struct GNUNET_RECLAIM_PluginFunctions);
703 api->cls = &plugin; 703 api->cls = &plugin;
704 api->store_ticket = &identity_provider_sqlite_store_ticket; 704 api->store_ticket = &reclaim_sqlite_store_ticket;
705 api->delete_ticket = &identity_provider_sqlite_delete_ticket; 705 api->delete_ticket = &reclaim_sqlite_delete_ticket;
706 api->iterate_tickets = &identity_provider_sqlite_iterate_tickets; 706 api->iterate_tickets = &reclaim_sqlite_iterate_tickets;
707 api->get_ticket_attributes = &identity_provider_sqlite_ticket_get_attrs; 707 api->get_ticket_attributes = &reclaim_sqlite_ticket_get_attrs;
708 LOG (GNUNET_ERROR_TYPE_INFO, 708 LOG (GNUNET_ERROR_TYPE_INFO,
709 _("Sqlite database running\n")); 709 _("Sqlite database running\n"));
710 return api; 710 return api;
@@ -718,9 +718,9 @@ libgnunet_plugin_identity_provider_sqlite_init (void *cls)
718 * @return always NULL 718 * @return always NULL
719 */ 719 */
720void * 720void *
721libgnunet_plugin_identity_provider_sqlite_done (void *cls) 721libgnunet_plugin_reclaim_sqlite_done (void *cls)
722{ 722{
723 struct GNUNET_IDENTITY_PROVIDER_PluginFunctions *api = cls; 723 struct GNUNET_RECLAIM_PluginFunctions *api = cls;
724 struct Plugin *plugin = api->cls; 724 struct Plugin *plugin = api->cls;
725 725
726 database_shutdown (plugin); 726 database_shutdown (plugin);
@@ -731,4 +731,4 @@ libgnunet_plugin_identity_provider_sqlite_done (void *cls)
731 return NULL; 731 return NULL;
732} 732}
733 733
734/* end of plugin_identity_provider_sqlite.c */ 734/* end of plugin_reclaim_sqlite.c */
diff --git a/src/identity-provider/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index d87a345cf..24673c692 100644
--- a/src/identity-provider/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -36,9 +36,9 @@
36#include <jansson.h> 36#include <jansson.h>
37#include <inttypes.h> 37#include <inttypes.h>
38#include "gnunet_signatures.h" 38#include "gnunet_signatures.h"
39#include "gnunet_identity_attribute_lib.h" 39#include "gnunet_reclaim_attribute_lib.h"
40#include "gnunet_identity_provider_service.h" 40#include "gnunet_reclaim_service.h"
41#include "jwt.h" 41#include "oidc_helper.h"
42 42
43/** 43/**
44 * REST root namespace 44 * REST root namespace
@@ -68,7 +68,7 @@
68/** 68/**
69 * Attribute key 69 * Attribute key
70 */ 70 */
71#define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE "attribute" 71#define GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE "attribute"
72 72
73/** 73/**
74 * Ticket key 74 * Ticket key
@@ -79,7 +79,7 @@
79/** 79/**
80 * Value key 80 * Value key
81 */ 81 */
82#define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE_VALUE "value" 82#define GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE_VALUE "value"
83 83
84/** 84/**
85 * State while collecting all egos 85 * State while collecting all egos
@@ -168,7 +168,6 @@ static char* OIDC_ignored_parameter_array [] =
168{ 168{
169 "display", 169 "display",
170 "prompt", 170 "prompt",
171 "max_age",
172 "ui_locales", 171 "ui_locales",
173 "response_mode", 172 "response_mode",
174 "id_token_hint", 173 "id_token_hint",
@@ -230,12 +229,6 @@ struct OIDC_Variables
230 char *client_id; 229 char *client_id;
231 230
232 /** 231 /**
233 * GNUNET_YES if there is a delegation to
234 * this RP or if it is a local identity
235 */
236 int is_client_trusted;
237
238 /**
239 * The OIDC redirect uri 232 * The OIDC redirect uri
240 */ 233 */
241 char *redirect_uri; 234 char *redirect_uri;
@@ -347,6 +340,16 @@ struct RequestHandle
347 struct GNUNET_REST_RequestHandle *rest_handle; 340 struct GNUNET_REST_RequestHandle *rest_handle;
348 341
349 /** 342 /**
343 * GNS handle
344 */
345 struct GNUNET_GNS_Handle *gns_handle;
346
347 /**
348 * GNS lookup op
349 */
350 struct GNUNET_GNS_LookupRequest *gns_op;
351
352 /**
350 * Handle to NAMESTORE 353 * Handle to NAMESTORE
351 */ 354 */
352 struct GNUNET_NAMESTORE_Handle *namestore_handle; 355 struct GNUNET_NAMESTORE_Handle *namestore_handle;
@@ -359,7 +362,7 @@ struct RequestHandle
359 /** 362 /**
360 * Attribute claim list 363 * Attribute claim list
361 */ 364 */
362 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attr_list; 365 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
363 366
364 /** 367 /**
365 * IDENTITY Operation 368 * IDENTITY Operation
@@ -369,27 +372,27 @@ struct RequestHandle
369 /** 372 /**
370 * Identity Provider 373 * Identity Provider
371 */ 374 */
372 struct GNUNET_IDENTITY_PROVIDER_Handle *idp; 375 struct GNUNET_RECLAIM_Handle *idp;
373 376
374 /** 377 /**
375 * Idp Operation 378 * Idp Operation
376 */ 379 */
377 struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op; 380 struct GNUNET_RECLAIM_Operation *idp_op;
378 381
379 /** 382 /**
380 * Attribute iterator 383 * Attribute iterator
381 */ 384 */
382 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_it; 385 struct GNUNET_RECLAIM_AttributeIterator *attr_it;
383 386
384 /** 387 /**
385 * Ticket iterator 388 * Ticket iterator
386 */ 389 */
387 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it; 390 struct GNUNET_RECLAIM_TicketIterator *ticket_it;
388 391
389 /** 392 /**
390 * A ticket 393 * A ticket
391 */ 394 */
392 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 395 struct GNUNET_RECLAIM_Ticket ticket;
393 396
394 /** 397 /**
395 * Desired timeout for the lookup (default is no timeout). 398 * Desired timeout for the lookup (default is no timeout).
@@ -422,6 +425,16 @@ struct RequestHandle
422 char *tld; 425 char *tld;
423 426
424 /** 427 /**
428 * The redirect prefix
429 */
430 char *redirect_prefix;
431
432 /**
433 * The redirect suffix
434 */
435 char *redirect_suffix;
436
437 /**
425 * Error response message 438 * Error response message
426 */ 439 */
427 char *emsg; 440 char *emsg;
@@ -450,8 +463,8 @@ struct RequestHandle
450static void 463static void
451cleanup_handle (struct RequestHandle *handle) 464cleanup_handle (struct RequestHandle *handle)
452{ 465{
453 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *claim_entry; 466 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry;
454 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *claim_tmp; 467 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp;
455 struct EgoEntry *ego_entry; 468 struct EgoEntry *ego_entry;
456 struct EgoEntry *ego_tmp; 469 struct EgoEntry *ego_tmp;
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -463,19 +476,28 @@ cleanup_handle (struct RequestHandle *handle)
463 if (NULL != handle->identity_handle) 476 if (NULL != handle->identity_handle)
464 GNUNET_IDENTITY_disconnect (handle->identity_handle); 477 GNUNET_IDENTITY_disconnect (handle->identity_handle);
465 if (NULL != handle->attr_it) 478 if (NULL != handle->attr_it)
466 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (handle->attr_it); 479 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
467 if (NULL != handle->ticket_it) 480 if (NULL != handle->ticket_it)
468 GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (handle->ticket_it); 481 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
469 if (NULL != handle->idp) 482 if (NULL != handle->idp)
470 GNUNET_IDENTITY_PROVIDER_disconnect (handle->idp); 483 GNUNET_RECLAIM_disconnect (handle->idp);
471 if (NULL != handle->url) 484 if (NULL != handle->url)
472 GNUNET_free (handle->url); 485 GNUNET_free (handle->url);
473 if (NULL != handle->tld) 486 if (NULL != handle->tld)
474 GNUNET_free (handle->tld); 487 GNUNET_free (handle->tld);
488 if (NULL != handle->redirect_prefix)
489 GNUNET_free (handle->redirect_prefix);
490 if (NULL != handle->redirect_suffix)
491 GNUNET_free (handle->redirect_suffix);
475 if (NULL != handle->emsg) 492 if (NULL != handle->emsg)
476 GNUNET_free (handle->emsg); 493 GNUNET_free (handle->emsg);
477 if (NULL != handle->edesc) 494 if (NULL != handle->edesc)
478 GNUNET_free (handle->edesc); 495 GNUNET_free (handle->edesc);
496 if (NULL != handle->gns_op)
497 GNUNET_GNS_lookup_cancel (handle->gns_op);
498 if (NULL != handle->gns_handle)
499 GNUNET_GNS_disconnect (handle->gns_handle);
500
479 if (NULL != handle->namestore_handle) 501 if (NULL != handle->namestore_handle)
480 GNUNET_NAMESTORE_disconnect (handle->namestore_handle); 502 GNUNET_NAMESTORE_disconnect (handle->namestore_handle);
481 if (NULL != handle->oidc) 503 if (NULL != handle->oidc)
@@ -732,6 +754,8 @@ cookie_identity_interpretation (struct RequestHandle *handle)
732 { 754 {
733 handle->oidc->login_identity = strtok(handle->oidc->login_identity, OIDC_COOKIE_HEADER_INFORMATION_KEY); 755 handle->oidc->login_identity = strtok(handle->oidc->login_identity, OIDC_COOKIE_HEADER_INFORMATION_KEY);
734 handle->oidc->login_identity = GNUNET_strdup(handle->oidc->login_identity); 756 handle->oidc->login_identity = GNUNET_strdup(handle->oidc->login_identity);
757 } else {
758 handle->oidc->login_identity = NULL;
735 } 759 }
736 } 760 }
737 else 761 else
@@ -753,7 +777,7 @@ login_redirection(void *cls)
753 struct RequestHandle *handle = cls; 777 struct RequestHandle *handle = cls;
754 778
755 if ( GNUNET_OK 779 if ( GNUNET_OK
756 == GNUNET_CONFIGURATION_get_value_string (cfg, "identity-rest-plugin", 780 == GNUNET_CONFIGURATION_get_value_string (cfg, "reclaim-rest-plugin",
757 "address", &login_base_url) ) 781 "address", &login_base_url) )
758 { 782 {
759 GNUNET_asprintf (&new_redirect, "%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", 783 GNUNET_asprintf (&new_redirect, "%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
@@ -799,11 +823,12 @@ oidc_iteration_error (void *cls)
799 GNUNET_SCHEDULER_add_now (&do_error, handle); 823 GNUNET_SCHEDULER_add_now (&do_error, handle);
800} 824}
801 825
802static void get_client_name_result (void *cls, 826static void
803 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 827get_client_name_result (void *cls,
804 const char *label, 828 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
805 unsigned int rd_count, 829 const char *label,
806 const struct GNUNET_GNSRECORD_Data *rd) 830 unsigned int rd_count,
831 const struct GNUNET_GNSRECORD_Data *rd)
807{ 832{
808 struct RequestHandle *handle = cls; 833 struct RequestHandle *handle = cls;
809 struct MHD_Response *resp; 834 struct MHD_Response *resp;
@@ -811,46 +836,33 @@ static void get_client_name_result (void *cls,
811 char *redirect_uri; 836 char *redirect_uri;
812 char *code_json_string; 837 char *code_json_string;
813 char *code_base64_final_string; 838 char *code_base64_final_string;
814 char *redirect_path; 839
815 char *tmp;
816 char *tmp_prefix;
817 char *prefix;
818 ticket_str = GNUNET_STRINGS_data_to_string_alloc (&handle->ticket, 840 ticket_str = GNUNET_STRINGS_data_to_string_alloc (&handle->ticket,
819 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); 841 sizeof (struct GNUNET_RECLAIM_Ticket));
820 //TODO change if more attributes are needed (see max_age) 842 //TODO change if more attributes are needed (see max_age)
821 GNUNET_asprintf (&code_json_string, "{\"ticket\":\"%s\"%s%s%s}", 843 code_json_string = OIDC_build_authz_code (&handle->priv_key,
822 ticket_str, 844 &handle->ticket,
823 (NULL != handle->oidc->nonce) ? ", \"nonce\":\"" : "", 845 handle->oidc->nonce);
824 (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "",
825 (NULL != handle->oidc->nonce) ? "\"" : "");
826 code_base64_final_string = base_64_encode(code_json_string); 846 code_base64_final_string = base_64_encode(code_json_string);
827 tmp = GNUNET_strdup (handle->oidc->redirect_uri);
828 redirect_path = strtok (tmp, "/");
829 redirect_path = strtok (NULL, "/");
830 redirect_path = strtok (NULL, "/");
831 tmp_prefix = GNUNET_strdup (handle->oidc->redirect_uri);
832 prefix = strrchr (tmp_prefix,
833 (unsigned char) '.');
834 *prefix = '\0';
835 GNUNET_asprintf (&redirect_uri, "%s.%s/%s?%s=%s&state=%s", 847 GNUNET_asprintf (&redirect_uri, "%s.%s/%s?%s=%s&state=%s",
836 tmp_prefix, 848 handle->redirect_prefix,
837 handle->tld, 849 handle->tld,
838 redirect_path, 850 handle->redirect_suffix,
839 handle->oidc->response_type, 851 handle->oidc->response_type,
840 code_base64_final_string, handle->oidc->state); 852 code_base64_final_string, handle->oidc->state);
841 resp = GNUNET_REST_create_response (""); 853 resp = GNUNET_REST_create_response ("");
842 MHD_add_response_header (resp, "Location", redirect_uri); 854 MHD_add_response_header (resp, "Location", redirect_uri);
843 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND); 855 handle->proc (handle->proc_cls, resp, MHD_HTTP_FOUND);
844 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 856 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
845 GNUNET_free (tmp);
846 GNUNET_free (tmp_prefix);
847 GNUNET_free (redirect_uri); 857 GNUNET_free (redirect_uri);
848 GNUNET_free (ticket_str); 858 GNUNET_free (ticket_str);
849 GNUNET_free (code_json_string); 859 GNUNET_free (code_json_string);
850 GNUNET_free (code_base64_final_string); 860 GNUNET_free (code_base64_final_string);
851 return; 861 return;
862
852} 863}
853 864
865
854static void 866static void
855get_client_name_error (void *cls) 867get_client_name_error (void *cls)
856{ 868{
@@ -861,32 +873,93 @@ get_client_name_error (void *cls)
861 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); 873 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
862} 874}
863 875
864/** 876
865 * Issues ticket and redirects to relying party with the authorization code as
866 * parameter. Otherwise redirects with error
867 */
868static void 877static void
869oidc_ticket_issue_cb (void* cls, 878lookup_redirect_uri_result (void *cls,
870 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket) 879 uint32_t rd_count,
880 const struct GNUNET_GNSRECORD_Data *rd)
871{ 881{
872 struct RequestHandle *handle = cls; 882 struct RequestHandle *handle = cls;
873 handle->idp_op = NULL; 883 char *tmp;
874 handle->ticket = *ticket; 884 char *tmp_key_str;
875 if (NULL != ticket) { 885 char *pos;
886 struct GNUNET_CRYPTO_EcdsaPublicKey redirect_zone;
887
888 handle->gns_op = NULL;
889 if (0 == rd_count)
890 {
891 handle->emsg = GNUNET_strdup("server_error");
892 handle->edesc = GNUNET_strdup("Server cannot generate ticket, redirect uri not found.");
893 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
894 return;
895 }
896 for (int i = 0; i < rd_count; i++)
897 {
898 if (GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT != rd[i].record_type)
899 continue;
900 if (0 != strcmp (rd[i].data,
901 handle->oidc->redirect_uri))
902 continue;
903 tmp = GNUNET_strdup (rd[i].data);
904 pos = strrchr (tmp,
905 (unsigned char) '.');
906 *pos = '\0';
907 handle->redirect_prefix = GNUNET_strdup (tmp);
908 tmp_key_str = pos + 1;
909 pos = strchr (tmp_key_str,
910 (unsigned char) '/');
911 *pos = '\0';
912 handle->redirect_suffix = GNUNET_strdup (pos + 1);
913
914 GNUNET_STRINGS_string_to_data (tmp_key_str,
915 strlen (tmp_key_str),
916 &redirect_zone,
917 sizeof (redirect_zone));
918
876 GNUNET_NAMESTORE_zone_to_name (handle->namestore_handle, 919 GNUNET_NAMESTORE_zone_to_name (handle->namestore_handle,
877 &handle->priv_key, 920 &handle->priv_key,
878 &handle->oidc->client_pkey, 921 &redirect_zone,
879 &get_client_name_error, 922 &get_client_name_error,
880 handle, 923 handle,
881 &get_client_name_result, 924 &get_client_name_result,
882 handle); 925 handle);
926 GNUNET_free (tmp);
883 return; 927 return;
884 } 928 }
885 handle->emsg = GNUNET_strdup("server_error"); 929 handle->emsg = GNUNET_strdup("server_error");
886 handle->edesc = GNUNET_strdup("Server cannot generate ticket."); 930 handle->edesc = GNUNET_strdup("Server cannot generate ticket, redirect uri not found.");
887 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); 931 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
888} 932}
889 933
934/**
935 * Issues ticket and redirects to relying party with the authorization code as
936 * parameter. Otherwise redirects with error
937 */
938static void
939oidc_ticket_issue_cb (void* cls,
940 const struct GNUNET_RECLAIM_Ticket *ticket)
941{
942 struct RequestHandle *handle = cls;
943
944 handle->idp_op = NULL;
945 handle->ticket = *ticket;
946 if (NULL == ticket)
947 {
948 handle->emsg = GNUNET_strdup("server_error");
949 handle->edesc = GNUNET_strdup("Server cannot generate ticket.");
950 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
951 return;
952 }
953 handle->gns_op = GNUNET_GNS_lookup (handle->gns_handle,
954 "+",
955 &handle->oidc->client_pkey,
956 GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT,
957 GNUNET_GNS_LO_DEFAULT,
958 &lookup_redirect_uri_result,
959 handle);
960
961}
962
890static void 963static void
891oidc_collect_finished_cb (void *cls) 964oidc_collect_finished_cb (void *cls)
892{ 965{
@@ -900,12 +973,12 @@ oidc_collect_finished_cb (void *cls)
900 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); 973 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
901 return; 974 return;
902 } 975 }
903 handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_issue (handle->idp, 976 handle->idp_op = GNUNET_RECLAIM_ticket_issue (handle->idp,
904 &handle->priv_key, 977 &handle->priv_key,
905 &handle->oidc->client_pkey, 978 &handle->oidc->client_pkey,
906 handle->attr_list, 979 handle->attr_list,
907 &oidc_ticket_issue_cb, 980 &oidc_ticket_issue_cb,
908 handle); 981 handle);
909} 982}
910 983
911 984
@@ -915,17 +988,17 @@ oidc_collect_finished_cb (void *cls)
915static void 988static void
916oidc_attr_collect (void *cls, 989oidc_attr_collect (void *cls,
917 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 990 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
918 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 991 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
919{ 992{
920 struct RequestHandle *handle = cls; 993 struct RequestHandle *handle = cls;
921 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 994 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
922 char* scope_variables; 995 char* scope_variables;
923 char* scope_variable; 996 char* scope_variable;
924 char delimiter[]=" "; 997 char delimiter[]=" ";
925 998
926 if ( (NULL == attr->name) || (NULL == attr->data) ) 999 if ( (NULL == attr->name) || (NULL == attr->data) )
927 { 1000 {
928 GNUNET_IDENTITY_PROVIDER_get_attributes_next (handle->attr_it); 1001 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
929 return; 1002 return;
930 } 1003 }
931 1004
@@ -941,18 +1014,18 @@ oidc_attr_collect (void *cls,
941 } 1014 }
942 if ( NULL == scope_variable ) 1015 if ( NULL == scope_variable )
943 { 1016 {
944 GNUNET_IDENTITY_PROVIDER_get_attributes_next (handle->attr_it); 1017 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
945 GNUNET_free(scope_variables); 1018 GNUNET_free(scope_variables);
946 return; 1019 return;
947 } 1020 }
948 GNUNET_free(scope_variables); 1021 GNUNET_free(scope_variables);
949 1022
950 le = GNUNET_new(struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); 1023 le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
951 le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr->name, attr->type, 1024 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr->name, attr->type,
952 attr->data, attr->data_size); 1025 attr->data, attr->data_size);
953 GNUNET_CONTAINER_DLL_insert(handle->attr_list->list_head, 1026 GNUNET_CONTAINER_DLL_insert(handle->attr_list->list_head,
954 handle->attr_list->list_tail, le); 1027 handle->attr_list->list_tail, le);
955 GNUNET_IDENTITY_PROVIDER_get_attributes_next (handle->attr_it); 1028 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
956} 1029}
957 1030
958 1031
@@ -1005,88 +1078,33 @@ login_check (void *cls)
1005 handle->priv_key = *GNUNET_IDENTITY_ego_get_private_key ( 1078 handle->priv_key = *GNUNET_IDENTITY_ego_get_private_key (
1006 handle->ego_entry->ego); 1079 handle->ego_entry->ego);
1007 handle->resp_object = GNUNET_JSONAPI_document_new (); 1080 handle->resp_object = GNUNET_JSONAPI_document_new ();
1008 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 1081 handle->idp = GNUNET_RECLAIM_connect (cfg);
1009 handle->attr_list = GNUNET_new( 1082 handle->attr_list = GNUNET_new(
1010 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); 1083 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
1011 handle->attr_it = GNUNET_IDENTITY_PROVIDER_get_attributes_start ( 1084 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (
1012 handle->idp, &handle->priv_key, &oidc_iteration_error, handle, 1085 handle->idp, &handle->priv_key, &oidc_iteration_error, handle,
1013 &oidc_attr_collect, handle, &oidc_collect_finished_cb, handle); 1086 &oidc_attr_collect, handle, &oidc_collect_finished_cb, handle);
1014 return; 1087 return;
1015 } 1088 }
1016 } 1089 }
1017 handle->emsg = GNUNET_strdup("invalid_cookie"); 1090 //handle->emsg = GNUNET_strdup("invalid_cookie");
1018 handle->edesc = GNUNET_strdup( 1091 //handle->edesc = GNUNET_strdup(
1019 "The cookie of the login identity is not valid"); 1092 // "The cookie of the login identity is not valid");
1020 GNUNET_SCHEDULER_add_now (&do_redirect_error, handle); 1093 //GNUNET_SCHEDULER_add_now (&do_redirect_error, handle);
1094 GNUNET_SCHEDULER_add_now (&login_redirection,handle);
1021 return; 1095 return;
1022 } 1096 }
1023 } 1097 }
1024} 1098}
1025 1099
1026/** 1100/**
1027 * Searches for client_id in namestore. If found trust status stored in handle
1028 * Else continues to search
1029 *
1030 * @param handle the RequestHandle
1031 */
1032static void
1033namestore_iteration_callback (
1034 void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
1035 const char *rname, unsigned int rd_len,
1036 const struct GNUNET_GNSRECORD_Data *rd)
1037{
1038 struct RequestHandle *handle = cls;
1039 struct GNUNET_CRYPTO_EcdsaPublicKey login_identity_pkey;
1040 struct GNUNET_CRYPTO_EcdsaPublicKey current_zone_pkey;
1041 int i;
1042
1043 for (i = 0; i < rd_len; i++)
1044 {
1045 if ( GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type )
1046 continue;
1047
1048 if ( NULL != handle->oidc->login_identity )
1049 {
1050 GNUNET_CRYPTO_ecdsa_public_key_from_string (
1051 handle->oidc->login_identity,
1052 strlen (handle->oidc->login_identity),
1053 &login_identity_pkey);
1054 GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego,
1055 &current_zone_pkey);
1056
1057 if ( 0 == memcmp (rd[i].data, &handle->oidc->client_pkey,
1058 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) )
1059 {
1060 if ( 0 == memcmp (&login_identity_pkey, &current_zone_pkey,
1061 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) )
1062 {
1063 handle->oidc->is_client_trusted = GNUNET_YES;
1064 }
1065 }
1066 }
1067 else
1068 {
1069 if ( 0 == memcmp (rd[i].data, &handle->oidc->client_pkey,
1070 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) )
1071 {
1072 handle->oidc->is_client_trusted = GNUNET_YES;
1073 }
1074 }
1075 }
1076
1077 GNUNET_NAMESTORE_zone_iterator_next (handle->namestore_handle_it,
1078 1);
1079}
1080
1081
1082/**
1083 * Iteration over all results finished, build final 1101 * Iteration over all results finished, build final
1084 * response. 1102 * response.
1085 * 1103 *
1086 * @param cls the `struct RequestHandle` 1104 * @param cls the `struct RequestHandle`
1087 */ 1105 */
1088static void 1106static void
1089namestore_iteration_finished (void *cls) 1107build_authz_response (void *cls)
1090{ 1108{
1091 struct RequestHandle *handle = cls; 1109 struct RequestHandle *handle = cls;
1092 struct GNUNET_HashCode cache_key; 1110 struct GNUNET_HashCode cache_key;
@@ -1096,25 +1114,6 @@ namestore_iteration_finished (void *cls)
1096 int number_of_ignored_parameter, iterator; 1114 int number_of_ignored_parameter, iterator;
1097 1115
1098 1116
1099 handle->ego_entry = handle->ego_entry->next;
1100
1101 if(NULL != handle->ego_entry)
1102 {
1103 handle->priv_key = *GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego);
1104 handle->namestore_handle_it = GNUNET_NAMESTORE_zone_iteration_start (handle->namestore_handle, &handle->priv_key,
1105 &oidc_iteration_error, handle, &namestore_iteration_callback, handle,
1106 &namestore_iteration_finished, handle);
1107 return;
1108 }
1109 if (GNUNET_NO == handle->oidc->is_client_trusted)
1110 {
1111 handle->emsg = GNUNET_strdup("unauthorized_client");
1112 handle->edesc = GNUNET_strdup("The client is not authorized to request an "
1113 "authorization code using this method.");
1114 GNUNET_SCHEDULER_add_now (&do_error, handle);
1115 return;
1116 }
1117
1118 // REQUIRED value: redirect_uri 1117 // REQUIRED value: redirect_uri
1119 GNUNET_CRYPTO_hash (OIDC_REDIRECT_URI_KEY, strlen (OIDC_REDIRECT_URI_KEY), 1118 GNUNET_CRYPTO_hash (OIDC_REDIRECT_URI_KEY, strlen (OIDC_REDIRECT_URI_KEY),
1120 &cache_key); 1119 &cache_key);
@@ -1244,8 +1243,8 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1244 struct RequestHandle *handle = cls; 1243 struct RequestHandle *handle = cls;
1245 struct GNUNET_HashCode cache_key; 1244 struct GNUNET_HashCode cache_key;
1246 struct EgoEntry *tmp_ego; 1245 struct EgoEntry *tmp_ego;
1247 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1248 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 1246 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
1247 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1249 1248
1250 cookie_identity_interpretation(handle); 1249 cookie_identity_interpretation(handle);
1251 1250
@@ -1299,9 +1298,8 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1299 1298
1300 handle->ego_entry = handle->ego_head; 1299 handle->ego_entry = handle->ego_head;
1301 handle->priv_key = *GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego); 1300 handle->priv_key = *GNUNET_IDENTITY_ego_get_private_key (handle->ego_head->ego);
1302 handle->oidc->is_client_trusted = GNUNET_NO; 1301 //If we know this identity, translated the corresponding TLD
1303 1302 //TODO: We might want to have a reverse lookup functionality for TLDs?
1304 //First check if client_id is one of our egos; TODO: handle other TLD cases: Delegation, from config
1305 for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) 1303 for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next)
1306 { 1304 {
1307 priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego); 1305 priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego);
@@ -1311,17 +1309,10 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1311 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) ) 1309 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) )
1312 { 1310 {
1313 handle->tld = GNUNET_strdup (tmp_ego->identifier); 1311 handle->tld = GNUNET_strdup (tmp_ego->identifier);
1314 handle->oidc->is_client_trusted = GNUNET_YES;
1315 handle->ego_entry = handle->ego_tail; 1312 handle->ego_entry = handle->ego_tail;
1316 } 1313 }
1317 } 1314 }
1318 1315 GNUNET_SCHEDULER_add_now (&build_authz_response, handle);
1319
1320 // Checks if client_id is valid:
1321 handle->namestore_handle_it = GNUNET_NAMESTORE_zone_iteration_start (
1322 handle->namestore_handle, &handle->priv_key, &oidc_iteration_error,
1323 handle, &namestore_iteration_callback, handle,
1324 &namestore_iteration_finished, handle);
1325} 1316}
1326 1317
1327/** 1318/**
@@ -1359,8 +1350,8 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
1359 1350
1360 current_time = GNUNET_new(struct GNUNET_TIME_Absolute); 1351 current_time = GNUNET_new(struct GNUNET_TIME_Absolute);
1361 *current_time = GNUNET_TIME_relative_to_absolute ( 1352 *current_time = GNUNET_TIME_relative_to_absolute (
1362 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_minute_ (), 1353 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_second_ (),
1363 30)); 1354 5));
1364 last_time = GNUNET_CONTAINER_multihashmap_get(OIDC_identity_login_time, &cache_key); 1355 last_time = GNUNET_CONTAINER_multihashmap_get(OIDC_identity_login_time, &cache_key);
1365 if (NULL != last_time) 1356 if (NULL != last_time)
1366 { 1357 {
@@ -1382,37 +1373,19 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
1382 return; 1373 return;
1383} 1374}
1384 1375
1385/** 1376static int
1386 * Responds to token url-encoded POST request 1377check_authorization (struct RequestHandle *handle,
1387 * 1378 struct GNUNET_CRYPTO_EcdsaPublicKey *cid)
1388 * @param con_handle the connection handle
1389 * @param url the url
1390 * @param cls the RequestHandle
1391 */
1392static void
1393token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1394 const char* url,
1395 void *cls)
1396{ 1379{
1397 //TODO static strings
1398 struct RequestHandle *handle = cls;
1399 struct GNUNET_HashCode cache_key; 1380 struct GNUNET_HashCode cache_key;
1400 char *authorization, *credentials; 1381 char *authorization;
1401 char delimiter[]=" "; 1382 char *credentials;
1402 char delimiter_user_psw[]=":"; 1383 char *basic_authorization;
1403 char *grant_type, *code; 1384 char *client_id;
1404 char *user_psw = NULL, *client_id, *psw; 1385 char *pass;
1405 char *expected_psw; 1386 char *expected_pass;
1406 int client_exists = GNUNET_NO; 1387 int client_exists = GNUNET_NO;
1407 struct MHD_Response *resp;
1408 char* code_output;
1409 json_t *root, *ticket_string, *nonce, *max_age;
1410 json_error_t error;
1411 char *json_response;
1412 1388
1413 /*
1414 * Check Authorization
1415 */
1416 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY, 1389 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
1417 strlen (OIDC_AUTHORIZATION_HEADER_KEY), 1390 strlen (OIDC_AUTHORIZATION_HEADER_KEY),
1418 &cache_key); 1391 &cache_key);
@@ -1422,80 +1395,75 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1422 handle->emsg=GNUNET_strdup("invalid_client"); 1395 handle->emsg=GNUNET_strdup("invalid_client");
1423 handle->edesc=GNUNET_strdup("missing authorization"); 1396 handle->edesc=GNUNET_strdup("missing authorization");
1424 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1397 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1425 GNUNET_SCHEDULER_add_now (&do_error, handle); 1398 return GNUNET_SYSERR;
1426 return;
1427 } 1399 }
1428 authorization = GNUNET_CONTAINER_multihashmap_get ( handle->rest_handle->header_param_map, &cache_key); 1400 authorization = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map,
1401 &cache_key);
1429 1402
1430 //split header in "Basic" and [content] 1403 //split header in "Basic" and [content]
1431 credentials = strtok (authorization, delimiter); 1404 credentials = strtok (authorization, " ");
1432 if (0 != strcmp ("Basic",credentials)) 1405 if (0 != strcmp ("Basic", credentials))
1433 { 1406 {
1434 handle->emsg=GNUNET_strdup("invalid_client"); 1407 handle->emsg=GNUNET_strdup("invalid_client");
1435 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1408 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1436 GNUNET_SCHEDULER_add_now (&do_error, handle); 1409 return GNUNET_SYSERR;
1437 return;
1438 } 1410 }
1439 credentials = strtok(NULL, delimiter); 1411 credentials = strtok(NULL, " ");
1440 if (NULL == credentials) 1412 if (NULL == credentials)
1441 { 1413 {
1442 handle->emsg=GNUNET_strdup("invalid_client"); 1414 handle->emsg=GNUNET_strdup("invalid_client");
1443 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1415 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1444 GNUNET_SCHEDULER_add_now (&do_error, handle); 1416 return GNUNET_SYSERR;
1445 return;
1446 } 1417 }
1447 GNUNET_STRINGS_base64_decode (credentials, strlen (credentials), &user_psw); 1418 GNUNET_STRINGS_base64_decode (credentials,
1419 strlen (credentials),
1420 (void**)&basic_authorization);
1448 1421
1449 if ( NULL == user_psw ) 1422 if ( NULL == basic_authorization )
1450 { 1423 {
1451 handle->emsg=GNUNET_strdup("invalid_client"); 1424 handle->emsg=GNUNET_strdup("invalid_client");
1452 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1425 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1453 GNUNET_SCHEDULER_add_now (&do_error, handle); 1426 return GNUNET_SYSERR;
1454 return;
1455 } 1427 }
1456 client_id = strtok (user_psw, delimiter_user_psw); 1428 client_id = strtok (basic_authorization, ":");
1457 if ( NULL == client_id ) 1429 if ( NULL == client_id )
1458 { 1430 {
1459 GNUNET_free_non_null(user_psw); 1431 GNUNET_free_non_null(basic_authorization);
1460 handle->emsg=GNUNET_strdup("invalid_client"); 1432 handle->emsg=GNUNET_strdup("invalid_client");
1461 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1433 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1462 GNUNET_SCHEDULER_add_now (&do_error, handle); 1434 return GNUNET_SYSERR;
1463 return;
1464 } 1435 }
1465 psw = strtok (NULL, delimiter_user_psw); 1436 pass = strtok (NULL, ":");
1466 if (NULL == psw) 1437 if (NULL == pass)
1467 { 1438 {
1468 GNUNET_free_non_null(user_psw); 1439 GNUNET_free_non_null(basic_authorization);
1469 handle->emsg=GNUNET_strdup("invalid_client"); 1440 handle->emsg=GNUNET_strdup("invalid_client");
1470 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1441 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1471 GNUNET_SCHEDULER_add_now (&do_error, handle); 1442 return GNUNET_SYSERR;
1472 return;
1473 } 1443 }
1474 1444
1475 //check client password 1445 //check client password
1476 if ( GNUNET_OK 1446 if ( GNUNET_OK
1477 == GNUNET_CONFIGURATION_get_value_string (cfg, "identity-rest-plugin", 1447 == GNUNET_CONFIGURATION_get_value_string (cfg, "reclaim-rest-plugin",
1478 "psw", &expected_psw) ) 1448 "psw", &expected_pass) )
1479 { 1449 {
1480 if (0 != strcmp (expected_psw, psw)) 1450 if (0 != strcmp (expected_pass, pass))
1481 { 1451 {
1482 GNUNET_free_non_null(user_psw); 1452 GNUNET_free_non_null(basic_authorization);
1483 GNUNET_free(expected_psw); 1453 GNUNET_free(expected_pass);
1484 handle->emsg=GNUNET_strdup("invalid_client"); 1454 handle->emsg=GNUNET_strdup("invalid_client");
1485 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1455 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1486 GNUNET_SCHEDULER_add_now (&do_error, handle); 1456 return GNUNET_SYSERR;
1487 return;
1488 } 1457 }
1489 GNUNET_free(expected_psw); 1458 GNUNET_free(expected_pass);
1490 } 1459 }
1491 else 1460 else
1492 { 1461 {
1493 GNUNET_free_non_null(user_psw); 1462 GNUNET_free_non_null(basic_authorization);
1494 handle->emsg = GNUNET_strdup("server_error"); 1463 handle->emsg = GNUNET_strdup("server_error");
1495 handle->edesc = GNUNET_strdup ("gnunet configuration failed"); 1464 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
1496 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; 1465 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1497 GNUNET_SCHEDULER_add_now (&do_error, handle); 1466 return GNUNET_SYSERR;
1498 return;
1499 } 1467 }
1500 1468
1501 //check client_id 1469 //check client_id
@@ -1510,9 +1478,107 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1510 } 1478 }
1511 if (GNUNET_NO == client_exists) 1479 if (GNUNET_NO == client_exists)
1512 { 1480 {
1513 GNUNET_free_non_null(user_psw); 1481 GNUNET_free_non_null(basic_authorization);
1514 handle->emsg=GNUNET_strdup("invalid_client"); 1482 handle->emsg=GNUNET_strdup("invalid_client");
1515 handle->response_code = MHD_HTTP_UNAUTHORIZED; 1483 handle->response_code = MHD_HTTP_UNAUTHORIZED;
1484 return GNUNET_SYSERR;
1485 }
1486 GNUNET_STRINGS_string_to_data (client_id,
1487 strlen(client_id),
1488 cid,
1489 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1490
1491 GNUNET_free (basic_authorization);
1492 return GNUNET_OK;
1493}
1494
1495static int
1496ego_exists (struct RequestHandle *handle,
1497 struct GNUNET_CRYPTO_EcdsaPublicKey *test_key)
1498{
1499 struct EgoEntry *ego_entry;
1500 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
1501
1502 for (ego_entry = handle->ego_head; NULL != ego_entry; ego_entry = ego_entry->next)
1503 {
1504 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key);
1505 if (0 == memcmp (&pub_key,
1506 test_key,
1507 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
1508 {
1509 break;
1510 }
1511 }
1512 if (NULL == ego_entry)
1513 return GNUNET_NO;
1514 return GNUNET_YES;
1515}
1516
1517static void
1518store_ticket_reference (const struct RequestHandle *handle,
1519 const char* access_token,
1520 const struct GNUNET_RECLAIM_Ticket *ticket,
1521 const struct GNUNET_CRYPTO_EcdsaPublicKey *cid)
1522{
1523 struct GNUNET_HashCode cache_key;
1524 char *id_ticket_combination;
1525 char *ticket_string;
1526 char *client_id;
1527
1528 GNUNET_CRYPTO_hash(access_token, strlen(access_token), &cache_key);
1529 client_id = GNUNET_STRINGS_data_to_string_alloc (cid,
1530 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1531 ticket_string = GNUNET_STRINGS_data_to_string_alloc (ticket,
1532 sizeof (struct GNUNET_RECLAIM_Ticket));
1533 GNUNET_asprintf(&id_ticket_combination,
1534 "%s;%s",
1535 client_id,
1536 ticket_string);
1537 GNUNET_CONTAINER_multihashmap_put(OIDC_interpret_access_token,
1538 &cache_key,
1539 id_ticket_combination,
1540 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1541
1542 GNUNET_free (client_id);
1543 GNUNET_free (ticket_string);
1544}
1545
1546/**
1547 * Responds to token url-encoded POST request
1548 *
1549 * @param con_handle the connection handle
1550 * @param url the url
1551 * @param cls the RequestHandle
1552 */
1553static void
1554token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1555 const char* url,
1556 void *cls)
1557{
1558 struct RequestHandle *handle = cls;
1559 struct GNUNET_TIME_Relative expiration_time;
1560 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *cl;
1561 struct GNUNET_RECLAIM_Ticket *ticket;
1562 struct GNUNET_CRYPTO_EcdsaPublicKey cid;
1563 struct GNUNET_HashCode cache_key;
1564 struct MHD_Response *resp;
1565 char *grant_type;
1566 char *code;
1567 char *json_response;
1568 char *id_token;
1569 char *access_token;
1570 char *jwt_secret;
1571 char *nonce;
1572 int i = 1;
1573
1574 /*
1575 * Check Authorization
1576 */
1577 if (GNUNET_SYSERR == check_authorization (handle,
1578 &cid))
1579 {
1580 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1581 "OIDC authorization for token endpoint failed\n");
1516 GNUNET_SCHEDULER_add_now (&do_error, handle); 1582 GNUNET_SCHEDULER_add_now (&do_error, handle);
1517 return; 1583 return;
1518 } 1584 }
@@ -1524,27 +1590,25 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1524 //TODO Do not allow multiple equal parameter names 1590 //TODO Do not allow multiple equal parameter names
1525 //REQUIRED grant_type 1591 //REQUIRED grant_type
1526 GNUNET_CRYPTO_hash (OIDC_GRANT_TYPE_KEY, strlen (OIDC_GRANT_TYPE_KEY), &cache_key); 1592 GNUNET_CRYPTO_hash (OIDC_GRANT_TYPE_KEY, strlen (OIDC_GRANT_TYPE_KEY), &cache_key);
1527 if ( GNUNET_NO 1593 if (GNUNET_NO ==
1528 == GNUNET_CONTAINER_multihashmap_contains ( 1594 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map,
1529 handle->rest_handle->url_param_map, &cache_key) ) 1595 &cache_key))
1530 { 1596 {
1531 GNUNET_free_non_null(user_psw);
1532 handle->emsg = GNUNET_strdup("invalid_request"); 1597 handle->emsg = GNUNET_strdup("invalid_request");
1533 handle->edesc = GNUNET_strdup("missing parameter grant_type"); 1598 handle->edesc = GNUNET_strdup("missing parameter grant_type");
1534 handle->response_code = MHD_HTTP_BAD_REQUEST; 1599 handle->response_code = MHD_HTTP_BAD_REQUEST;
1535 GNUNET_SCHEDULER_add_now (&do_error, handle); 1600 GNUNET_SCHEDULER_add_now (&do_error, handle);
1536 return; 1601 return;
1537 } 1602 }
1538 grant_type = GNUNET_CONTAINER_multihashmap_get ( 1603 grant_type = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
1539 handle->rest_handle->url_param_map, &cache_key); 1604 &cache_key);
1540 1605
1541 //REQUIRED code 1606 //REQUIRED code
1542 GNUNET_CRYPTO_hash (OIDC_CODE_KEY, strlen (OIDC_CODE_KEY), &cache_key); 1607 GNUNET_CRYPTO_hash (OIDC_CODE_KEY, strlen (OIDC_CODE_KEY), &cache_key);
1543 if ( GNUNET_NO 1608 if (GNUNET_NO ==
1544 == GNUNET_CONTAINER_multihashmap_contains ( 1609 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map,
1545 handle->rest_handle->url_param_map, &cache_key) ) 1610 &cache_key))
1546 { 1611 {
1547 GNUNET_free_non_null(user_psw);
1548 handle->emsg = GNUNET_strdup("invalid_request"); 1612 handle->emsg = GNUNET_strdup("invalid_request");
1549 handle->edesc = GNUNET_strdup("missing parameter code"); 1613 handle->edesc = GNUNET_strdup("missing parameter code");
1550 handle->response_code = MHD_HTTP_BAD_REQUEST; 1614 handle->response_code = MHD_HTTP_BAD_REQUEST;
@@ -1557,11 +1621,10 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1557 //REQUIRED redirect_uri 1621 //REQUIRED redirect_uri
1558 GNUNET_CRYPTO_hash (OIDC_REDIRECT_URI_KEY, strlen (OIDC_REDIRECT_URI_KEY), 1622 GNUNET_CRYPTO_hash (OIDC_REDIRECT_URI_KEY, strlen (OIDC_REDIRECT_URI_KEY),
1559 &cache_key); 1623 &cache_key);
1560 if ( GNUNET_NO 1624 if (GNUNET_NO ==
1561 == GNUNET_CONTAINER_multihashmap_contains ( 1625 GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map,
1562 handle->rest_handle->url_param_map, &cache_key) ) 1626 &cache_key) )
1563 { 1627 {
1564 GNUNET_free_non_null(user_psw);
1565 handle->emsg = GNUNET_strdup("invalid_request"); 1628 handle->emsg = GNUNET_strdup("invalid_request");
1566 handle->edesc = GNUNET_strdup("missing parameter redirect_uri"); 1629 handle->edesc = GNUNET_strdup("missing parameter redirect_uri");
1567 handle->response_code = MHD_HTTP_BAD_REQUEST; 1630 handle->response_code = MHD_HTTP_BAD_REQUEST;
@@ -1572,21 +1635,18 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1572 //Check parameter grant_type == "authorization_code" 1635 //Check parameter grant_type == "authorization_code"
1573 if (0 != strcmp(OIDC_GRANT_TYPE_VALUE, grant_type)) 1636 if (0 != strcmp(OIDC_GRANT_TYPE_VALUE, grant_type))
1574 { 1637 {
1575 GNUNET_free_non_null(user_psw);
1576 handle->emsg=GNUNET_strdup("unsupported_grant_type"); 1638 handle->emsg=GNUNET_strdup("unsupported_grant_type");
1577 handle->response_code = MHD_HTTP_BAD_REQUEST; 1639 handle->response_code = MHD_HTTP_BAD_REQUEST;
1578 GNUNET_SCHEDULER_add_now (&do_error, handle); 1640 GNUNET_SCHEDULER_add_now (&do_error, handle);
1579 return; 1641 return;
1580 } 1642 }
1581 GNUNET_CRYPTO_hash (code, strlen (code), &cache_key); 1643 GNUNET_CRYPTO_hash (code, strlen (code), &cache_key);
1582 int i = 1; 1644 if (GNUNET_SYSERR ==
1583 if ( GNUNET_SYSERR 1645 GNUNET_CONTAINER_multihashmap_put (OIDC_ticket_once,
1584 == GNUNET_CONTAINER_multihashmap_put (OIDC_ticket_once, 1646 &cache_key,
1585 &cache_key, 1647 &i,
1586 &i, 1648 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) )
1587 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) )
1588 { 1649 {
1589 GNUNET_free_non_null(user_psw);
1590 handle->emsg = GNUNET_strdup("invalid_request"); 1650 handle->emsg = GNUNET_strdup("invalid_request");
1591 handle->edesc = GNUNET_strdup("Cannot use the same code more than once"); 1651 handle->edesc = GNUNET_strdup("Cannot use the same code more than once");
1592 handle->response_code = MHD_HTTP_BAD_REQUEST; 1652 handle->response_code = MHD_HTTP_BAD_REQUEST;
@@ -1595,16 +1655,11 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1595 } 1655 }
1596 1656
1597 //decode code 1657 //decode code
1598 GNUNET_STRINGS_base64_decode(code,strlen(code),&code_output); 1658 if(GNUNET_OK != OIDC_parse_authz_code (&cid,
1599 root = json_loads (code_output, 0, &error); 1659 code,
1600 GNUNET_free(code_output); 1660 &ticket,
1601 ticket_string = json_object_get (root, "ticket"); 1661 &nonce))
1602 nonce = json_object_get (root, "nonce");
1603 max_age = json_object_get (root, "max_age");
1604
1605 if(ticket_string == NULL && !json_is_string(ticket_string))
1606 { 1662 {
1607 GNUNET_free_non_null(user_psw);
1608 handle->emsg = GNUNET_strdup("invalid_request"); 1663 handle->emsg = GNUNET_strdup("invalid_request");
1609 handle->edesc = GNUNET_strdup("invalid code"); 1664 handle->edesc = GNUNET_strdup("invalid code");
1610 handle->response_code = MHD_HTTP_BAD_REQUEST; 1665 handle->response_code = MHD_HTTP_BAD_REQUEST;
@@ -1612,42 +1667,13 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1612 return; 1667 return;
1613 } 1668 }
1614 1669
1615 struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket = GNUNET_new(struct GNUNET_IDENTITY_PROVIDER_Ticket);
1616 if ( GNUNET_OK
1617 != GNUNET_STRINGS_string_to_data (json_string_value(ticket_string),
1618 strlen (json_string_value(ticket_string)),
1619 ticket,
1620 sizeof(struct GNUNET_IDENTITY_PROVIDER_Ticket)))
1621 {
1622 GNUNET_free_non_null(user_psw);
1623 handle->emsg = GNUNET_strdup("invalid_request");
1624 handle->edesc = GNUNET_strdup("invalid code");
1625 handle->response_code = MHD_HTTP_BAD_REQUEST;
1626 GNUNET_SCHEDULER_add_now (&do_error, handle);
1627 GNUNET_free(ticket);
1628 return;
1629 }
1630 // this is the current client (relying party)
1631 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
1632 GNUNET_IDENTITY_ego_get_public_key(handle->ego_entry->ego,&pub_key);
1633 if (0 != memcmp(&pub_key,&ticket->audience,sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
1634 {
1635 GNUNET_free_non_null(user_psw);
1636 handle->emsg = GNUNET_strdup("invalid_request");
1637 handle->edesc = GNUNET_strdup("invalid code");
1638 handle->response_code = MHD_HTTP_BAD_REQUEST;
1639 GNUNET_SCHEDULER_add_now (&do_error, handle);
1640 GNUNET_free(ticket);
1641 return;
1642 }
1643
1644 //create jwt 1670 //create jwt
1645 unsigned long long int expiration_time; 1671 if (GNUNET_OK !=
1646 if ( GNUNET_OK 1672 GNUNET_CONFIGURATION_get_value_time(cfg,
1647 != GNUNET_CONFIGURATION_get_value_number(cfg, "identity-rest-plugin", 1673 "reclaim-rest-plugin",
1648 "expiration_time", &expiration_time) ) 1674 "expiration_time",
1675 &expiration_time))
1649 { 1676 {
1650 GNUNET_free_non_null(user_psw);
1651 handle->emsg = GNUNET_strdup("server_error"); 1677 handle->emsg = GNUNET_strdup("server_error");
1652 handle->edesc = GNUNET_strdup ("gnunet configuration failed"); 1678 handle->edesc = GNUNET_strdup ("gnunet configuration failed");
1653 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; 1679 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
@@ -1656,118 +1682,56 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1656 return; 1682 return;
1657 } 1683 }
1658 1684
1659 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *cl = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList);
1660 //aud REQUIRED public key client_id must be there
1661 GNUNET_IDENTITY_ATTRIBUTE_list_add(cl,
1662 "aud",
1663 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING,
1664 client_id,
1665 strlen(client_id));
1666 //exp REQUIRED time expired from config
1667 struct GNUNET_TIME_Absolute exp_time = GNUNET_TIME_relative_to_absolute (
1668 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_second_ (),
1669 expiration_time));
1670 const char* exp_time_string = GNUNET_STRINGS_absolute_time_to_string(exp_time);
1671 GNUNET_IDENTITY_ATTRIBUTE_list_add (cl,
1672 "exp",
1673 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING,
1674 exp_time_string,
1675 strlen(exp_time_string));
1676 //iat REQUIRED time now
1677 struct GNUNET_TIME_Absolute time_now = GNUNET_TIME_absolute_get();
1678 const char* time_now_string = GNUNET_STRINGS_absolute_time_to_string(time_now);
1679 GNUNET_IDENTITY_ATTRIBUTE_list_add (cl,
1680 "iat",
1681 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING,
1682 time_now_string,
1683 strlen(time_now_string));
1684 //nonce only if nonce is provided
1685 if ( NULL != nonce && json_is_string(nonce) )
1686 {
1687 GNUNET_IDENTITY_ATTRIBUTE_list_add (cl,
1688 "nonce",
1689 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING,
1690 json_string_value(nonce),
1691 strlen(json_string_value(nonce)));
1692 }
1693 //auth_time only if max_age is provided
1694 if ( NULL != max_age && json_is_string(max_age) )
1695 {
1696 GNUNET_IDENTITY_ATTRIBUTE_list_add (cl,
1697 "auth_time",
1698 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING,
1699 json_string_value(max_age),
1700 strlen(json_string_value(max_age)));
1701 }
1702 //TODO OPTIONAL acr,amr,azp
1703 1685
1704 struct EgoEntry *ego_entry; 1686 //TODO OPTIONAL acr,amr,azp
1705 for (ego_entry = handle->ego_head; NULL != ego_entry; ego_entry = ego_entry->next) 1687 if (GNUNET_NO == ego_exists (handle,
1688 &ticket->audience))
1706 { 1689 {
1707 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key); 1690 handle->emsg = GNUNET_strdup("invalid_request");
1708 if (0 == memcmp (&pub_key, &ticket->audience, sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) 1691 handle->edesc = GNUNET_strdup("invalid code...");
1709 { 1692 handle->response_code = MHD_HTTP_BAD_REQUEST;
1710 break; 1693 GNUNET_SCHEDULER_add_now (&do_error, handle);
1711 } 1694 GNUNET_free(ticket);
1712 } 1695 }
1713 if ( NULL == ego_entry ) 1696 if ( GNUNET_OK
1697 != GNUNET_CONFIGURATION_get_value_string (cfg, "reclaim-rest-plugin",
1698 "jwt_secret", &jwt_secret) )
1714 { 1699 {
1715 GNUNET_free_non_null(user_psw);
1716 handle->emsg = GNUNET_strdup("invalid_request"); 1700 handle->emsg = GNUNET_strdup("invalid_request");
1717 handle->edesc = GNUNET_strdup("invalid code...."); 1701 handle->edesc = GNUNET_strdup("No signing secret configured!");
1718 handle->response_code = MHD_HTTP_BAD_REQUEST; 1702 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
1719 GNUNET_SCHEDULER_add_now (&do_error, handle); 1703 GNUNET_SCHEDULER_add_now (&do_error, handle);
1720 GNUNET_free(ticket); 1704 GNUNET_free(ticket);
1721 return; 1705 return;
1722 } 1706 }
1723 char *id_token = jwt_create_from_list(&ticket->audience, 1707 //TODO We should collect the attributes here. cl always empty
1724 cl, 1708 cl = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
1725 GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego)); 1709 id_token = OIDC_id_token_new (&ticket->audience,
1726 1710 &ticket->identity,
1727 //Create random access_token 1711 cl,
1728 char* access_token_number; 1712 &expiration_time,
1729 char* access_token; 1713 (NULL != nonce) ? nonce : NULL,
1730 uint64_t random_number; 1714 jwt_secret);
1731 random_number = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX); 1715 access_token = OIDC_access_token_new ();
1732 GNUNET_asprintf(&access_token_number, "%" PRIu64, random_number); 1716 OIDC_build_token_response (access_token,
1733 GNUNET_STRINGS_base64_encode(access_token_number,strlen(access_token_number),&access_token); 1717 id_token,
1734 1718 &expiration_time,
1735 1719 &json_response);
1736 1720
1737 //TODO OPTIONAL add refresh_token and scope 1721 store_ticket_reference (handle,
1738 GNUNET_asprintf (&json_response, 1722 access_token,
1739 "{ \"access_token\" : \"%s\", " 1723 ticket,
1740 "\"token_type\" : \"Bearer\", " 1724 &cid);
1741 "\"expires_in\" : %d, "
1742 "\"id_token\" : \"%s\"}",
1743 access_token,
1744 expiration_time,
1745 id_token);
1746 GNUNET_CRYPTO_hash(access_token, strlen(access_token), &cache_key);
1747 char *id_ticket_combination;
1748 GNUNET_asprintf(&id_ticket_combination,
1749 "%s;%s",
1750 client_id,
1751 json_string_value(ticket_string));
1752 GNUNET_CONTAINER_multihashmap_put(OIDC_interpret_access_token,
1753 &cache_key,
1754 id_ticket_combination,
1755 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1756
1757 resp = GNUNET_REST_create_response (json_response); 1725 resp = GNUNET_REST_create_response (json_response);
1758 MHD_add_response_header (resp, "Cache-Control", "no-store"); 1726 MHD_add_response_header (resp, "Cache-Control", "no-store");
1759 MHD_add_response_header (resp, "Pragma", "no-cache"); 1727 MHD_add_response_header (resp, "Pragma", "no-cache");
1760 MHD_add_response_header (resp, "Content-Type", "application/json"); 1728 MHD_add_response_header (resp, "Content-Type", "application/json");
1761 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 1729 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1762 1730 GNUNET_RECLAIM_ATTRIBUTE_list_destroy(cl);
1763 GNUNET_IDENTITY_ATTRIBUTE_list_destroy(cl);
1764 GNUNET_free(access_token_number);
1765 GNUNET_free(access_token); 1731 GNUNET_free(access_token);
1766 GNUNET_free(user_psw);
1767 GNUNET_free(json_response); 1732 GNUNET_free(json_response);
1768 GNUNET_free(ticket); 1733 GNUNET_free(ticket);
1769 GNUNET_free(id_token); 1734 GNUNET_free(id_token);
1770 json_decref (root);
1771 GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle); 1735 GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle);
1772} 1736}
1773 1737
@@ -1777,7 +1741,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1777static void 1741static void
1778consume_ticket (void *cls, 1742consume_ticket (void *cls,
1779 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 1743 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1780 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 1744 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
1781{ 1745{
1782 struct RequestHandle *handle = cls; 1746 struct RequestHandle *handle = cls;
1783 char *tmp_value; 1747 char *tmp_value;
@@ -1789,9 +1753,9 @@ consume_ticket (void *cls,
1789 return; 1753 return;
1790 } 1754 }
1791 1755
1792 tmp_value = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (attr->type, 1756 tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
1793 attr->data, 1757 attr->data,
1794 attr->data_size); 1758 attr->data_size);
1795 1759
1796 value = json_string (tmp_value); 1760 value = json_string (tmp_value);
1797 1761
@@ -1820,7 +1784,7 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1820 struct GNUNET_HashCode cache_key; 1784 struct GNUNET_HashCode cache_key;
1821 char *authorization, *authorization_type, *authorization_access_token; 1785 char *authorization, *authorization_type, *authorization_access_token;
1822 char *client_ticket, *client, *ticket_str; 1786 char *client_ticket, *client, *ticket_str;
1823 struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket; 1787 struct GNUNET_RECLAIM_Ticket *ticket;
1824 1788
1825 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY, 1789 GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
1826 strlen (OIDC_AUTHORIZATION_HEADER_KEY), 1790 strlen (OIDC_AUTHORIZATION_HEADER_KEY),
@@ -1918,12 +1882,12 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1918 GNUNET_free(client_ticket); 1882 GNUNET_free(client_ticket);
1919 return; 1883 return;
1920 } 1884 }
1921 ticket = GNUNET_new(struct GNUNET_IDENTITY_PROVIDER_Ticket); 1885 ticket = GNUNET_new(struct GNUNET_RECLAIM_Ticket);
1922 if ( GNUNET_OK 1886 if ( GNUNET_OK
1923 != GNUNET_STRINGS_string_to_data (ticket_str, 1887 != GNUNET_STRINGS_string_to_data (ticket_str,
1924 strlen (ticket_str), 1888 strlen (ticket_str),
1925 ticket, 1889 ticket,
1926 sizeof(struct GNUNET_IDENTITY_PROVIDER_Ticket))) 1890 sizeof(struct GNUNET_RECLAIM_Ticket)))
1927 { 1891 {
1928 handle->emsg = GNUNET_strdup("invalid_token"); 1892 handle->emsg = GNUNET_strdup("invalid_token");
1929 handle->edesc = GNUNET_strdup("The Access Token expired"); 1893 handle->edesc = GNUNET_strdup("The Access Token expired");
@@ -1935,15 +1899,15 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
1935 return; 1899 return;
1936 } 1900 }
1937 1901
1938 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 1902 handle->idp = GNUNET_RECLAIM_connect (cfg);
1939 handle->oidc->response = json_object(); 1903 handle->oidc->response = json_object();
1940 json_object_set_new( handle->oidc->response, "sub", json_string( handle->ego_entry->keystring)); 1904 json_object_set_new( handle->oidc->response, "sub", json_string( handle->ego_entry->keystring));
1941 handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume ( 1905 handle->idp_op = GNUNET_RECLAIM_ticket_consume (
1942 handle->idp, 1906 handle->idp,
1943 GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego), 1907 GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego),
1944 ticket, 1908 ticket,
1945 consume_ticket, 1909 consume_ticket,
1946 handle); 1910 handle);
1947 GNUNET_free(ticket); 1911 GNUNET_free(ticket);
1948 GNUNET_free(authorization); 1912 GNUNET_free(authorization);
1949 GNUNET_free(client_ticket); 1913 GNUNET_free(client_ticket);
@@ -2103,6 +2067,7 @@ rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
2103 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, 2067 handle->identity_handle = GNUNET_IDENTITY_connect (cfg,
2104 &list_ego, 2068 &list_ego,
2105 handle); 2069 handle);
2070 handle->gns_handle = GNUNET_GNS_connect (cfg);
2106 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg); 2071 handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg);
2107 handle->timeout_task = 2072 handle->timeout_task =
2108 GNUNET_SCHEDULER_add_delayed (handle->timeout, 2073 GNUNET_SCHEDULER_add_delayed (handle->timeout,
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/reclaim/plugin_rest_reclaim.c
index a83163db2..38ffc4ddb 100644
--- a/src/identity-provider/plugin_rest_identity_provider.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -18,8 +18,8 @@
18/** 18/**
19 * @author Martin Schanzenbach 19 * @author Martin Schanzenbach
20 * @author Philippe Buschmann 20 * @author Philippe Buschmann
21 * @file identity/plugin_rest_identity.c 21 * @file reclaim/plugin_rest_reclaim.c
22 * @brief GNUnet Namestore REST plugin 22 * @brief GNUnet reclaim REST plugin
23 * 23 *
24 */ 24 */
25 25
@@ -36,38 +36,38 @@
36#include <jansson.h> 36#include <jansson.h>
37#include <inttypes.h> 37#include <inttypes.h>
38#include "gnunet_signatures.h" 38#include "gnunet_signatures.h"
39#include "gnunet_identity_attribute_lib.h" 39#include "gnunet_reclaim_attribute_lib.h"
40#include "gnunet_identity_provider_service.h" 40#include "gnunet_reclaim_service.h"
41 41
42/** 42/**
43 * REST root namespace 43 * REST root namespace
44 */ 44 */
45#define GNUNET_REST_API_NS_IDENTITY_PROVIDER "/idp" 45#define GNUNET_REST_API_NS_RECLAIM "/reclaim"
46 46
47/** 47/**
48 * Attribute namespace 48 * Attribute namespace
49 */ 49 */
50#define GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES "/idp/attributes" 50#define GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES "/reclaim/attributes"
51 51
52/** 52/**
53 * Ticket namespace 53 * Ticket namespace
54 */ 54 */
55#define GNUNET_REST_API_NS_IDENTITY_TICKETS "/idp/tickets" 55#define GNUNET_REST_API_NS_IDENTITY_TICKETS "/reclaim/tickets"
56 56
57/** 57/**
58 * Revoke namespace 58 * Revoke namespace
59 */ 59 */
60#define GNUNET_REST_API_NS_IDENTITY_REVOKE "/idp/revoke" 60#define GNUNET_REST_API_NS_IDENTITY_REVOKE "/reclaim/revoke"
61 61
62/** 62/**
63 * Revoke namespace 63 * Revoke namespace
64 */ 64 */
65#define GNUNET_REST_API_NS_IDENTITY_CONSUME "/idp/consume" 65#define GNUNET_REST_API_NS_IDENTITY_CONSUME "/reclaim/consume"
66 66
67/** 67/**
68 * Attribute key 68 * Attribute key
69 */ 69 */
70#define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE "attribute" 70#define GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE "attribute"
71 71
72/** 72/**
73 * Ticket key 73 * Ticket key
@@ -78,7 +78,7 @@
78/** 78/**
79 * Value key 79 * Value key
80 */ 80 */
81#define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE_VALUE "value" 81#define GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE_VALUE "value"
82 82
83/** 83/**
84 * State while collecting all egos 84 * State while collecting all egos
@@ -190,7 +190,7 @@ struct RequestHandle
190 /** 190 /**
191 * Attribute claim list 191 * Attribute claim list
192 */ 192 */
193 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attr_list; 193 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attr_list;
194 194
195 /** 195 /**
196 * IDENTITY Operation 196 * IDENTITY Operation
@@ -200,27 +200,27 @@ struct RequestHandle
200 /** 200 /**
201 * Identity Provider 201 * Identity Provider
202 */ 202 */
203 struct GNUNET_IDENTITY_PROVIDER_Handle *idp; 203 struct GNUNET_RECLAIM_Handle *idp;
204 204
205 /** 205 /**
206 * Idp Operation 206 * Idp Operation
207 */ 207 */
208 struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op; 208 struct GNUNET_RECLAIM_Operation *idp_op;
209 209
210 /** 210 /**
211 * Attribute iterator 211 * Attribute iterator
212 */ 212 */
213 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_it; 213 struct GNUNET_RECLAIM_AttributeIterator *attr_it;
214 214
215 /** 215 /**
216 * Ticket iterator 216 * Ticket iterator
217 */ 217 */
218 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it; 218 struct GNUNET_RECLAIM_TicketIterator *ticket_it;
219 219
220 /** 220 /**
221 * A ticket 221 * A ticket
222 */ 222 */
223 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 223 struct GNUNET_RECLAIM_Ticket ticket;
224 224
225 /** 225 /**
226 * Desired timeout for the lookup (default is no timeout). 226 * Desired timeout for the lookup (default is no timeout).
@@ -271,8 +271,8 @@ struct RequestHandle
271static void 271static void
272cleanup_handle (struct RequestHandle *handle) 272cleanup_handle (struct RequestHandle *handle)
273{ 273{
274 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *claim_entry; 274 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry;
275 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *claim_tmp; 275 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp;
276 struct EgoEntry *ego_entry; 276 struct EgoEntry *ego_entry;
277 struct EgoEntry *ego_tmp; 277 struct EgoEntry *ego_tmp;
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -284,11 +284,11 @@ cleanup_handle (struct RequestHandle *handle)
284 if (NULL != handle->identity_handle) 284 if (NULL != handle->identity_handle)
285 GNUNET_IDENTITY_disconnect (handle->identity_handle); 285 GNUNET_IDENTITY_disconnect (handle->identity_handle);
286 if (NULL != handle->attr_it) 286 if (NULL != handle->attr_it)
287 GNUNET_IDENTITY_PROVIDER_get_attributes_stop (handle->attr_it); 287 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
288 if (NULL != handle->ticket_it) 288 if (NULL != handle->ticket_it)
289 GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (handle->ticket_it); 289 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
290 if (NULL != handle->idp) 290 if (NULL != handle->idp)
291 GNUNET_IDENTITY_PROVIDER_disconnect (handle->idp); 291 GNUNET_RECLAIM_disconnect (handle->idp);
292 if (NULL != handle->url) 292 if (NULL != handle->url)
293 GNUNET_free (handle->url); 293 GNUNET_free (handle->url);
294 if (NULL != handle->emsg) 294 if (NULL != handle->emsg)
@@ -435,7 +435,7 @@ collect_finished_cb (void *cls)
435 */ 435 */
436static void 436static void
437ticket_collect (void *cls, 437ticket_collect (void *cls,
438 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket) 438 const struct GNUNET_RECLAIM_Ticket *ticket)
439{ 439{
440 struct GNUNET_JSONAPI_Resource *json_resource; 440 struct GNUNET_JSONAPI_Resource *json_resource;
441 struct RequestHandle *handle = cls; 441 struct RequestHandle *handle = cls;
@@ -474,7 +474,7 @@ ticket_collect (void *cls,
474 value); 474 value);
475 GNUNET_free (tmp); 475 GNUNET_free (tmp);
476 json_decref (value); 476 json_decref (value);
477 GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (handle->ticket_it); 477 GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it);
478} 478}
479 479
480 480
@@ -523,8 +523,8 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
523 return; 523 return;
524 } 524 }
525 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 525 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
526 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 526 handle->idp = GNUNET_RECLAIM_connect (cfg);
527 handle->ticket_it = GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (handle->idp, 527 handle->ticket_it = GNUNET_RECLAIM_ticket_iteration_start (handle->idp,
528 priv_key, 528 priv_key,
529 &collect_error_cb, 529 &collect_error_cb,
530 handle, 530 handle,
@@ -549,7 +549,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
549 struct RequestHandle *handle = cls; 549 struct RequestHandle *handle = cls;
550 struct EgoEntry *ego_entry; 550 struct EgoEntry *ego_entry;
551 struct MHD_Response *resp; 551 struct MHD_Response *resp;
552 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attribute; 552 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attribute;
553 struct GNUNET_JSONAPI_Document *json_obj; 553 struct GNUNET_JSONAPI_Document *json_obj;
554 struct GNUNET_JSONAPI_Resource *json_res; 554 struct GNUNET_JSONAPI_Resource *json_res;
555 struct GNUNET_TIME_Relative exp; 555 struct GNUNET_TIME_Relative exp;
@@ -565,14 +565,14 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
565 565
566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding an attribute for %s.\n", 566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding an attribute for %s.\n",
567 handle->url); 567 handle->url);
568 if ( strlen (GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES) >= 568 if ( strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >=
569 strlen (handle->url)) 569 strlen (handle->url))
570 { 570 {
571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 571 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
572 GNUNET_SCHEDULER_add_now (&do_error, handle); 572 GNUNET_SCHEDULER_add_now (&do_error, handle);
573 return; 573 return;
574 } 574 }
575 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES) + 1; 575 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
576 576
577 for (ego_entry = handle->ego_head; 577 for (ego_entry = handle->ego_head;
578 NULL != ego_entry; 578 NULL != ego_entry;
@@ -625,7 +625,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
625 } 625 }
626 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); 626 json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0);
627 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, 627 if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res,
628 GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE)) 628 GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE))
629 { 629 {
630 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 630 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
631 "Unsupported JSON data type\n"); 631 "Unsupported JSON data type\n");
@@ -651,12 +651,12 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
651 value_json = GNUNET_JSONAPI_resource_read_attr (json_res, 651 value_json = GNUNET_JSONAPI_resource_read_attr (json_res,
652 "value"); 652 "value");
653 value_str = json_string_value (value_json); 653 value_str = json_string_value (value_json);
654 attribute = GNUNET_IDENTITY_ATTRIBUTE_claim_new (name_str, 654 attribute = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str,
655 GNUNET_IDENTITY_ATTRIBUTE_TYPE_STRING, 655 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
656 value_str, 656 value_str,
657 strlen (value_str) + 1); 657 strlen (value_str) + 1);
658 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 658 handle->idp = GNUNET_RECLAIM_connect (cfg);
659 handle->idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (handle->idp, 659 handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp,
660 identity_priv, 660 identity_priv,
661 attribute, 661 attribute,
662 &exp, 662 &exp,
@@ -675,7 +675,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
675static void 675static void
676attr_collect (void *cls, 676attr_collect (void *cls,
677 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 677 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
678 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 678 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
679{ 679{
680 struct GNUNET_JSONAPI_Resource *json_resource; 680 struct GNUNET_JSONAPI_Resource *json_resource;
681 struct RequestHandle *handle = cls; 681 struct RequestHandle *handle = cls;
@@ -684,17 +684,17 @@ attr_collect (void *cls,
684 684
685 if ((NULL == attr->name) || (NULL == attr->data)) 685 if ((NULL == attr->name) || (NULL == attr->data))
686 { 686 {
687 GNUNET_IDENTITY_PROVIDER_get_attributes_next (handle->attr_it); 687 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
688 return; 688 return;
689 } 689 }
690 690
691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", 691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n",
692 attr->name); 692 attr->name);
693 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE, 693 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE,
694 attr->name); 694 attr->name);
695 GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource); 695 GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource);
696 696
697 tmp_value = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (attr->type, 697 tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type,
698 attr->data, 698 attr->data,
699 attr->data_size); 699 attr->data_size);
700 700
@@ -705,7 +705,7 @@ attr_collect (void *cls,
705 value); 705 value);
706 json_decref (value); 706 json_decref (value);
707 GNUNET_free(tmp_value); 707 GNUNET_free(tmp_value);
708 GNUNET_IDENTITY_PROVIDER_get_attributes_next (handle->attr_it); 708 GNUNET_RECLAIM_get_attributes_next (handle->attr_it);
709} 709}
710 710
711 711
@@ -729,14 +729,14 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
729 729
730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting attributes for %s.\n", 730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting attributes for %s.\n",
731 handle->url); 731 handle->url);
732 if ( strlen (GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES) >= 732 if ( strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >=
733 strlen (handle->url)) 733 strlen (handle->url))
734 { 734 {
735 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 735 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
736 GNUNET_SCHEDULER_add_now (&do_error, handle); 736 GNUNET_SCHEDULER_add_now (&do_error, handle);
737 return; 737 return;
738 } 738 }
739 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES) + 1; 739 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
740 740
741 for (ego_entry = handle->ego_head; 741 for (ego_entry = handle->ego_head;
742 NULL != ego_entry; 742 NULL != ego_entry;
@@ -755,8 +755,8 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
755 return; 755 return;
756 } 756 }
757 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 757 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
758 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 758 handle->idp = GNUNET_RECLAIM_connect (cfg);
759 handle->attr_it = GNUNET_IDENTITY_PROVIDER_get_attributes_start (handle->idp, 759 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp,
760 priv_key, 760 priv_key,
761 &collect_error_cb, 761 &collect_error_cb,
762 handle, 762 handle,
@@ -780,7 +780,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
780 struct RequestHandle *handle = cls; 780 struct RequestHandle *handle = cls;
781 struct EgoEntry *ego_entry; 781 struct EgoEntry *ego_entry;
782 struct MHD_Response *resp; 782 struct MHD_Response *resp;
783 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 783 struct GNUNET_RECLAIM_Ticket ticket;
784 struct GNUNET_JSONAPI_Document *json_obj; 784 struct GNUNET_JSONAPI_Document *json_obj;
785 struct GNUNET_JSONAPI_Resource *json_res; 785 struct GNUNET_JSONAPI_Resource *json_res;
786 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; 786 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk;
@@ -844,7 +844,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
844 rnd_json = GNUNET_JSONAPI_resource_read_attr (json_res, 844 rnd_json = GNUNET_JSONAPI_resource_read_attr (json_res,
845 "rnd"); 845 "rnd");
846 identity_json = GNUNET_JSONAPI_resource_read_attr (json_res, 846 identity_json = GNUNET_JSONAPI_resource_read_attr (json_res,
847 "identity"); 847 "issuer");
848 audience_json = GNUNET_JSONAPI_resource_read_attr (json_res, 848 audience_json = GNUNET_JSONAPI_resource_read_attr (json_res,
849 "audience"); 849 "audience");
850 rnd_str = json_string_value (rnd_json); 850 rnd_str = json_string_value (rnd_json);
@@ -884,8 +884,8 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
884 } 884 }
885 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 885 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
886 886
887 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 887 handle->idp = GNUNET_RECLAIM_connect (cfg);
888 handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_revoke (handle->idp, 888 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp,
889 identity_priv, 889 identity_priv,
890 &ticket, 890 &ticket,
891 &finished_cont, 891 &finished_cont,
@@ -896,7 +896,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
896static void 896static void
897consume_cont (void *cls, 897consume_cont (void *cls,
898 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 898 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
899 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr) 899 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
900{ 900{
901 struct RequestHandle *handle = cls; 901 struct RequestHandle *handle = cls;
902 struct GNUNET_JSONAPI_Resource *json_resource; 902 struct GNUNET_JSONAPI_Resource *json_resource;
@@ -910,7 +910,7 @@ consume_cont (void *cls,
910 910
911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", 911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n",
912 attr->name); 912 attr->name);
913 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE, 913 json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_RECLAIM_ATTRIBUTE,
914 attr->name); 914 attr->name);
915 GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource); 915 GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource);
916 916
@@ -934,7 +934,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
934 struct RequestHandle *handle = cls; 934 struct RequestHandle *handle = cls;
935 struct EgoEntry *ego_entry; 935 struct EgoEntry *ego_entry;
936 struct MHD_Response *resp; 936 struct MHD_Response *resp;
937 struct GNUNET_IDENTITY_PROVIDER_Ticket ticket; 937 struct GNUNET_RECLAIM_Ticket ticket;
938 struct GNUNET_JSONAPI_Document *json_obj; 938 struct GNUNET_JSONAPI_Document *json_obj;
939 struct GNUNET_JSONAPI_Resource *json_res; 939 struct GNUNET_JSONAPI_Resource *json_res;
940 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; 940 struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk;
@@ -1038,8 +1038,8 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
1038 } 1038 }
1039 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 1039 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1040 handle->resp_object = GNUNET_JSONAPI_document_new (); 1040 handle->resp_object = GNUNET_JSONAPI_document_new ();
1041 handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); 1041 handle->idp = GNUNET_RECLAIM_connect (cfg);
1042 handle->idp_op = GNUNET_IDENTITY_PROVIDER_ticket_consume (handle->idp, 1042 handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp,
1043 identity_priv, 1043 identity_priv,
1044 &ticket, 1044 &ticket,
1045 &consume_cont, 1045 &consume_cont,
@@ -1084,12 +1084,12 @@ init_cont (struct RequestHandle *handle)
1084{ 1084{
1085 struct GNUNET_REST_RequestHandlerError err; 1085 struct GNUNET_REST_RequestHandlerError err;
1086 static const struct GNUNET_REST_RequestHandler handlers[] = { 1086 static const struct GNUNET_REST_RequestHandler handlers[] = {
1087 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES, &list_attribute_cont}, 1087 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont},
1088 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES, &add_attribute_cont}, 1088 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont},
1089 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont}, 1089 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont},
1090 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont}, 1090 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont},
1091 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont}, 1091 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont},
1092 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_PROVIDER, 1092 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM,
1093 &options_cont}, 1093 &options_cont},
1094 GNUNET_REST_HANDLER_END 1094 GNUNET_REST_HANDLER_END
1095 }; 1095 };
@@ -1202,7 +1202,7 @@ rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1202 * @return NULL on error, otherwise the plugin context 1202 * @return NULL on error, otherwise the plugin context
1203 */ 1203 */
1204void * 1204void *
1205libgnunet_plugin_rest_identity_provider_init (void *cls) 1205libgnunet_plugin_rest_reclaim_init (void *cls)
1206{ 1206{
1207 static struct Plugin plugin; 1207 static struct Plugin plugin;
1208 struct GNUNET_REST_Plugin *api; 1208 struct GNUNET_REST_Plugin *api;
@@ -1214,7 +1214,7 @@ libgnunet_plugin_rest_identity_provider_init (void *cls)
1214 plugin.cfg = cfg; 1214 plugin.cfg = cfg;
1215 api = GNUNET_new (struct GNUNET_REST_Plugin); 1215 api = GNUNET_new (struct GNUNET_REST_Plugin);
1216 api->cls = &plugin; 1216 api->cls = &plugin;
1217 api->name = GNUNET_REST_API_NS_IDENTITY_PROVIDER; 1217 api->name = GNUNET_REST_API_NS_RECLAIM;
1218 api->process_request = &rest_identity_process_request; 1218 api->process_request = &rest_identity_process_request;
1219 GNUNET_asprintf (&allow_methods, 1219 GNUNET_asprintf (&allow_methods,
1220 "%s, %s, %s, %s, %s", 1220 "%s, %s, %s, %s, %s",
@@ -1237,7 +1237,7 @@ libgnunet_plugin_rest_identity_provider_init (void *cls)
1237 * @return always NULL 1237 * @return always NULL
1238 */ 1238 */
1239void * 1239void *
1240libgnunet_plugin_rest_identity_provider_done (void *cls) 1240libgnunet_plugin_rest_reclaim_done (void *cls)
1241{ 1241{
1242 struct GNUNET_REST_Plugin *api = cls; 1242 struct GNUNET_REST_Plugin *api = cls;
1243 struct Plugin *plugin = api->cls; 1243 struct Plugin *plugin = api->cls;
@@ -1250,4 +1250,4 @@ libgnunet_plugin_rest_identity_provider_done (void *cls)
1250 return NULL; 1250 return NULL;
1251} 1251}
1252 1252
1253/* end of plugin_rest_identity_provider.c */ 1253/* end of plugin_rest_reclaim.c */
diff --git a/src/identity-provider/identity-provider.conf b/src/reclaim/reclaim.conf
index cc50152a1..cf0a0dc5e 100644
--- a/src/identity-provider/identity-provider.conf
+++ b/src/reclaim/reclaim.conf
@@ -1,22 +1,23 @@
1[identity-provider] 1[reclaim]
2START_ON_DEMAND = NO 2START_ON_DEMAND = NO
3RUN_PER_USER = YES 3RUN_PER_USER = YES
4#PORT = 2108 4#PORT = 2108
5HOSTNAME = localhost 5HOSTNAME = localhost
6BINARY = gnunet-service-identity-provider 6BINARY = gnunet-service-reclaim
7ACCEPT_FROM = 127.0.0.1; 7ACCEPT_FROM = 127.0.0.1;
8ACCEPT_FROM6 = ::1; 8ACCEPT_FROM6 = ::1;
9UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-identity-provider.sock 9UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-reclaim.sock
10UNIX_MATCH_UID = NO 10UNIX_MATCH_UID = NO
11UNIX_MATCH_GID = YES 11UNIX_MATCH_GID = YES
12TOKEN_EXPIRATION_INTERVAL = 30 m 12TOKEN_EXPIRATION_INTERVAL = 30 m
13DATABASE = sqlite 13DATABASE = sqlite
14 14
15[identity-rest-plugin] 15[reclaim-rest-plugin]
16#ADDRESS = https://identity.gnu:8000#/login 16#ADDRESS = https://identity.gnu:8000#/login
17ADDRESS = https://reclaim.ui/#/login 17ADDRESS = https://reclaim.ui/#/login
18PSW = secret 18PSW = secret
19EXPIRATION_TIME = 3600 19JWT_SECRET = secret
20EXPIRATION_TIME = 1d
20 21
21[identity-provider-sqlite] 22[reclaim-sqlite]
22FILENAME = $GNUNET_DATA_HOME/identity-provider/sqlite.db 23FILENAME = $GNUNET_DATA_HOME/reclaim/sqlite.db
diff --git a/src/identity-provider/identity_provider.h b/src/reclaim/reclaim.h
index 6a4b7769f..d2c84686d 100644
--- a/src/identity-provider/identity_provider.h
+++ b/src/reclaim/reclaim.h
@@ -18,13 +18,13 @@
18 18
19/** 19/**
20 * @author Martin Schanzenbach 20 * @author Martin Schanzenbach
21 * @file identity-provider/identity_provider.h 21 * @file reclaim/reclaim.h
22 * 22 *
23 * @brief Common type definitions for the identity provider 23 * @brief Common type definitions for the identity provider
24 * service and API. 24 * service and API.
25 */ 25 */
26#ifndef IDENTITY_PROVIDER_H 26#ifndef RECLAIM_H
27#define IDENTITY_PROVIDER_H 27#define RECLAIM_H
28 28
29#include "gnunet_common.h" 29#include "gnunet_common.h"
30 30
@@ -152,7 +152,7 @@ struct AttributeIterationStartMessage
152struct AttributeIterationNextMessage 152struct AttributeIterationNextMessage
153{ 153{
154 /** 154 /**
155 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_NEXT 155 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT
156 */ 156 */
157 struct GNUNET_MessageHeader header; 157 struct GNUNET_MessageHeader header;
158 158
@@ -170,7 +170,7 @@ struct AttributeIterationNextMessage
170struct AttributeIterationStopMessage 170struct AttributeIterationStopMessage
171{ 171{
172 /** 172 /**
173 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_STOP 173 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP
174 */ 174 */
175 struct GNUNET_MessageHeader header; 175 struct GNUNET_MessageHeader header;
176 176
@@ -214,7 +214,7 @@ struct TicketIterationStartMessage
214struct TicketIterationNextMessage 214struct TicketIterationNextMessage
215{ 215{
216 /** 216 /**
217 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT 217 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT
218 */ 218 */
219 struct GNUNET_MessageHeader header; 219 struct GNUNET_MessageHeader header;
220 220
@@ -232,7 +232,7 @@ struct TicketIterationNextMessage
232struct TicketIterationStopMessage 232struct TicketIterationStopMessage
233{ 233{
234 /** 234 /**
235 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP 235 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP
236 */ 236 */
237 struct GNUNET_MessageHeader header; 237 struct GNUNET_MessageHeader header;
238 238
@@ -251,7 +251,7 @@ struct TicketIterationStopMessage
251struct IssueTicketMessage 251struct IssueTicketMessage
252{ 252{
253 /** 253 /**
254 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET 254 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET
255 */ 255 */
256 struct GNUNET_MessageHeader header; 256 struct GNUNET_MessageHeader header;
257 257
@@ -284,7 +284,7 @@ struct IssueTicketMessage
284struct RevokeTicketMessage 284struct RevokeTicketMessage
285{ 285{
286 /** 286 /**
287 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET 287 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET
288 */ 288 */
289 struct GNUNET_MessageHeader header; 289 struct GNUNET_MessageHeader header;
290 290
@@ -312,7 +312,7 @@ struct RevokeTicketMessage
312struct RevokeTicketResultMessage 312struct RevokeTicketResultMessage
313{ 313{
314 /** 314 /**
315 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT 315 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT
316 */ 316 */
317 struct GNUNET_MessageHeader header; 317 struct GNUNET_MessageHeader header;
318 318
@@ -334,7 +334,7 @@ struct RevokeTicketResultMessage
334struct TicketResultMessage 334struct TicketResultMessage
335{ 335{
336 /** 336 /**
337 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT 337 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
338 */ 338 */
339 struct GNUNET_MessageHeader header; 339 struct GNUNET_MessageHeader header;
340 340
@@ -351,7 +351,7 @@ struct TicketResultMessage
351struct ConsumeTicketMessage 351struct ConsumeTicketMessage
352{ 352{
353 /** 353 /**
354 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET 354 * Type will be #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET
355 */ 355 */
356 struct GNUNET_MessageHeader header; 356 struct GNUNET_MessageHeader header;
357 357
diff --git a/src/identity-provider/identity_provider_api.c b/src/reclaim/reclaim_api.c
index 772b4a244..3f1584ccd 100644
--- a/src/identity-provider/identity_provider_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -17,8 +17,8 @@
17*/ 17*/
18 18
19/** 19/**
20 * @file identity-provider/identity_provider_api.c 20 * @file reclaim/reclaim_api.c
21 * @brief api to interact with the identity provider service 21 * @brief api to interact with the reclaim service
22 * @author Martin Schanzenbach 22 * @author Martin Schanzenbach
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
@@ -26,33 +26,33 @@
26#include "gnunet_constants.h" 26#include "gnunet_constants.h"
27#include "gnunet_protocols.h" 27#include "gnunet_protocols.h"
28#include "gnunet_mq_lib.h" 28#include "gnunet_mq_lib.h"
29#include "gnunet_identity_provider_service.h" 29#include "gnunet_reclaim_service.h"
30#include "gnunet_identity_attribute_lib.h" 30#include "gnunet_reclaim_attribute_lib.h"
31#include "identity_provider.h" 31#include "reclaim.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__) 33#define LOG(kind,...) GNUNET_log_from (kind, "reclaim-api",__VA_ARGS__)
34 34
35 35
36/** 36/**
37 * Handle for an operation with the service. 37 * Handle for an operation with the service.
38 */ 38 */
39struct GNUNET_IDENTITY_PROVIDER_Operation 39struct GNUNET_RECLAIM_Operation
40{ 40{
41 41
42 /** 42 /**
43 * Main handle. 43 * Main handle.
44 */ 44 */
45 struct GNUNET_IDENTITY_PROVIDER_Handle *h; 45 struct GNUNET_RECLAIM_Handle *h;
46 46
47 /** 47 /**
48 * We keep operations in a DLL. 48 * We keep operations in a DLL.
49 */ 49 */
50 struct GNUNET_IDENTITY_PROVIDER_Operation *next; 50 struct GNUNET_RECLAIM_Operation *next;
51 51
52 /** 52 /**
53 * We keep operations in a DLL. 53 * We keep operations in a DLL.
54 */ 54 */
55 struct GNUNET_IDENTITY_PROVIDER_Operation *prev; 55 struct GNUNET_RECLAIM_Operation *prev;
56 56
57 /** 57 /**
58 * Message to send to the service. 58 * Message to send to the service.
@@ -63,22 +63,22 @@ struct GNUNET_IDENTITY_PROVIDER_Operation
63 /** 63 /**
64 * Continuation to invoke after attribute store call 64 * Continuation to invoke after attribute store call
65 */ 65 */
66 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus as_cb; 66 GNUNET_RECLAIM_ContinuationWithStatus as_cb;
67 67
68 /** 68 /**
69 * Attribute result callback 69 * Attribute result callback
70 */ 70 */
71 GNUNET_IDENTITY_PROVIDER_AttributeResult ar_cb; 71 GNUNET_RECLAIM_AttributeResult ar_cb;
72 72
73 /** 73 /**
74 * Revocation result callback 74 * Revocation result callback
75 */ 75 */
76 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus rvk_cb; 76 GNUNET_RECLAIM_ContinuationWithStatus rvk_cb;
77 77
78 /** 78 /**
79 * Ticket result callback 79 * Ticket result callback
80 */ 80 */
81 GNUNET_IDENTITY_PROVIDER_TicketCallback tr_cb; 81 GNUNET_RECLAIM_TicketCallback tr_cb;
82 82
83 /** 83 /**
84 * Envelope with the message for this queue entry. 84 * Envelope with the message for this queue entry.
@@ -100,23 +100,23 @@ struct GNUNET_IDENTITY_PROVIDER_Operation
100/** 100/**
101 * Handle for a ticket iterator operation 101 * Handle for a ticket iterator operation
102 */ 102 */
103struct GNUNET_IDENTITY_PROVIDER_TicketIterator 103struct GNUNET_RECLAIM_TicketIterator
104{ 104{
105 105
106 /** 106 /**
107 * Kept in a DLL. 107 * Kept in a DLL.
108 */ 108 */
109 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *next; 109 struct GNUNET_RECLAIM_TicketIterator *next;
110 110
111 /** 111 /**
112 * Kept in a DLL. 112 * Kept in a DLL.
113 */ 113 */
114 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *prev; 114 struct GNUNET_RECLAIM_TicketIterator *prev;
115 115
116 /** 116 /**
117 * Main handle to access the idp. 117 * Main handle to access the idp.
118 */ 118 */
119 struct GNUNET_IDENTITY_PROVIDER_Handle *h; 119 struct GNUNET_RECLAIM_Handle *h;
120 120
121 /** 121 /**
122 * Function to call on completion. 122 * Function to call on completion.
@@ -131,7 +131,7 @@ struct GNUNET_IDENTITY_PROVIDER_TicketIterator
131 /** 131 /**
132 * The continuation to call with the results 132 * The continuation to call with the results
133 */ 133 */
134 GNUNET_IDENTITY_PROVIDER_TicketCallback tr_cb; 134 GNUNET_RECLAIM_TicketCallback tr_cb;
135 135
136 /** 136 /**
137 * Closure for @e tr_cb. 137 * Closure for @e tr_cb.
@@ -165,23 +165,23 @@ struct GNUNET_IDENTITY_PROVIDER_TicketIterator
165/** 165/**
166 * Handle for a attribute iterator operation 166 * Handle for a attribute iterator operation
167 */ 167 */
168struct GNUNET_IDENTITY_PROVIDER_AttributeIterator 168struct GNUNET_RECLAIM_AttributeIterator
169{ 169{
170 170
171 /** 171 /**
172 * Kept in a DLL. 172 * Kept in a DLL.
173 */ 173 */
174 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *next; 174 struct GNUNET_RECLAIM_AttributeIterator *next;
175 175
176 /** 176 /**
177 * Kept in a DLL. 177 * Kept in a DLL.
178 */ 178 */
179 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *prev; 179 struct GNUNET_RECLAIM_AttributeIterator *prev;
180 180
181 /** 181 /**
182 * Main handle to access the idp. 182 * Main handle to access the idp.
183 */ 183 */
184 struct GNUNET_IDENTITY_PROVIDER_Handle *h; 184 struct GNUNET_RECLAIM_Handle *h;
185 185
186 /** 186 /**
187 * Function to call on completion. 187 * Function to call on completion.
@@ -196,7 +196,7 @@ struct GNUNET_IDENTITY_PROVIDER_AttributeIterator
196 /** 196 /**
197 * The continuation to call with the results 197 * The continuation to call with the results
198 */ 198 */
199 GNUNET_IDENTITY_PROVIDER_AttributeResult proc; 199 GNUNET_RECLAIM_AttributeResult proc;
200 200
201 /** 201 /**
202 * Closure for @e proc. 202 * Closure for @e proc.
@@ -235,7 +235,7 @@ struct GNUNET_IDENTITY_PROVIDER_AttributeIterator
235/** 235/**
236 * Handle for the service. 236 * Handle for the service.
237 */ 237 */
238struct GNUNET_IDENTITY_PROVIDER_Handle 238struct GNUNET_RECLAIM_Handle
239{ 239{
240 /** 240 /**
241 * Configuration to use. 241 * Configuration to use.
@@ -255,32 +255,32 @@ struct GNUNET_IDENTITY_PROVIDER_Handle
255 /** 255 /**
256 * Head of active operations. 256 * Head of active operations.
257 */ 257 */
258 struct GNUNET_IDENTITY_PROVIDER_Operation *op_head; 258 struct GNUNET_RECLAIM_Operation *op_head;
259 259
260 /** 260 /**
261 * Tail of active operations. 261 * Tail of active operations.
262 */ 262 */
263 struct GNUNET_IDENTITY_PROVIDER_Operation *op_tail; 263 struct GNUNET_RECLAIM_Operation *op_tail;
264 264
265 /** 265 /**
266 * Head of active iterations 266 * Head of active iterations
267 */ 267 */
268 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_head; 268 struct GNUNET_RECLAIM_AttributeIterator *it_head;
269 269
270 /** 270 /**
271 * Tail of active iterations 271 * Tail of active iterations
272 */ 272 */
273 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_tail; 273 struct GNUNET_RECLAIM_AttributeIterator *it_tail;
274 274
275 /** 275 /**
276 * Head of active iterations 276 * Head of active iterations
277 */ 277 */
278 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_head; 278 struct GNUNET_RECLAIM_TicketIterator *ticket_it_head;
279 279
280 /** 280 /**
281 * Tail of active iterations 281 * Tail of active iterations
282 */ 282 */
283 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_tail; 283 struct GNUNET_RECLAIM_TicketIterator *ticket_it_tail;
284 284
285 285
286 /** 286 /**
@@ -318,10 +318,10 @@ struct GNUNET_IDENTITY_PROVIDER_Handle
318/** 318/**
319 * Try again to connect to the service. 319 * Try again to connect to the service.
320 * 320 *
321 * @param h handle to the identity provider service. 321 * @param h handle to the reclaim service.
322 */ 322 */
323static void 323static void
324reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h); 324reconnect (struct GNUNET_RECLAIM_Handle *h);
325 325
326/** 326/**
327 * Reconnect 327 * Reconnect
@@ -331,7 +331,7 @@ reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h);
331static void 331static void
332reconnect_task (void *cls) 332reconnect_task (void *cls)
333{ 333{
334 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls; 334 struct GNUNET_RECLAIM_Handle *handle = cls;
335 335
336 handle->reconnect_task = NULL; 336 handle->reconnect_task = NULL;
337 reconnect (handle); 337 reconnect (handle);
@@ -344,7 +344,7 @@ reconnect_task (void *cls)
344 * @param handle our service 344 * @param handle our service
345 */ 345 */
346static void 346static void
347force_reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle) 347force_reconnect (struct GNUNET_RECLAIM_Handle *handle)
348{ 348{
349 GNUNET_MQ_destroy (handle->mq); 349 GNUNET_MQ_destroy (handle->mq);
350 handle->mq = NULL; 350 handle->mq = NULL;
@@ -362,9 +362,9 @@ force_reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *handle)
362 * @param it entry to free 362 * @param it entry to free
363 */ 363 */
364static void 364static void
365free_it (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it) 365free_it (struct GNUNET_RECLAIM_AttributeIterator *it)
366{ 366{
367 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h; 367 struct GNUNET_RECLAIM_Handle *h = it->h;
368 368
369 GNUNET_CONTAINER_DLL_remove (h->it_head, 369 GNUNET_CONTAINER_DLL_remove (h->it_head,
370 h->it_tail, 370 h->it_tail,
@@ -375,7 +375,7 @@ free_it (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it)
375} 375}
376 376
377static void 377static void
378free_op (struct GNUNET_IDENTITY_PROVIDER_Operation* op) 378free_op (struct GNUNET_RECLAIM_Operation* op)
379{ 379{
380 if (NULL == op) 380 if (NULL == op)
381 return; 381 return;
@@ -397,7 +397,7 @@ static void
397mq_error_handler (void *cls, 397mq_error_handler (void *cls,
398 enum GNUNET_MQ_Error error) 398 enum GNUNET_MQ_Error error)
399{ 399{
400 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls; 400 struct GNUNET_RECLAIM_Handle *handle = cls;
401 force_reconnect (handle); 401 force_reconnect (handle);
402} 402}
403 403
@@ -412,8 +412,8 @@ static void
412handle_attribute_store_response (void *cls, 412handle_attribute_store_response (void *cls,
413 const struct AttributeStoreResultMessage *msg) 413 const struct AttributeStoreResultMessage *msg)
414{ 414{
415 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls; 415 struct GNUNET_RECLAIM_Handle *h = cls;
416 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 416 struct GNUNET_RECLAIM_Operation *op;
417 uint32_t r_id = ntohl (msg->id); 417 uint32_t r_id = ntohl (msg->id);
418 int res; 418 int res;
419 const char *emsg; 419 const char *emsg;
@@ -448,7 +448,7 @@ handle_attribute_store_response (void *cls,
448 448
449/** 449/**
450 * Handle an incoming message of type 450 * Handle an incoming message of type
451 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT 451 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
452 * 452 *
453 * @param cls 453 * @param cls
454 * @param msg the message we received 454 * @param msg the message we received
@@ -474,7 +474,7 @@ check_consume_ticket_result (void *cls,
474 474
475/** 475/**
476 * Handle an incoming message of type 476 * Handle an incoming message of type
477 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT 477 * #GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT
478 * 478 *
479 * @param cls 479 * @param cls
480 * @param msg the message we received 480 * @param msg the message we received
@@ -483,8 +483,8 @@ static void
483handle_consume_ticket_result (void *cls, 483handle_consume_ticket_result (void *cls,
484 const struct ConsumeTicketResultMessage *msg) 484 const struct ConsumeTicketResultMessage *msg)
485{ 485{
486 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls; 486 struct GNUNET_RECLAIM_Handle *h = cls;
487 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 487 struct GNUNET_RECLAIM_Operation *op;
488 size_t attrs_len; 488 size_t attrs_len;
489 uint32_t r_id = ntohl (msg->id); 489 uint32_t r_id = ntohl (msg->id);
490 490
@@ -500,9 +500,9 @@ handle_consume_ticket_result (void *cls,
500 return; 500 return;
501 501
502 { 502 {
503 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs; 503 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
504 struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; 504 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
505 attrs = GNUNET_IDENTITY_ATTRIBUTE_list_deserialize ((char*)&msg[1], 505 attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char*)&msg[1],
506 attrs_len); 506 attrs_len);
507 if (NULL != op->ar_cb) 507 if (NULL != op->ar_cb)
508 { 508 {
@@ -518,7 +518,7 @@ handle_consume_ticket_result (void *cls,
518 op->ar_cb (op->cls, 518 op->ar_cb (op->cls,
519 &msg->identity, 519 &msg->identity,
520 le->claim); 520 le->claim);
521 GNUNET_IDENTITY_ATTRIBUTE_list_destroy (attrs); 521 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs);
522 } 522 }
523 } 523 }
524 if (NULL != op) 524 if (NULL != op)
@@ -539,7 +539,7 @@ handle_consume_ticket_result (void *cls,
539 539
540/** 540/**
541 * Handle an incoming message of type 541 * Handle an incoming message of type
542 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT 542 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
543 * 543 *
544 * @param cls 544 * @param cls
545 * @param msg the message we received 545 * @param msg the message we received
@@ -565,7 +565,7 @@ check_attribute_result (void *cls,
565 565
566/** 566/**
567 * Handle an incoming message of type 567 * Handle an incoming message of type
568 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT 568 * #GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT
569 * 569 *
570 * @param cls 570 * @param cls
571 * @param msg the message we received 571 * @param msg the message we received
@@ -575,9 +575,9 @@ handle_attribute_result (void *cls,
575 const struct AttributeResultMessage *msg) 575 const struct AttributeResultMessage *msg)
576{ 576{
577 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; 577 static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
578 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls; 578 struct GNUNET_RECLAIM_Handle *h = cls;
579 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it; 579 struct GNUNET_RECLAIM_AttributeIterator *it;
580 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 580 struct GNUNET_RECLAIM_Operation *op;
581 size_t attr_len; 581 size_t attr_len;
582 uint32_t r_id = ntohl (msg->id); 582 uint32_t r_id = ntohl (msg->id);
583 583
@@ -627,8 +627,8 @@ handle_attribute_result (void *cls,
627 } 627 }
628 628
629 { 629 {
630 struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr; 630 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
631 attr = GNUNET_IDENTITY_ATTRIBUTE_deserialize ((char*)&msg[1], 631 attr = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char*)&msg[1],
632 attr_len); 632 attr_len);
633 if (NULL != it) 633 if (NULL != it)
634 { 634 {
@@ -652,7 +652,7 @@ handle_attribute_result (void *cls,
652 652
653/** 653/**
654 * Handle an incoming message of type 654 * Handle an incoming message of type
655 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT 655 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
656 * 656 *
657 * @param cls 657 * @param cls
658 * @param msg the message we received 658 * @param msg the message we received
@@ -677,7 +677,7 @@ check_ticket_result (void *cls,
677 677
678/** 678/**
679 * Handle an incoming message of type 679 * Handle an incoming message of type
680 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT 680 * #GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT
681 * 681 *
682 * @param cls 682 * @param cls
683 * @param msg the message we received 683 * @param msg the message we received
@@ -686,10 +686,10 @@ static void
686handle_ticket_result (void *cls, 686handle_ticket_result (void *cls,
687 const struct TicketResultMessage *msg) 687 const struct TicketResultMessage *msg)
688{ 688{
689 struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls; 689 struct GNUNET_RECLAIM_Handle *handle = cls;
690 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 690 struct GNUNET_RECLAIM_Operation *op;
691 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it; 691 struct GNUNET_RECLAIM_TicketIterator *it;
692 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket; 692 const struct GNUNET_RECLAIM_Ticket *ticket;
693 uint32_t r_id = ntohl (msg->id); 693 uint32_t r_id = ntohl (msg->id);
694 size_t msg_len; 694 size_t msg_len;
695 695
@@ -712,7 +712,7 @@ handle_ticket_result (void *cls,
712 if (NULL != op->tr_cb) 712 if (NULL != op->tr_cb)
713 op->tr_cb (op->cls, NULL); 713 op->tr_cb (op->cls, NULL);
714 } else { 714 } else {
715 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1]; 715 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
716 if (NULL != op->tr_cb) 716 if (NULL != op->tr_cb)
717 op->tr_cb (op->cls, ticket); 717 op->tr_cb (op->cls, ticket);
718 } 718 }
@@ -728,7 +728,7 @@ handle_ticket_result (void *cls,
728 it->finish_cb (it->finish_cb_cls); 728 it->finish_cb (it->finish_cb_cls);
729 GNUNET_free (it); 729 GNUNET_free (it);
730 } else { 730 } else {
731 ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket *)&msg[1]; 731 ticket = (struct GNUNET_RECLAIM_Ticket *)&msg[1];
732 if (NULL != it->tr_cb) 732 if (NULL != it->tr_cb)
733 it->tr_cb (it->cls, ticket); 733 it->tr_cb (it->cls, ticket);
734 } 734 }
@@ -740,7 +740,7 @@ handle_ticket_result (void *cls,
740 740
741/** 741/**
742 * Handle an incoming message of type 742 * Handle an incoming message of type
743 * #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT 743 * #GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT
744 * 744 *
745 * @param cls 745 * @param cls
746 * @param msg the message we received 746 * @param msg the message we received
@@ -749,8 +749,8 @@ static void
749handle_revoke_ticket_result (void *cls, 749handle_revoke_ticket_result (void *cls,
750 const struct RevokeTicketResultMessage *msg) 750 const struct RevokeTicketResultMessage *msg)
751{ 751{
752 struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls; 752 struct GNUNET_RECLAIM_Handle *h = cls;
753 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 753 struct GNUNET_RECLAIM_Operation *op;
754 uint32_t r_id = ntohl (msg->id); 754 uint32_t r_id = ntohl (msg->id);
755 int32_t success; 755 int32_t success;
756 756
@@ -785,42 +785,42 @@ handle_revoke_ticket_result (void *cls,
785/** 785/**
786 * Try again to connect to the service. 786 * Try again to connect to the service.
787 * 787 *
788 * @param h handle to the identity provider service. 788 * @param h handle to the reclaim service.
789 */ 789 */
790static void 790static void
791reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) 791reconnect (struct GNUNET_RECLAIM_Handle *h)
792{ 792{
793 struct GNUNET_MQ_MessageHandler handlers[] = { 793 struct GNUNET_MQ_MessageHandler handlers[] = {
794 GNUNET_MQ_hd_fixed_size (attribute_store_response, 794 GNUNET_MQ_hd_fixed_size (attribute_store_response,
795 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE, 795 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE_RESPONSE,
796 struct AttributeStoreResultMessage, 796 struct AttributeStoreResultMessage,
797 h), 797 h),
798 GNUNET_MQ_hd_var_size (attribute_result, 798 GNUNET_MQ_hd_var_size (attribute_result,
799 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_RESULT, 799 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT,
800 struct AttributeResultMessage, 800 struct AttributeResultMessage,
801 h), 801 h),
802 GNUNET_MQ_hd_var_size (ticket_result, 802 GNUNET_MQ_hd_var_size (ticket_result,
803 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT, 803 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT,
804 struct TicketResultMessage, 804 struct TicketResultMessage,
805 h), 805 h),
806 GNUNET_MQ_hd_var_size (consume_ticket_result, 806 GNUNET_MQ_hd_var_size (consume_ticket_result,
807 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT, 807 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT,
808 struct ConsumeTicketResultMessage, 808 struct ConsumeTicketResultMessage,
809 h), 809 h),
810 GNUNET_MQ_hd_fixed_size (revoke_ticket_result, 810 GNUNET_MQ_hd_fixed_size (revoke_ticket_result,
811 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT, 811 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT,
812 struct RevokeTicketResultMessage, 812 struct RevokeTicketResultMessage,
813 h), 813 h),
814 GNUNET_MQ_handler_end () 814 GNUNET_MQ_handler_end ()
815 }; 815 };
816 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 816 struct GNUNET_RECLAIM_Operation *op;
817 817
818 GNUNET_assert (NULL == h->mq); 818 GNUNET_assert (NULL == h->mq);
819 LOG (GNUNET_ERROR_TYPE_DEBUG, 819 LOG (GNUNET_ERROR_TYPE_DEBUG,
820 "Connecting to identity provider service.\n"); 820 "Connecting to reclaim service.\n");
821 821
822 h->mq = GNUNET_CLIENT_connect (h->cfg, 822 h->mq = GNUNET_CLIENT_connect (h->cfg,
823 "identity-provider", 823 "reclaim",
824 handlers, 824 handlers,
825 &mq_error_handler, 825 &mq_error_handler,
826 h); 826 h);
@@ -833,17 +833,17 @@ reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
833 833
834 834
835/** 835/**
836 * Connect to the identity provider service. 836 * Connect to the reclaim service.
837 * 837 *
838 * @param cfg the configuration to use 838 * @param cfg the configuration to use
839 * @return handle to use 839 * @return handle to use
840 */ 840 */
841struct GNUNET_IDENTITY_PROVIDER_Handle * 841struct GNUNET_RECLAIM_Handle *
842GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 842GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
843{ 843{
844 struct GNUNET_IDENTITY_PROVIDER_Handle *h; 844 struct GNUNET_RECLAIM_Handle *h;
845 845
846 h = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Handle); 846 h = GNUNET_new (struct GNUNET_RECLAIM_Handle);
847 h->cfg = cfg; 847 h->cfg = cfg;
848 reconnect (h); 848 reconnect (h);
849 if (NULL == h->mq) 849 if (NULL == h->mq)
@@ -864,9 +864,9 @@ GNUNET_IDENTITY_PROVIDER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
864 * @param op operation to cancel 864 * @param op operation to cancel
865 */ 865 */
866void 866void
867GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op) 867GNUNET_RECLAIM_cancel (struct GNUNET_RECLAIM_Operation *op)
868{ 868{
869 struct GNUNET_IDENTITY_PROVIDER_Handle *h = op->h; 869 struct GNUNET_RECLAIM_Handle *h = op->h;
870 870
871 GNUNET_CONTAINER_DLL_remove (h->op_head, 871 GNUNET_CONTAINER_DLL_remove (h->op_head,
872 h->op_tail, 872 h->op_tail,
@@ -881,7 +881,7 @@ GNUNET_IDENTITY_PROVIDER_cancel (struct GNUNET_IDENTITY_PROVIDER_Operation *op)
881 * @param h handle to destroy 881 * @param h handle to destroy
882 */ 882 */
883void 883void
884GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) 884GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h)
885{ 885{
886 GNUNET_assert (NULL != h); 886 GNUNET_assert (NULL != h);
887 if (NULL != h->mq) 887 if (NULL != h->mq)
@@ -902,7 +902,7 @@ GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
902 * Store an attribute. If the attribute is already present, 902 * Store an attribute. If the attribute is already present,
903 * it is replaced with the new attribute. 903 * it is replaced with the new attribute.
904 * 904 *
905 * @param h handle to the identity provider 905 * @param h handle to the reclaim
906 * @param pkey private key of the identity 906 * @param pkey private key of the identity
907 * @param attr the attribute value 907 * @param attr the attribute value
908 * @param exp_interval the relative expiration interval for the attribute 908 * @param exp_interval the relative expiration interval for the attribute
@@ -910,19 +910,19 @@ GNUNET_IDENTITY_PROVIDER_disconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h)
910 * @param cont_cls closure for @a cont 910 * @param cont_cls closure for @a cont
911 * @return handle to abort the request 911 * @return handle to abort the request
912 */ 912 */
913struct GNUNET_IDENTITY_PROVIDER_Operation * 913struct GNUNET_RECLAIM_Operation *
914GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 914GNUNET_RECLAIM_attribute_store (struct GNUNET_RECLAIM_Handle *h,
915 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 915 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
916 const struct GNUNET_IDENTITY_ATTRIBUTE_Claim *attr, 916 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
917 const struct GNUNET_TIME_Relative *exp_interval, 917 const struct GNUNET_TIME_Relative *exp_interval,
918 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont, 918 GNUNET_RECLAIM_ContinuationWithStatus cont,
919 void *cont_cls) 919 void *cont_cls)
920{ 920{
921 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 921 struct GNUNET_RECLAIM_Operation *op;
922 struct AttributeStoreMessage *sam; 922 struct AttributeStoreMessage *sam;
923 size_t attr_len; 923 size_t attr_len;
924 924
925 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation); 925 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
926 op->h = h; 926 op->h = h;
927 op->as_cb = cont; 927 op->as_cb = cont;
928 op->cls = cont_cls; 928 op->cls = cont_cls;
@@ -930,15 +930,15 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
930 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 930 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
931 h->op_tail, 931 h->op_tail,
932 op); 932 op);
933 attr_len = GNUNET_IDENTITY_ATTRIBUTE_serialize_get_size (attr); 933 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (attr);
934 op->env = GNUNET_MQ_msg_extra (sam, 934 op->env = GNUNET_MQ_msg_extra (sam,
935 attr_len, 935 attr_len,
936 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE); 936 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE);
937 sam->identity = *pkey; 937 sam->identity = *pkey;
938 sam->id = htonl (op->r_id); 938 sam->id = htonl (op->r_id);
939 sam->exp = GNUNET_htonll (exp_interval->rel_value_us); 939 sam->exp = GNUNET_htonll (exp_interval->rel_value_us);
940 940
941 GNUNET_IDENTITY_ATTRIBUTE_serialize (attr, 941 GNUNET_RECLAIM_ATTRIBUTE_serialize (attr,
942 (char*)&sam[1]); 942 (char*)&sam[1]);
943 943
944 sam->attr_len = htons (attr_len); 944 sam->attr_len = htons (attr_len);
@@ -952,11 +952,11 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
952 952
953/** 953/**
954 * List all attributes for a local identity. 954 * List all attributes for a local identity.
955 * This MUST lock the `struct GNUNET_IDENTITY_PROVIDER_Handle` 955 * This MUST lock the `struct GNUNET_RECLAIM_Handle`
956 * for any other calls than #GNUNET_IDENTITY_PROVIDER_get_attributes_next() and 956 * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and
957 * #GNUNET_IDENTITY_PROVIDER_get_attributes_stop. @a proc will be called once 957 * #GNUNET_RECLAIM_get_attributes_stop. @a proc will be called once
958 * immediately, and then again after 958 * immediately, and then again after
959 * #GNUNET_IDENTITY_PROVIDER_get_attributes_next() is invoked. 959 * #GNUNET_RECLAIM_get_attributes_next() is invoked.
960 * 960 *
961 * On error (disconnect), @a error_cb will be invoked. 961 * On error (disconnect), @a error_cb will be invoked.
962 * On normal completion, @a finish_cb proc will be 962 * On normal completion, @a finish_cb proc will be
@@ -975,23 +975,23 @@ GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle
975 * @param finish_cb_cls closure for @a finish_cb 975 * @param finish_cb_cls closure for @a finish_cb
976 * @return an iterator handle to use for iteration 976 * @return an iterator handle to use for iteration
977 */ 977 */
978struct GNUNET_IDENTITY_PROVIDER_AttributeIterator * 978struct GNUNET_RECLAIM_AttributeIterator *
979GNUNET_IDENTITY_PROVIDER_get_attributes_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 979GNUNET_RECLAIM_get_attributes_start (struct GNUNET_RECLAIM_Handle *h,
980 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 980 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
981 GNUNET_SCHEDULER_TaskCallback error_cb, 981 GNUNET_SCHEDULER_TaskCallback error_cb,
982 void *error_cb_cls, 982 void *error_cb_cls,
983 GNUNET_IDENTITY_PROVIDER_AttributeResult proc, 983 GNUNET_RECLAIM_AttributeResult proc,
984 void *proc_cls, 984 void *proc_cls,
985 GNUNET_SCHEDULER_TaskCallback finish_cb, 985 GNUNET_SCHEDULER_TaskCallback finish_cb,
986 void *finish_cb_cls) 986 void *finish_cb_cls)
987{ 987{
988 struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it; 988 struct GNUNET_RECLAIM_AttributeIterator *it;
989 struct GNUNET_MQ_Envelope *env; 989 struct GNUNET_MQ_Envelope *env;
990 struct AttributeIterationStartMessage *msg; 990 struct AttributeIterationStartMessage *msg;
991 uint32_t rid; 991 uint32_t rid;
992 992
993 rid = h->r_id_gen++; 993 rid = h->r_id_gen++;
994 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator); 994 it = GNUNET_new (struct GNUNET_RECLAIM_AttributeIterator);
995 it->h = h; 995 it->h = h;
996 it->error_cb = error_cb; 996 it->error_cb = error_cb;
997 it->error_cb_cls = error_cb_cls; 997 it->error_cb_cls = error_cb_cls;
@@ -1005,7 +1005,7 @@ GNUNET_IDENTITY_PROVIDER_get_attributes_start (struct GNUNET_IDENTITY_PROVIDER_H
1005 h->it_tail, 1005 h->it_tail,
1006 it); 1006 it);
1007 env = GNUNET_MQ_msg (msg, 1007 env = GNUNET_MQ_msg (msg,
1008 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_START); 1008 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START);
1009 msg->id = htonl (rid); 1009 msg->id = htonl (rid);
1010 msg->identity = *identity; 1010 msg->identity = *identity;
1011 if (NULL == h->mq) 1011 if (NULL == h->mq)
@@ -1018,20 +1018,20 @@ GNUNET_IDENTITY_PROVIDER_get_attributes_start (struct GNUNET_IDENTITY_PROVIDER_H
1018 1018
1019 1019
1020/** 1020/**
1021 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_get_attributes_start 1021 * Calls the record processor specified in #GNUNET_RECLAIM_get_attributes_start
1022 * for the next record. 1022 * for the next record.
1023 * 1023 *
1024 * @param it the iterator 1024 * @param it the iterator
1025 */ 1025 */
1026void 1026void
1027GNUNET_IDENTITY_PROVIDER_get_attributes_next (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it) 1027GNUNET_RECLAIM_get_attributes_next (struct GNUNET_RECLAIM_AttributeIterator *it)
1028{ 1028{
1029 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h; 1029 struct GNUNET_RECLAIM_Handle *h = it->h;
1030 struct AttributeIterationNextMessage *msg; 1030 struct AttributeIterationNextMessage *msg;
1031 struct GNUNET_MQ_Envelope *env; 1031 struct GNUNET_MQ_Envelope *env;
1032 1032
1033 env = GNUNET_MQ_msg (msg, 1033 env = GNUNET_MQ_msg (msg,
1034 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_NEXT); 1034 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT);
1035 msg->id = htonl (it->r_id); 1035 msg->id = htonl (it->r_id);
1036 GNUNET_MQ_send (h->mq, 1036 GNUNET_MQ_send (h->mq,
1037 env); 1037 env);
@@ -1041,21 +1041,21 @@ GNUNET_IDENTITY_PROVIDER_get_attributes_next (struct GNUNET_IDENTITY_PROVIDER_At
1041/** 1041/**
1042 * Stops iteration and releases the idp handle for further calls. Must 1042 * Stops iteration and releases the idp handle for further calls. Must
1043 * be called on any iteration that has not yet completed prior to calling 1043 * be called on any iteration that has not yet completed prior to calling
1044 * #GNUNET_IDENTITY_PROVIDER_disconnect. 1044 * #GNUNET_RECLAIM_disconnect.
1045 * 1045 *
1046 * @param it the iterator 1046 * @param it the iterator
1047 */ 1047 */
1048void 1048void
1049GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it) 1049GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it)
1050{ 1050{
1051 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h; 1051 struct GNUNET_RECLAIM_Handle *h = it->h;
1052 struct GNUNET_MQ_Envelope *env; 1052 struct GNUNET_MQ_Envelope *env;
1053 struct AttributeIterationStopMessage *msg; 1053 struct AttributeIterationStopMessage *msg;
1054 1054
1055 if (NULL != h->mq) 1055 if (NULL != h->mq)
1056 { 1056 {
1057 env = GNUNET_MQ_msg (msg, 1057 env = GNUNET_MQ_msg (msg,
1058 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_ITERATION_STOP); 1058 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP);
1059 msg->id = htonl (it->r_id); 1059 msg->id = htonl (it->r_id);
1060 GNUNET_MQ_send (h->mq, 1060 GNUNET_MQ_send (h->mq,
1061 env); 1061 env);
@@ -1066,10 +1066,10 @@ GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_At
1066 1066
1067/** TODO 1067/** TODO
1068 * Issues a ticket to another identity. The identity may use 1068 * Issues a ticket to another identity. The identity may use
1069 * @GNUNET_IDENTITY_PROVIDER_authorization_ticket_consume to consume the ticket 1069 * @GNUNET_RECLAIM_authorization_ticket_consume to consume the ticket
1070 * and retrieve the attributes specified in the AttributeList. 1070 * and retrieve the attributes specified in the AttributeList.
1071 * 1071 *
1072 * @param h the identity provider to use 1072 * @param h the reclaim to use
1073 * @param iss the issuing identity 1073 * @param iss the issuing identity
1074 * @param rp the subject of the ticket (the relying party) 1074 * @param rp the subject of the ticket (the relying party)
1075 * @param attrs the attributes that the relying party is given access to 1075 * @param attrs the attributes that the relying party is given access to
@@ -1077,19 +1077,19 @@ GNUNET_IDENTITY_PROVIDER_get_attributes_stop (struct GNUNET_IDENTITY_PROVIDER_At
1077 * @param cb_cls the callback closure 1077 * @param cb_cls the callback closure
1078 * @return handle to abort the operation 1078 * @return handle to abort the operation
1079 */ 1079 */
1080struct GNUNET_IDENTITY_PROVIDER_Operation * 1080struct GNUNET_RECLAIM_Operation *
1081GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 1081GNUNET_RECLAIM_ticket_issue (struct GNUNET_RECLAIM_Handle *h,
1082 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, 1082 const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss,
1083 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, 1083 const struct GNUNET_CRYPTO_EcdsaPublicKey *rp,
1084 const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs, 1084 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
1085 GNUNET_IDENTITY_PROVIDER_TicketCallback cb, 1085 GNUNET_RECLAIM_TicketCallback cb,
1086 void *cb_cls) 1086 void *cb_cls)
1087{ 1087{
1088 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 1088 struct GNUNET_RECLAIM_Operation *op;
1089 struct IssueTicketMessage *tim; 1089 struct IssueTicketMessage *tim;
1090 size_t attr_len; 1090 size_t attr_len;
1091 1091
1092 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation); 1092 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1093 op->h = h; 1093 op->h = h;
1094 op->tr_cb = cb; 1094 op->tr_cb = cb;
1095 op->cls = cb_cls; 1095 op->cls = cb_cls;
@@ -1097,15 +1097,15 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h
1097 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 1097 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1098 h->op_tail, 1098 h->op_tail,
1099 op); 1099 op);
1100 attr_len = GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (attrs); 1100 attr_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs);
1101 op->env = GNUNET_MQ_msg_extra (tim, 1101 op->env = GNUNET_MQ_msg_extra (tim,
1102 attr_len, 1102 attr_len,
1103 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET); 1103 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET);
1104 tim->identity = *iss; 1104 tim->identity = *iss;
1105 tim->rp = *rp; 1105 tim->rp = *rp;
1106 tim->id = htonl (op->r_id); 1106 tim->id = htonl (op->r_id);
1107 1107
1108 GNUNET_IDENTITY_ATTRIBUTE_list_serialize (attrs, 1108 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs,
1109 (char*)&tim[1]); 1109 (char*)&tim[1]);
1110 1110
1111 tim->attr_len = htons (attr_len); 1111 tim->attr_len = htons (attr_len);
@@ -1119,24 +1119,24 @@ GNUNET_IDENTITY_PROVIDER_ticket_issue (struct GNUNET_IDENTITY_PROVIDER_Handle *h
1119 * Consumes an issued ticket. The ticket is persisted 1119 * Consumes an issued ticket. The ticket is persisted
1120 * and used to retrieve identity information from the issuer 1120 * and used to retrieve identity information from the issuer
1121 * 1121 *
1122 * @param h the identity provider to use 1122 * @param h the reclaim to use
1123 * @param identity the identity that is the subject of the issued ticket (the relying party) 1123 * @param identity the identity that is the subject of the issued ticket (the relying party)
1124 * @param ticket the issued ticket to consume 1124 * @param ticket the issued ticket to consume
1125 * @param cb the callback to call 1125 * @param cb the callback to call
1126 * @param cb_cls the callback closure 1126 * @param cb_cls the callback closure
1127 * @return handle to abort the operation 1127 * @return handle to abort the operation
1128 */ 1128 */
1129struct GNUNET_IDENTITY_PROVIDER_Operation * 1129struct GNUNET_RECLAIM_Operation *
1130GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 1130GNUNET_RECLAIM_ticket_consume (struct GNUNET_RECLAIM_Handle *h,
1131 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 1131 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1132 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 1132 const struct GNUNET_RECLAIM_Ticket *ticket,
1133 GNUNET_IDENTITY_PROVIDER_AttributeResult cb, 1133 GNUNET_RECLAIM_AttributeResult cb,
1134 void *cb_cls) 1134 void *cb_cls)
1135{ 1135{
1136 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 1136 struct GNUNET_RECLAIM_Operation *op;
1137 struct ConsumeTicketMessage *ctm; 1137 struct ConsumeTicketMessage *ctm;
1138 1138
1139 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation); 1139 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1140 op->h = h; 1140 op->h = h;
1141 op->ar_cb = cb; 1141 op->ar_cb = cb;
1142 op->cls = cb_cls; 1142 op->cls = cb_cls;
@@ -1145,14 +1145,14 @@ GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle
1145 h->op_tail, 1145 h->op_tail,
1146 op); 1146 op);
1147 op->env = GNUNET_MQ_msg_extra (ctm, 1147 op->env = GNUNET_MQ_msg_extra (ctm,
1148 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket), 1148 sizeof (const struct GNUNET_RECLAIM_Ticket),
1149 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET); 1149 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET);
1150 ctm->identity = *identity; 1150 ctm->identity = *identity;
1151 ctm->id = htonl (op->r_id); 1151 ctm->id = htonl (op->r_id);
1152 1152
1153 GNUNET_memcpy ((char*)&ctm[1], 1153 GNUNET_memcpy ((char*)&ctm[1],
1154 ticket, 1154 ticket,
1155 sizeof (const struct GNUNET_IDENTITY_PROVIDER_Ticket)); 1155 sizeof (const struct GNUNET_RECLAIM_Ticket));
1156 1156
1157 if (NULL != h->mq) 1157 if (NULL != h->mq)
1158 GNUNET_MQ_send_copy (h->mq, 1158 GNUNET_MQ_send_copy (h->mq,
@@ -1166,7 +1166,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle
1166 * Lists all tickets that have been issued to remote 1166 * Lists all tickets that have been issued to remote
1167 * identites (relying parties) 1167 * identites (relying parties)
1168 * 1168 *
1169 * @param h the identity provider to use 1169 * @param h the reclaim to use
1170 * @param identity the issuing identity 1170 * @param identity the issuing identity
1171 * @param error_cb function to call on error (i.e. disconnect), 1171 * @param error_cb function to call on error (i.e. disconnect),
1172 * the handle is afterwards invalid 1172 * the handle is afterwards invalid
@@ -1179,17 +1179,17 @@ GNUNET_IDENTITY_PROVIDER_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Handle
1179 * @param finish_cb_cls closure for @a finish_cb 1179 * @param finish_cb_cls closure for @a finish_cb
1180 * @return an iterator handle to use for iteration 1180 * @return an iterator handle to use for iteration
1181 */ 1181 */
1182struct GNUNET_IDENTITY_PROVIDER_TicketIterator * 1182struct GNUNET_RECLAIM_TicketIterator *
1183GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 1183GNUNET_RECLAIM_ticket_iteration_start (struct GNUNET_RECLAIM_Handle *h,
1184 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 1184 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1185 GNUNET_SCHEDULER_TaskCallback error_cb, 1185 GNUNET_SCHEDULER_TaskCallback error_cb,
1186 void *error_cb_cls, 1186 void *error_cb_cls,
1187 GNUNET_IDENTITY_PROVIDER_TicketCallback proc, 1187 GNUNET_RECLAIM_TicketCallback proc,
1188 void *proc_cls, 1188 void *proc_cls,
1189 GNUNET_SCHEDULER_TaskCallback finish_cb, 1189 GNUNET_SCHEDULER_TaskCallback finish_cb,
1190 void *finish_cb_cls) 1190 void *finish_cb_cls)
1191{ 1191{
1192 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it; 1192 struct GNUNET_RECLAIM_TicketIterator *it;
1193 struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub; 1193 struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub;
1194 struct GNUNET_MQ_Envelope *env; 1194 struct GNUNET_MQ_Envelope *env;
1195 struct TicketIterationStartMessage *msg; 1195 struct TicketIterationStartMessage *msg;
@@ -1198,7 +1198,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER
1198 GNUNET_CRYPTO_ecdsa_key_get_public (identity, 1198 GNUNET_CRYPTO_ecdsa_key_get_public (identity,
1199 &identity_pub); 1199 &identity_pub);
1200 rid = h->r_id_gen++; 1200 rid = h->r_id_gen++;
1201 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator); 1201 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator);
1202 it->h = h; 1202 it->h = h;
1203 it->error_cb = error_cb; 1203 it->error_cb = error_cb;
1204 it->error_cb_cls = error_cb_cls; 1204 it->error_cb_cls = error_cb_cls;
@@ -1211,7 +1211,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER
1211 h->ticket_it_tail, 1211 h->ticket_it_tail,
1212 it); 1212 it);
1213 env = GNUNET_MQ_msg (msg, 1213 env = GNUNET_MQ_msg (msg,
1214 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START); 1214 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START);
1215 msg->id = htonl (rid); 1215 msg->id = htonl (rid);
1216 msg->identity = identity_pub; 1216 msg->identity = identity_pub;
1217 msg->is_audience = htonl (GNUNET_NO); 1217 msg->is_audience = htonl (GNUNET_NO);
@@ -1229,7 +1229,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER
1229 * Lists all tickets that have been issued to remote 1229 * Lists all tickets that have been issued to remote
1230 * identites (relying parties) 1230 * identites (relying parties)
1231 * 1231 *
1232 * @param h the identity provider to use 1232 * @param h the reclaim to use
1233 * @param identity the issuing identity 1233 * @param identity the issuing identity
1234 * @param error_cb function to call on error (i.e. disconnect), 1234 * @param error_cb function to call on error (i.e. disconnect),
1235 * the handle is afterwards invalid 1235 * the handle is afterwards invalid
@@ -1242,23 +1242,23 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER
1242 * @param finish_cb_cls closure for @a finish_cb 1242 * @param finish_cb_cls closure for @a finish_cb
1243 * @return an iterator handle to use for iteration 1243 * @return an iterator handle to use for iteration
1244 */ 1244 */
1245struct GNUNET_IDENTITY_PROVIDER_TicketIterator * 1245struct GNUNET_RECLAIM_TicketIterator *
1246GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 1246GNUNET_RECLAIM_ticket_iteration_start_rp (struct GNUNET_RECLAIM_Handle *h,
1247 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 1247 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
1248 GNUNET_SCHEDULER_TaskCallback error_cb, 1248 GNUNET_SCHEDULER_TaskCallback error_cb,
1249 void *error_cb_cls, 1249 void *error_cb_cls,
1250 GNUNET_IDENTITY_PROVIDER_TicketCallback proc, 1250 GNUNET_RECLAIM_TicketCallback proc,
1251 void *proc_cls, 1251 void *proc_cls,
1252 GNUNET_SCHEDULER_TaskCallback finish_cb, 1252 GNUNET_SCHEDULER_TaskCallback finish_cb,
1253 void *finish_cb_cls) 1253 void *finish_cb_cls)
1254{ 1254{
1255 struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it; 1255 struct GNUNET_RECLAIM_TicketIterator *it;
1256 struct GNUNET_MQ_Envelope *env; 1256 struct GNUNET_MQ_Envelope *env;
1257 struct TicketIterationStartMessage *msg; 1257 struct TicketIterationStartMessage *msg;
1258 uint32_t rid; 1258 uint32_t rid;
1259 1259
1260 rid = h->r_id_gen++; 1260 rid = h->r_id_gen++;
1261 it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator); 1261 it = GNUNET_new (struct GNUNET_RECLAIM_TicketIterator);
1262 it->h = h; 1262 it->h = h;
1263 it->error_cb = error_cb; 1263 it->error_cb = error_cb;
1264 it->error_cb_cls = error_cb_cls; 1264 it->error_cb_cls = error_cb_cls;
@@ -1271,7 +1271,7 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVI
1271 h->ticket_it_tail, 1271 h->ticket_it_tail,
1272 it); 1272 it);
1273 env = GNUNET_MQ_msg (msg, 1273 env = GNUNET_MQ_msg (msg,
1274 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START); 1274 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START);
1275 msg->id = htonl (rid); 1275 msg->id = htonl (rid);
1276 msg->identity = *identity; 1276 msg->identity = *identity;
1277 msg->is_audience = htonl (GNUNET_YES); 1277 msg->is_audience = htonl (GNUNET_YES);
@@ -1286,20 +1286,20 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVI
1286} 1286}
1287 1287
1288/** 1288/**
1289 * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_ticket_iteration_start 1289 * Calls the record processor specified in #GNUNET_RECLAIM_ticket_iteration_start
1290 * for the next record. 1290 * for the next record.
1291 * 1291 *
1292 * @param it the iterator 1292 * @param it the iterator
1293 */ 1293 */
1294void 1294void
1295GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it) 1295GNUNET_RECLAIM_ticket_iteration_next (struct GNUNET_RECLAIM_TicketIterator *it)
1296{ 1296{
1297 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h; 1297 struct GNUNET_RECLAIM_Handle *h = it->h;
1298 struct TicketIterationNextMessage *msg; 1298 struct TicketIterationNextMessage *msg;
1299 struct GNUNET_MQ_Envelope *env; 1299 struct GNUNET_MQ_Envelope *env;
1300 1300
1301 env = GNUNET_MQ_msg (msg, 1301 env = GNUNET_MQ_msg (msg,
1302 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT); 1302 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT);
1303 msg->id = htonl (it->r_id); 1303 msg->id = htonl (it->r_id);
1304 GNUNET_MQ_send (h->mq, 1304 GNUNET_MQ_send (h->mq,
1305 env); 1305 env);
@@ -1309,21 +1309,21 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (struct GNUNET_IDENTITY_PROVIDER_
1309/** 1309/**
1310 * Stops iteration and releases the idp handle for further calls. Must 1310 * Stops iteration and releases the idp handle for further calls. Must
1311 * be called on any iteration that has not yet completed prior to calling 1311 * be called on any iteration that has not yet completed prior to calling
1312 * #GNUNET_IDENTITY_PROVIDER_disconnect. 1312 * #GNUNET_RECLAIM_disconnect.
1313 * 1313 *
1314 * @param it the iterator 1314 * @param it the iterator
1315 */ 1315 */
1316void 1316void
1317GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it) 1317GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it)
1318{ 1318{
1319 struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h; 1319 struct GNUNET_RECLAIM_Handle *h = it->h;
1320 struct GNUNET_MQ_Envelope *env; 1320 struct GNUNET_MQ_Envelope *env;
1321 struct TicketIterationStopMessage *msg; 1321 struct TicketIterationStopMessage *msg;
1322 1322
1323 if (NULL != h->mq) 1323 if (NULL != h->mq)
1324 { 1324 {
1325 env = GNUNET_MQ_msg (msg, 1325 env = GNUNET_MQ_msg (msg,
1326 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP); 1326 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP);
1327 msg->id = htonl (it->r_id); 1327 msg->id = htonl (it->r_id);
1328 GNUNET_MQ_send (h->mq, 1328 GNUNET_MQ_send (h->mq,
1329 env); 1329 env);
@@ -1335,27 +1335,26 @@ GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_
1335 * Revoked an issued ticket. The relying party will be unable to retrieve 1335 * Revoked an issued ticket. The relying party will be unable to retrieve
1336 * updated attributes. 1336 * updated attributes.
1337 * 1337 *
1338 * @param h the identity provider to use 1338 * @param h the reclaim to use
1339 * @param identity the issuing identity 1339 * @param identity the issuing identity
1340 * @param ticket the ticket to revoke 1340 * @param ticket the ticket to revoke
1341 * @param cb the callback 1341 * @param cb the callback
1342 * @param cb_cls the callback closure 1342 * @param cb_cls the callback closure
1343 * @return handle to abort the operation 1343 * @return handle to abort the operation
1344 */ 1344 */
1345struct GNUNET_IDENTITY_PROVIDER_Operation * 1345struct GNUNET_RECLAIM_Operation *
1346GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *h, 1346GNUNET_RECLAIM_ticket_revoke (struct GNUNET_RECLAIM_Handle *h,
1347 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, 1347 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity,
1348 const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket, 1348 const struct GNUNET_RECLAIM_Ticket *ticket,
1349 GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cb, 1349 GNUNET_RECLAIM_ContinuationWithStatus cb,
1350 void *cb_cls) 1350 void *cb_cls)
1351{ 1351{
1352 struct GNUNET_IDENTITY_PROVIDER_Operation *op; 1352 struct GNUNET_RECLAIM_Operation *op;
1353 struct GNUNET_MQ_Envelope *env;
1354 struct RevokeTicketMessage *msg; 1353 struct RevokeTicketMessage *msg;
1355 uint32_t rid; 1354 uint32_t rid;
1356 1355
1357 rid = h->r_id_gen++; 1356 rid = h->r_id_gen++;
1358 op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation); 1357 op = GNUNET_new (struct GNUNET_RECLAIM_Operation);
1359 op->h = h; 1358 op->h = h;
1360 op->rvk_cb = cb; 1359 op->rvk_cb = cb;
1361 op->cls = cb_cls; 1360 op->cls = cb_cls;
@@ -1363,22 +1362,22 @@ GNUNET_IDENTITY_PROVIDER_ticket_revoke (struct GNUNET_IDENTITY_PROVIDER_Handle *
1363 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 1362 GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
1364 h->op_tail, 1363 h->op_tail,
1365 op); 1364 op);
1366 env = GNUNET_MQ_msg_extra (msg, 1365 op->env = GNUNET_MQ_msg_extra (msg,
1367 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket), 1366 sizeof (struct GNUNET_RECLAIM_Ticket),
1368 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET); 1367 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET);
1369 msg->id = htonl (rid); 1368 msg->id = htonl (rid);
1370 msg->identity = *identity; 1369 msg->identity = *identity;
1371 GNUNET_memcpy (&msg[1], 1370 GNUNET_memcpy (&msg[1],
1372 ticket, 1371 ticket,
1373 sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket)); 1372 sizeof (struct GNUNET_RECLAIM_Ticket));
1374 if (NULL == h->mq) 1373 if (NULL != h->mq) {
1375 op->env = env;
1376 else
1377 GNUNET_MQ_send (h->mq, 1374 GNUNET_MQ_send (h->mq,
1378 env); 1375 op->env);
1376 op->env = NULL;
1377 }
1379 return op; 1378 return op;
1380} 1379}
1381 1380
1382 1381
1383 1382
1384/* end of identity_provider_api.c */ 1383/* end of reclaim_api.c */
diff --git a/src/reclaim/test_reclaim.sh b/src/reclaim/test_reclaim.sh
new file mode 100755
index 000000000..311f5382a
--- /dev/null
+++ b/src/reclaim/test_reclaim.sh
@@ -0,0 +1,31 @@
1#!/bin/bash
2#trap "gnunet-arm -e -c test_reclaim_lookup.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27gnunet-identity -C testego -c test_reclaim.conf
28valgrind gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
29gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
30gnunet-reclaim -e testego -D -c test_reclaim.conf
31gnunet-arm -e -c test_reclaim.conf
diff --git a/src/reclaim/test_reclaim_attribute.sh b/src/reclaim/test_reclaim_attribute.sh
new file mode 100755
index 000000000..39bd715b7
--- /dev/null
+++ b/src/reclaim/test_reclaim_attribute.sh
@@ -0,0 +1,40 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27#gnunet-arm -i rest -c test_reclaim.conf
28gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf
30TEST_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep testego | awk '{print $3}')
31gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
32gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf > /dev/null 2>&1
33if test $? != 0
34then
35 echo "Failed."
36 exit 1
37fi
38
39#curl localhost:7776/reclaim/attributes/testego
40gnunet-arm -e -c test_reclaim.conf
diff --git a/src/reclaim/test_reclaim_consume.sh b/src/reclaim/test_reclaim_consume.sh
new file mode 100755
index 000000000..36c8052d0
--- /dev/null
+++ b/src/reclaim/test_reclaim_consume.sh
@@ -0,0 +1,43 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27#gnunet-arm -i rest -c test_reclaim.conf
28gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf
30SUBJECT_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep rpego | awk '{print $3}')
31TEST_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep testego | awk '{print $3}')
32gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf
33gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf
34TICKET=$(gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf | awk '{print $1}')
35gnunet-reclaim -e rpego -C $TICKET -c test_reclaim.conf > /dev/null 2>&1
36
37if test $? != 0
38then
39 "Failed."
40 exit 1
41fi
42#curl http://localhost:7776/reclaim/tickets/testego
43gnunet-arm -e -c test_reclaim.conf
diff --git a/src/identity-provider/test_idp_defaults.conf b/src/reclaim/test_reclaim_defaults.conf
index a9a197dea..a9a197dea 100644
--- a/src/identity-provider/test_idp_defaults.conf
+++ b/src/reclaim/test_reclaim_defaults.conf
diff --git a/src/reclaim/test_reclaim_issue.sh b/src/reclaim/test_reclaim_issue.sh
new file mode 100755
index 000000000..6a71470e1
--- /dev/null
+++ b/src/reclaim/test_reclaim_issue.sh
@@ -0,0 +1,42 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf
27#gnunet-arm -i rest -c test_reclaim.conf
28gnunet-identity -C testego -c test_reclaim.conf
29gnunet-identity -C rpego -c test_reclaim.conf
30SUBJECT_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep rpego | awk '{print $3}')
31TEST_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep testego | awk '{print $3}')
32gnunet-reclaim -e testego -a email -V john@doe.gnu -c test_reclaim.conf > /dev/null 2>&1
33gnunet-reclaim -e testego -a name -V John -c test_reclaim.conf > /dev/null 2>&1
34#gnunet-reclaim -e testego -D -c test_reclaim.conf
35gnunet-reclaim -e testego -i "email,name" -r $SUBJECT_KEY -c test_reclaim.conf > /dev/null 2>&1
36if test $? != 0
37then
38 echo "Failed."
39 exit 1
40fi
41#curl http://localhost:7776/reclaim/attributes/testego
42gnunet-arm -e -c test_reclaim.conf
diff --git a/src/reclaim/test_reclaim_revoke.sh b/src/reclaim/test_reclaim_revoke.sh
new file mode 100755
index 000000000..595752fd8
--- /dev/null
+++ b/src/reclaim/test_reclaim_revoke.sh
@@ -0,0 +1,65 @@
1#!/bin/bash
2trap "gnunet-arm -e -c test_reclaim.conf" SIGINT
3
4LOCATION=$(which gnunet-config)
5if [ -z $LOCATION ]
6then
7 LOCATION="gnunet-config"
8fi
9$LOCATION --version 1> /dev/null
10if test $? != 0
11then
12 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
13 exit 77
14fi
15
16rm -rf `gnunet-config -c test_reclaim.conf -s PATHS -o GNUNET_HOME -f`
17
18# (1) PKEY1.user -> PKEY2.resu.user
19# (2) PKEY2.resu -> PKEY3
20# (3) PKEY3.user -> PKEY4
21
22
23which timeout &> /dev/null && DO_TIMEOUT="timeout 30"
24
25TEST_ATTR="test"
26gnunet-arm -s -c test_reclaim.conf 2&>1 > /dev/null
27gnunet-identity -C alice -c test_reclaim.conf
28gnunet-identity -C bob -c test_reclaim.conf
29gnunet-identity -C eve -c test_reclaim.conf
30ALICE_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep alice | awk '{print $3}')
31BOB_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep bob | awk '{print $3}')
32EVE_KEY=$(gnunet-identity -d -c test_reclaim.conf | grep eve | awk '{print $3}')
33
34gnunet-reclaim -e alice -E 15s -a email -V john@doe.gnu -c test_reclaim.conf
35gnunet-reclaim -e alice -E 15s -a name -V John -c test_reclaim.conf
36TICKET_BOB=$(gnunet-reclaim -e alice -i "email,name" -r $BOB_KEY -c test_reclaim.conf | awk '{print $1}')
37#gnunet-reclaim -e bob -C $TICKET_BOB -c test_reclaim.conf
38TICKET_EVE=$(gnunet-reclaim -e alice -i "email" -r $EVE_KEY -c test_reclaim.conf | awk '{print $1}')
39
40#echo "Consuming $TICKET"
41#gnunet-reclaim -e eve -C $TICKET_EVE -c test_reclaim.conf
42gnunet-reclaim -e alice -R $TICKET_EVE -c test_reclaim.conf
43
44#sleep 6
45
46gnunet-reclaim -e eve -C $TICKET_EVE -c test_reclaim.conf 2&>1 >/dev/null
47if test $? == 0
48then
49 echo "Eve can still resolve attributes..."
50 gnunet-arm -e -c test_reclaim.conf
51 exit 1
52fi
53
54gnunet-arm -e -c test_reclaim.conf
55gnunet-arm -s -c test_reclaim.conf 2&>1 > /dev/null
56
57gnunet-reclaim -e bob -C $TICKET_BOB -c test_reclaim.conf 2&>1 >/dev/null
58if test $? != 0
59then
60 echo "Bob cannot resolve attributes..."
61 gnunet-arm -e -c test_reclaim.conf
62 exit 1
63fi
64
65gnunet-arm -e -c test_reclaim.conf
diff --git a/src/rest/Makefile.am b/src/rest/Makefile.am
index ebfb98024..ce0454d53 100644
--- a/src/rest/Makefile.am
+++ b/src/rest/Makefile.am
@@ -29,6 +29,18 @@ libexec_PROGRAMS = \
29EXTRA_DIST = \ 29EXTRA_DIST = \
30 rest.conf 30 rest.conf
31 31
32plugin_LTLIBRARIES = libgnunet_plugin_rest_copying.la
33
34libgnunet_plugin_rest_copying_la_SOURCES = \
35 plugin_rest_copying.c
36libgnunet_plugin_rest_copying_la_LIBADD = \
37 $(top_builddir)/src/rest/libgnunetrest.la \
38 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
39 $(LTLIBINTL) -lmicrohttpd
40libgnunet_plugin_rest_copying_la_LDFLAGS = \
41 $(GN_PLUGIN_LDFLAGS)
42
43
32gnunet_rest_server_SOURCES = \ 44gnunet_rest_server_SOURCES = \
33 gnunet-rest-server.c 45 gnunet-rest-server.c
34 46
diff --git a/src/rest/plugin_rest_copying.c b/src/rest/plugin_rest_copying.c
new file mode 100644
index 000000000..668dc5d38
--- /dev/null
+++ b/src/rest/plugin_rest_copying.c
@@ -0,0 +1,231 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17 */
18/**
19 * @author Martin Schanzenbach
20 * @file gns/plugin_rest_copying.c
21 * @brief REST plugin that serves licensing information.
22 *
23 */
24
25#include "platform.h"
26#include "gnunet_rest_plugin.h"
27#include <gnunet_rest_lib.h>
28
29#define GNUNET_REST_API_NS_COPYING "/copying"
30
31#define GNUNET_REST_COPYING_TEXT "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>"
32
33/**
34 * @brief struct returned by the initialization function of the plugin
35 */
36struct Plugin
37{
38 const struct GNUNET_CONFIGURATION_Handle *cfg;
39};
40
41const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43struct RequestHandle
44{
45 /**
46 * Handle to rest request
47 */
48 struct GNUNET_REST_RequestHandle *rest_handle;
49
50 /**
51 * The plugin result processor
52 */
53 GNUNET_REST_ResultProcessor proc;
54
55 /**
56 * The closure of the result processor
57 */
58 void *proc_cls;
59
60 /**
61 * HTTP response code
62 */
63 int response_code;
64
65};
66
67
68/**
69 * Cleanup request handle.
70 *
71 * @param handle Handle to clean up
72 */
73static void
74cleanup_handle (struct RequestHandle *handle)
75{
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
77 "Cleaning up\n");
78 GNUNET_free (handle);
79}
80
81
82/**
83 * Task run on shutdown. Cleans up everything.
84 *
85 * @param cls unused
86 * @param tc scheduler context
87 */
88static void
89do_error (void *cls)
90{
91 struct RequestHandle *handle = cls;
92 struct MHD_Response *resp;
93
94 resp = GNUNET_REST_create_response (NULL);
95 handle->proc (handle->proc_cls, resp, handle->response_code);
96 cleanup_handle (handle);
97}
98
99
100/**
101 * Handle rest request
102 *
103 * @param handle the lookup handle
104 */
105static void
106get_cont (struct GNUNET_REST_RequestHandle *con_handle,
107 const char* url,
108 void *cls)
109{
110 struct MHD_Response *resp;
111 struct RequestHandle *handle = cls;
112
113 resp = GNUNET_REST_create_response (GNUNET_REST_COPYING_TEXT);
114 handle->proc (handle->proc_cls,
115 resp,
116 MHD_HTTP_OK);
117 cleanup_handle (handle);
118}
119
120
121
122/**
123 * Handle rest request
124 *
125 * @param handle the lookup handle
126 */
127static void
128options_cont (struct GNUNET_REST_RequestHandle *con_handle,
129 const char* url,
130 void *cls)
131{
132 struct MHD_Response *resp;
133 struct RequestHandle *handle = cls;
134
135 resp = GNUNET_REST_create_response (NULL);
136 MHD_add_response_header (resp,
137 "Access-Control-Allow-Methods",
138 MHD_HTTP_METHOD_GET);
139 handle->proc (handle->proc_cls,
140 resp,
141 MHD_HTTP_OK);
142 cleanup_handle (handle);
143}
144
145
146/**
147 * Function processing the REST call
148 *
149 * @param method HTTP method
150 * @param url URL of the HTTP request
151 * @param data body of the HTTP request (optional)
152 * @param data_size length of the body
153 * @param proc callback function for the result
154 * @param proc_cls closure for @a proc
155 * @return #GNUNET_OK if request accepted
156 */
157static void
158rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
159 GNUNET_REST_ResultProcessor proc,
160 void *proc_cls)
161{
162 static const struct GNUNET_REST_RequestHandler handlers[] = {
163 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_COPYING, &get_cont},
164 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_COPYING, &options_cont},
165 GNUNET_REST_HANDLER_END
166 };
167 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
168 struct GNUNET_REST_RequestHandlerError err;
169
170 handle->proc_cls = proc_cls;
171 handle->proc = proc;
172 handle->rest_handle = conndata_handle;
173
174 if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle,
175 handlers,
176 &err,
177 handle))
178 {
179 handle->response_code = err.error_code;
180 GNUNET_SCHEDULER_add_now (&do_error, handle);
181 }
182}
183
184
185/**
186 * Entry point for the plugin.
187 *
188 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
189 * @return NULL on error, otherwise the plugin context
190 */
191void *
192libgnunet_plugin_rest_copying_init (void *cls)
193{
194 static struct Plugin plugin;
195 cfg = cls;
196 struct GNUNET_REST_Plugin *api;
197
198 if (NULL != plugin.cfg)
199 return NULL; /* can only initialize once! */
200 memset (&plugin, 0, sizeof (struct Plugin));
201 plugin.cfg = cfg;
202 api = GNUNET_new (struct GNUNET_REST_Plugin);
203 api->cls = &plugin;
204 api->name = GNUNET_REST_API_NS_COPYING;
205 api->process_request = &rest_copying_process_request;
206 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
207 _("COPYING REST API initialized\n"));
208 return api;
209}
210
211
212/**
213 * Exit point from the plugin.
214 *
215 * @param cls the plugin context (as returned by "init")
216 * @return always NULL
217 */
218void *
219libgnunet_plugin_rest_copying_done (void *cls)
220{
221 struct GNUNET_REST_Plugin *api = cls;
222 struct Plugin *plugin = api->cls;
223
224 plugin->cfg = NULL;
225 GNUNET_free (api);
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "COPYING REST plugin is finished\n");
228 return NULL;
229}
230
231/* end of plugin_rest_copying.c */
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index 16f23e86c..49714872f 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -49,7 +49,11 @@ static unsigned bits_needed;
49/** 49/**
50 * How long do we run the test? 50 * How long do we run the test?
51 */ 51 */
52//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 52static struct GNUNET_TIME_Relative duration;
53
54/**
55 * When do we do a hard shutdown?
56 */
53static struct GNUNET_TIME_Relative timeout; 57static struct GNUNET_TIME_Relative timeout;
54 58
55 59
@@ -446,6 +450,10 @@ struct RPSPeer
446 * @brief statistics values 450 * @brief statistics values
447 */ 451 */
448 uint64_t stats[STAT_TYPE_MAX]; 452 uint64_t stats[STAT_TYPE_MAX];
453 /**
454 * @brief Handle for the statistics get request
455 */
456 struct GNUNET_STATISTICS_GetHandle *h_stat_get[STAT_TYPE_MAX];
449}; 457};
450 458
451/** 459/**
@@ -489,15 +497,16 @@ static unsigned int view_sizes;
489static int ok; 497static int ok;
490 498
491/** 499/**
492 * Identifier for the churn task that runs periodically 500 * Identifier for the task that runs after the test to collect results
493 */ 501 */
494static struct GNUNET_SCHEDULER_Task *post_test_task; 502static struct GNUNET_SCHEDULER_Task *post_test_task;
495 503
496/** 504/**
497 * Identifier for the churn task that runs periodically 505 * Identifier for the shutdown task
498 */ 506 */
499static struct GNUNET_SCHEDULER_Task *shutdown_task; 507static struct GNUNET_SCHEDULER_Task *shutdown_task;
500 508
509
501/** 510/**
502 * Identifier for the churn task that runs periodically 511 * Identifier for the churn task that runs periodically
503 */ 512 */
@@ -874,6 +883,75 @@ static int check_statistics_collect_completed ()
874 return GNUNET_YES; 883 return GNUNET_YES;
875} 884}
876 885
886static void
887rps_disconnect_adapter (void *cls,
888 void *op_result);
889
890static void
891cancel_pending_req (struct PendingRequest *pending_req)
892{
893 struct RPSPeer *rps_peer;
894
895 rps_peer = pending_req->rps_peer;
896 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
897 rps_peer->pending_req_tail,
898 pending_req);
899 rps_peer->num_pending_reqs--;
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
901 "Cancelling pending rps get request\n");
902 GNUNET_SCHEDULER_cancel (pending_req->request_task);
903 GNUNET_free (pending_req);
904}
905
906static void
907cancel_request (struct PendingReply *pending_rep)
908{
909 struct RPSPeer *rps_peer;
910
911 rps_peer = pending_rep->rps_peer;
912 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
913 rps_peer->pending_rep_tail,
914 pending_rep);
915 rps_peer->num_pending_reps--;
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
917 "Cancelling rps get reply\n");
918 GNUNET_RPS_request_cancel (pending_rep->req_handle);
919 GNUNET_free (pending_rep);
920}
921
922void
923clean_peer (unsigned peer_index)
924{
925 struct PendingRequest *pending_req;
926
927 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head))
928 {
929 cancel_pending_req (pending_req);
930 }
931 pending_req = rps_peers[peer_index].pending_req_head;
932 rps_disconnect_adapter (&rps_peers[peer_index],
933 &rps_peers[peer_index].rps_handle);
934 for (unsigned stat_type = STAT_TYPE_ROUNDS;
935 stat_type < STAT_TYPE_MAX;
936 stat_type++)
937 {
938 if (NULL != rps_peers[peer_index].h_stat_get[stat_type])
939 {
940 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
941 "(%u) did not yet receive stat value for `%s'\n",
942 rps_peers[peer_index].index,
943 stat_type_2_str (stat_type));
944 GNUNET_STATISTICS_get_cancel (
945 rps_peers[peer_index].h_stat_get[stat_type]);
946 }
947 }
948 if (NULL != rps_peers[peer_index].op)
949 {
950 GNUNET_TESTBED_operation_done (rps_peers[peer_index].op);
951 rps_peers[peer_index].op = NULL;
952 }
953}
954
877/** 955/**
878 * Task run on timeout to shut everything down. 956 * Task run on timeout to shut everything down.
879 */ 957 */
@@ -881,35 +959,55 @@ static void
881shutdown_op (void *cls) 959shutdown_op (void *cls)
882{ 960{
883 unsigned int i; 961 unsigned int i;
962 struct OpListEntry *entry;
884 963
885 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 964 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
886 "Shutdown task scheduled, going down.\n"); 965 "Shutdown task scheduled, going down.\n");
887 in_shutdown = GNUNET_YES; 966 in_shutdown = GNUNET_YES;
967
968 if (NULL != shutdown_task)
969 {
970 GNUNET_SCHEDULER_cancel (shutdown_task);
971 shutdown_task = NULL;
972 }
888 if (NULL != post_test_task) 973 if (NULL != post_test_task)
889 { 974 {
890 GNUNET_SCHEDULER_cancel (post_test_task); 975 GNUNET_SCHEDULER_cancel (post_test_task);
976 post_test_task = NULL;
891 } 977 }
892 if (NULL != churn_task) 978 if (NULL != churn_task)
893 { 979 {
894 GNUNET_SCHEDULER_cancel (churn_task); 980 GNUNET_SCHEDULER_cancel (churn_task);
895 churn_task = NULL; 981 churn_task = NULL;
896 } 982 }
983 entry = oplist_head;
984 while (NULL != (entry = oplist_head))
985 {
986 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
987 "Operation still pending on shutdown (%u)\n",
988 entry->index);
989 GNUNET_TESTBED_operation_done (entry->op);
990 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
991 GNUNET_free (entry);
992 }
897 for (i = 0; i < num_peers; i++) 993 for (i = 0; i < num_peers; i++)
898 { 994 {
899 if (NULL != rps_peers[i].rps_handle) 995 clean_peer (i);
900 {
901 GNUNET_RPS_disconnect (rps_peers[i].rps_handle);
902 }
903 if (NULL != rps_peers[i].op)
904 {
905 GNUNET_TESTBED_operation_done (rps_peers[i].op);
906 }
907 } 996 }
908} 997}
909 998
999static void
1000trigger_shutdown (void *cls)
1001{
1002 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1003 "Shutdown was triggerd by timeout, going down.\n");
1004 shutdown_task = NULL;
1005 GNUNET_SCHEDULER_shutdown ();
1006}
1007
910 1008
911/** 1009/**
912 * Task run on timeout to collect statistics and potentially shut down. 1010 * Task run after #duration to collect statistics and potentially shut down.
913 */ 1011 */
914static void 1012static void
915post_test_op (void *cls) 1013post_test_op (void *cls)
@@ -919,7 +1017,7 @@ post_test_op (void *cls)
919 post_test_task = NULL; 1017 post_test_task = NULL;
920 post_test = GNUNET_YES; 1018 post_test = GNUNET_YES;
921 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1019 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
922 "Post test task scheduled, going down.\n"); 1020 "Post test task scheduled.\n");
923 if (NULL != churn_task) 1021 if (NULL != churn_task)
924 { 1022 {
925 GNUNET_SCHEDULER_cancel (churn_task); 1023 GNUNET_SCHEDULER_cancel (churn_task);
@@ -943,7 +1041,7 @@ post_test_op (void *cls)
943 GNUNET_YES == check_statistics_collect_completed()) 1041 GNUNET_YES == check_statistics_collect_completed())
944 { 1042 {
945 GNUNET_SCHEDULER_cancel (shutdown_task); 1043 GNUNET_SCHEDULER_cancel (shutdown_task);
946 shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL); 1044 shutdown_task = NULL;
947 GNUNET_SCHEDULER_shutdown (); 1045 GNUNET_SCHEDULER_shutdown ();
948 } 1046 }
949} 1047}
@@ -1030,9 +1128,9 @@ info_cb (void *cb_cls,
1030 */ 1128 */
1031static void 1129static void
1032rps_connect_complete_cb (void *cls, 1130rps_connect_complete_cb (void *cls,
1033 struct GNUNET_TESTBED_Operation *op, 1131 struct GNUNET_TESTBED_Operation *op,
1034 void *ca_result, 1132 void *ca_result,
1035 const char *emsg) 1133 const char *emsg)
1036{ 1134{
1037 struct RPSPeer *rps_peer = cls; 1135 struct RPSPeer *rps_peer = cls;
1038 struct GNUNET_RPS_Handle *rps = ca_result; 1136 struct GNUNET_RPS_Handle *rps = ca_result;
@@ -1057,7 +1155,9 @@ rps_connect_complete_cb (void *cls,
1057 return; 1155 return;
1058 } 1156 }
1059 1157
1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); 1158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1159 "Started client successfully (%u)\n",
1160 rps_peer->index);
1061 1161
1062 cur_test_run.main_test (rps_peer); 1162 cur_test_run.main_test (rps_peer);
1063} 1163}
@@ -1075,7 +1175,7 @@ rps_connect_complete_cb (void *cls,
1075 */ 1175 */
1076static void * 1176static void *
1077rps_connect_adapter (void *cls, 1177rps_connect_adapter (void *cls,
1078 const struct GNUNET_CONFIGURATION_Handle *cfg) 1178 const struct GNUNET_CONFIGURATION_Handle *cfg)
1079{ 1179{
1080 struct GNUNET_RPS_Handle *h; 1180 struct GNUNET_RPS_Handle *h;
1081 1181
@@ -1167,15 +1267,26 @@ stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1167 */ 1267 */
1168static void 1268static void
1169rps_disconnect_adapter (void *cls, 1269rps_disconnect_adapter (void *cls,
1170 void *op_result) 1270 void *op_result)
1171{ 1271{
1172 struct RPSPeer *peer = cls; 1272 struct RPSPeer *peer = cls;
1173 struct GNUNET_RPS_Handle *h = op_result; 1273 struct GNUNET_RPS_Handle *h = op_result;
1274 struct PendingReply *pending_rep;
1174 1275
1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnect_adapter()\n"); 1276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1277 "disconnect_adapter (%u)\n",
1278 peer->index);
1176 GNUNET_assert (NULL != peer); 1279 GNUNET_assert (NULL != peer);
1177 GNUNET_RPS_disconnect (h); 1280 if (NULL != peer->rps_handle)
1178 peer->rps_handle = NULL; 1281 {
1282 while (NULL != (pending_rep = peer->pending_rep_head))
1283 {
1284 cancel_request (pending_rep);
1285 }
1286 GNUNET_assert (h == peer->rps_handle);
1287 GNUNET_RPS_disconnect (h);
1288 peer->rps_handle = NULL;
1289 }
1179} 1290}
1180 1291
1181 1292
@@ -1219,13 +1330,15 @@ default_reply_handle (void *cls,
1219 rps_peer->num_recv_ids++; 1330 rps_peer->num_recv_ids++;
1220 } 1331 }
1221 1332
1222 if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) 1333 if (GNUNET_YES != post_test) return;
1334 if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) return;
1335 if (0 == evaluate())
1223 { 1336 {
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); 1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1225 GNUNET_assert (NULL != post_test_task); 1338 "Test succeeded before end of duration\n");
1226 GNUNET_SCHEDULER_cancel (post_test_task); 1339 if (NULL != post_test_task) GNUNET_SCHEDULER_cancel (post_test_task);
1227 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); 1340 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL);
1228 GNUNET_assert (NULL!= post_test_task); 1341 GNUNET_assert (NULL != post_test_task);
1229 } 1342 }
1230} 1343}
1231 1344
@@ -1239,13 +1352,13 @@ request_peers (void *cls)
1239 struct RPSPeer *rps_peer; 1352 struct RPSPeer *rps_peer;
1240 struct PendingReply *pending_rep; 1353 struct PendingReply *pending_rep;
1241 1354
1242 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1243 return;
1244 rps_peer = pending_req->rps_peer; 1355 rps_peer = pending_req->rps_peer;
1245 GNUNET_assert (1 <= rps_peer->num_pending_reqs); 1356 GNUNET_assert (1 <= rps_peer->num_pending_reqs);
1246 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, 1357 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1247 rps_peer->pending_req_tail, 1358 rps_peer->pending_req_tail,
1248 pending_req); 1359 pending_req);
1360 rps_peer->num_pending_reqs--;
1361 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return;
1249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1250 "Requesting one peer\n"); 1363 "Requesting one peer\n");
1251 pending_rep = GNUNET_new (struct PendingReply); 1364 pending_rep = GNUNET_new (struct PendingReply);
@@ -1258,39 +1371,6 @@ request_peers (void *cls)
1258 rps_peer->pending_rep_tail, 1371 rps_peer->pending_rep_tail,
1259 pending_rep); 1372 pending_rep);
1260 rps_peer->num_pending_reps++; 1373 rps_peer->num_pending_reps++;
1261 rps_peer->num_pending_reqs--;
1262}
1263
1264static void
1265cancel_pending_req (struct PendingRequest *pending_req)
1266{
1267 struct RPSPeer *rps_peer;
1268
1269 rps_peer = pending_req->rps_peer;
1270 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1271 rps_peer->pending_req_tail,
1272 pending_req);
1273 rps_peer->num_pending_reqs--;
1274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1275 "Cancelling pending request\n");
1276 GNUNET_SCHEDULER_cancel (pending_req->request_task);
1277 GNUNET_free (pending_req);
1278}
1279
1280static void
1281cancel_request (struct PendingReply *pending_rep)
1282{
1283 struct RPSPeer *rps_peer;
1284
1285 rps_peer = pending_rep->rps_peer;
1286 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1287 rps_peer->pending_rep_tail,
1288 pending_rep);
1289 rps_peer->num_pending_reps--;
1290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1291 "Cancelling request\n");
1292 GNUNET_RPS_request_cancel (pending_rep->req_handle);
1293 GNUNET_free (pending_rep);
1294} 1374}
1295 1375
1296 1376
@@ -2261,12 +2341,6 @@ void write_final_stats (void){
2261 stat_type < STAT_TYPE_MAX; 2341 stat_type < STAT_TYPE_MAX;
2262 stat_type++) 2342 stat_type++)
2263 { 2343 {
2264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2265 "Add to sum (%" PRIu64 ") %" PRIu64 " of stat type %u - %s\n",
2266 sums[stat_type],
2267 rps_peers[i].stats[stat_type],
2268 stat_type,
2269 stat_type_2_str (stat_type));
2270 sums[stat_type] += rps_peers[i].stats[stat_type]; 2344 sums[stat_type] += rps_peers[i].stats[stat_type];
2271 } 2345 }
2272 } 2346 }
@@ -2312,6 +2386,8 @@ post_test_shutdown_ready_cb (void *cls,
2312{ 2386{
2313 struct STATcls *stat_cls = (struct STATcls *) cls; 2387 struct STATcls *stat_cls = (struct STATcls *) cls;
2314 struct RPSPeer *rps_peer = stat_cls->rps_peer; 2388 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2389
2390 rps_peer->h_stat_get[stat_cls->stat_type] = NULL;
2315 if (GNUNET_OK == success) 2391 if (GNUNET_OK == success)
2316 { 2392 {
2317 /* set flag that we we got the value */ 2393 /* set flag that we we got the value */
@@ -2363,6 +2439,7 @@ stat_iterator (void *cls,
2363{ 2439{
2364 const struct STATcls *stat_cls = (const struct STATcls *) cls; 2440 const struct STATcls *stat_cls = (const struct STATcls *) cls;
2365 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; 2441 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer;
2442
2366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", 2443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n",
2367 //stat_type_2_str (stat_cls->stat_type), 2444 //stat_type_2_str (stat_cls->stat_type),
2368 name, 2445 name,
@@ -2455,12 +2532,13 @@ void post_profiler (struct RPSPeer *rps_peer)
2455 stat_cls->stat_type = stat_type; 2532 stat_cls->stat_type = stat_type;
2456 rps_peer->file_name_stats = 2533 rps_peer->file_name_stats =
2457 store_prefix_file_name (rps_peer->peer_id, "stats"); 2534 store_prefix_file_name (rps_peer->peer_id, "stats");
2458 GNUNET_STATISTICS_get (rps_peer->stats_h, 2535 rps_peer->h_stat_get[stat_type] = GNUNET_STATISTICS_get (
2459 "rps", 2536 rps_peer->stats_h,
2460 stat_type_2_str (stat_type), 2537 "rps",
2461 post_test_shutdown_ready_cb, 2538 stat_type_2_str (stat_type),
2462 stat_iterator, 2539 post_test_shutdown_ready_cb,
2463 (struct STATcls *) stat_cls); 2540 stat_iterator,
2541 (struct STATcls *) stat_cls);
2464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2465 "Requested statistics for %s (peer %" PRIu32 ")\n", 2543 "Requested statistics for %s (peer %" PRIu32 ")\n",
2466 stat_type_2_str (stat_type), 2544 stat_type_2_str (stat_type),
@@ -2555,6 +2633,8 @@ test_run (void *cls,
2555 /* Connect all peers to statistics service */ 2633 /* Connect all peers to statistics service */
2556 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) 2634 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
2557 { 2635 {
2636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2637 "Connecting to statistics service\n");
2558 rps_peers[i].stat_op = 2638 rps_peers[i].stat_op =
2559 GNUNET_TESTBED_service_connect (NULL, 2639 GNUNET_TESTBED_service_connect (NULL,
2560 peers[i], 2640 peers[i],
@@ -2569,11 +2649,12 @@ test_run (void *cls,
2569 2649
2570 if (NULL != churn_task) 2650 if (NULL != churn_task)
2571 GNUNET_SCHEDULER_cancel (churn_task); 2651 GNUNET_SCHEDULER_cancel (churn_task);
2572 post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); 2652 post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL);
2573 timeout = GNUNET_TIME_relative_multiply (timeout, 1 + (0.1 * num_peers)); 2653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us/1000000);
2574 shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); 2654 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout,
2575 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); 2655 &trigger_shutdown,
2576 2656 NULL);
2657 GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL);
2577} 2658}
2578 2659
2579 2660
@@ -2609,7 +2690,7 @@ run (void *cls,
2609 if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5; 2690 if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5;
2610 //cur_test_run.have_churn = HAVE_CHURN; 2691 //cur_test_run.have_churn = HAVE_CHURN;
2611 cur_test_run.have_churn = HAVE_NO_CHURN; 2692 cur_test_run.have_churn = HAVE_NO_CHURN;
2612 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; 2693 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
2613 cur_test_run.have_collect_statistics = COLLECT_STATISTICS; 2694 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
2614 cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) | 2695 cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) |
2615 BIT(STAT_TYPE_BLOCKS) | 2696 BIT(STAT_TYPE_BLOCKS) |
@@ -2632,10 +2713,38 @@ run (void *cls,
2632 /* 'Clean' directory */ 2713 /* 'Clean' directory */
2633 (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); 2714 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
2634 GNUNET_DISK_directory_create ("/tmp/rps/"); 2715 GNUNET_DISK_directory_create ("/tmp/rps/");
2635 if (0 == timeout.rel_value_us) 2716 if (0 == duration.rel_value_us)
2636 { 2717 {
2637 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); 2718 if (0 == timeout.rel_value_us)
2719 {
2720 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
2721 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2722 (90 * 1.2) +
2723 (0.01 * num_peers));
2724 }
2725 else
2726 {
2727 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2728 (timeout.rel_value_us/1000000)
2729 * 0.75);
2730 }
2638 } 2731 }
2732 else
2733 {
2734 if (0 == timeout.rel_value_us)
2735 {
2736 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2737 ((duration.rel_value_us/1000000)
2738 * 1.2) + (0.01 * num_peers));
2739 }
2740 }
2741 GNUNET_assert (duration.rel_value_us < timeout.rel_value_us);
2742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2743 "duration is %lus\n",
2744 duration.rel_value_us/1000000);
2745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2746 "timeout is %lus\n",
2747 timeout.rel_value_us/1000000);
2639 2748
2640 /* Compute number of bits for representing largest peer id */ 2749 /* Compute number of bits for representing largest peer id */
2641 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) 2750 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++)
@@ -2685,6 +2794,12 @@ main (int argc, char *argv[])
2685 gettext_noop ("number of peers to start"), 2794 gettext_noop ("number of peers to start"),
2686 &num_peers), 2795 &num_peers),
2687 2796
2797 GNUNET_GETOPT_option_relative_time ('d',
2798 "duration",
2799 "DURATION",
2800 gettext_noop ("duration of the profiling"),
2801 &duration),
2802
2688 GNUNET_GETOPT_option_relative_time ('t', 2803 GNUNET_GETOPT_option_relative_time ('t',
2689 "timeout", 2804 "timeout",
2690 "TIMEOUT", 2805 "TIMEOUT",
@@ -2732,7 +2847,6 @@ main (int argc, char *argv[])
2732 GNUNET_free (rps_peers); 2847 GNUNET_free (rps_peers);
2733 GNUNET_free (rps_peer_ids); 2848 GNUNET_free (rps_peer_ids);
2734 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 2849 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
2735 printf ("test -1\n");
2736 return ret_value; 2850 return ret_value;
2737} 2851}
2738 2852
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 84fb33be2..d601ac7d4 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -68,6 +68,7 @@ static struct GNUNET_STATISTICS_Handle *stats;
68 */ 68 */
69static struct GNUNET_PeerIdentity own_identity; 69static struct GNUNET_PeerIdentity own_identity;
70 70
71static int in_shutdown = GNUNET_NO;
71 72
72/** 73/**
73 * @brief Port used for cadet. 74 * @brief Port used for cadet.
@@ -97,11 +98,6 @@ static struct GNUNET_HashCode port;
97#define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) 98#define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask))
98 99
99/** 100/**
100 * Set a channel flag of given channel context.
101 */
102#define set_channel_flag(channel_flags, mask) ((*channel_flags) |= (mask))
103
104/**
105 * Get channel flag of given channel context. 101 * Get channel flag of given channel context.
106 */ 102 */
107#define check_channel_flag_set(channel_flags, mask)\ 103#define check_channel_flag_set(channel_flags, mask)\
@@ -164,6 +160,11 @@ struct PendingMessage
164}; 160};
165 161
166/** 162/**
163 * @brief Context for a channel
164 */
165struct ChannelCtx;
166
167/**
167 * Struct used to keep track of other peer's status 168 * Struct used to keep track of other peer's status
168 * 169 *
169 * This is stored in a multipeermap. 170 * This is stored in a multipeermap.
@@ -181,22 +182,12 @@ struct PeerContext
181 /** 182 /**
182 * Channel open to client. 183 * Channel open to client.
183 */ 184 */
184 struct GNUNET_CADET_Channel *send_channel; 185 struct ChannelCtx *send_channel_ctx;
185
186 /**
187 * Flags to the sending channel
188 */
189 uint32_t *send_channel_flags;
190 186
191 /** 187 /**
192 * Channel open from client. 188 * Channel open from client.
193 */ 189 */
194 struct GNUNET_CADET_Channel *recv_channel; // unneeded? 190 struct ChannelCtx *recv_channel_ctx;
195
196 /**
197 * Flags to the receiving channel
198 */
199 uint32_t *recv_channel_flags;
200 191
201 /** 192 /**
202 * Array of pending operations on this peer. 193 * Array of pending operations on this peer.
@@ -242,6 +233,11 @@ struct PeerContext
242 struct PendingMessage *pending_messages_tail; 233 struct PendingMessage *pending_messages_tail;
243 234
244 /** 235 /**
236 * @brief Task to destroy this context.
237 */
238 struct GNUNET_SCHEDULER_Task *destruction_task;
239
240 /**
245 * This is pobably followed by 'statistical' data (when we first saw 241 * This is pobably followed by 'statistical' data (when we first saw
246 * it, how did we get its ID, how many pushes (in a timeinterval), 242 * it, how did we get its ID, how many pushes (in a timeinterval),
247 * ...) 243 * ...)
@@ -265,6 +261,33 @@ struct PeersIteratorCls
265}; 261};
266 262
267/** 263/**
264 * @brief Context for a channel
265 */
266struct ChannelCtx
267{
268 /**
269 * @brief Meant to be used in a DLL
270 */
271 struct ChannelCtx *next;
272 struct ChannelCtx *prev;
273
274 /**
275 * @brief The channel itself
276 */
277 struct GNUNET_CADET_Channel *channel;
278
279 /**
280 * @brief The peer context associated with the channel
281 */
282 struct PeerContext *peer_ctx;
283
284 /**
285 * @brief Scheduled task that will destroy this context
286 */
287 struct GNUNET_SCHEDULER_Task *destruction_task;
288};
289
290/**
268 * @brief Hashmap of valid peers. 291 * @brief Hashmap of valid peers.
269 */ 292 */
270static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; 293static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers;
@@ -332,8 +355,6 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
332 355
333 ctx = GNUNET_new (struct PeerContext); 356 ctx = GNUNET_new (struct PeerContext);
334 ctx->peer_id = *peer; 357 ctx->peer_id = *peer;
335 ctx->send_channel_flags = GNUNET_new (uint32_t);
336 ctx->recv_channel_flags = GNUNET_new (uint32_t);
337 ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, 358 ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx,
338 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 359 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
339 GNUNET_assert (GNUNET_OK == ret); 360 GNUNET_assert (GNUNET_OK == ret);
@@ -387,8 +408,8 @@ Peers_check_connected (const struct GNUNET_PeerIdentity *peer)
387 /* Get the context */ 408 /* Get the context */
388 peer_ctx = get_peer_ctx (peer); 409 peer_ctx = get_peer_ctx (peer);
389 /* If we have no channel to this peer we don't know whether it's online */ 410 /* If we have no channel to this peer we don't know whether it's online */
390 if ( (NULL == peer_ctx->send_channel) && 411 if ( (NULL == peer_ctx->send_channel_ctx) &&
391 (NULL == peer_ctx->recv_channel) ) 412 (NULL == peer_ctx->recv_channel_ctx) )
392 { 413 {
393 Peers_unset_peer_flag (peer, Peers_ONLINE); 414 Peers_unset_peer_flag (peer, Peers_ONLINE);
394 return GNUNET_NO; 415 return GNUNET_NO;
@@ -575,6 +596,24 @@ handle_peer_pull_reply (void *cls,
575 596
576/* End declaration of handlers */ 597/* End declaration of handlers */
577 598
599/**
600 * @brief Allocate memory for a new channel context and insert it into DLL
601 *
602 * @param peer_ctx context of the according peer
603 *
604 * @return The channel context
605 */
606static struct ChannelCtx *
607add_channel_ctx (struct PeerContext *peer_ctx);
608
609/**
610 * @brief Remove the channel context from the DLL and free the memory.
611 *
612 * @param channel_ctx The channel context.
613 */
614static void
615remove_channel_ctx (struct ChannelCtx *channel_ctx);
616
578 617
579/** 618/**
580 * @brief Get the channel of a peer. If not existing, create. 619 * @brief Get the channel of a peer. If not existing, create.
@@ -610,16 +649,17 @@ get_channel (const struct GNUNET_PeerIdentity *peer)
610 649
611 650
612 peer_ctx = get_peer_ctx (peer); 651 peer_ctx = get_peer_ctx (peer);
613 if (NULL == peer_ctx->send_channel) 652 if (NULL == peer_ctx->send_channel_ctx)
614 { 653 {
615 LOG (GNUNET_ERROR_TYPE_DEBUG, 654 LOG (GNUNET_ERROR_TYPE_DEBUG,
616 "Trying to establish channel to peer %s\n", 655 "Trying to establish channel to peer %s\n",
617 GNUNET_i2s (peer)); 656 GNUNET_i2s (peer));
618 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); 657 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity);
619 *ctx_peer = *peer; 658 *ctx_peer = *peer;
620 peer_ctx->send_channel = 659 peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx);
660 peer_ctx->send_channel_ctx->channel =
621 GNUNET_CADET_channel_create (cadet_handle, 661 GNUNET_CADET_channel_create (cadet_handle,
622 (struct GNUNET_PeerIdentity *) ctx_peer, /* context */ 662 peer_ctx->send_channel_ctx, /* context */
623 peer, 663 peer,
624 &port, 664 &port,
625 GNUNET_CADET_OPTION_RELIABLE, 665 GNUNET_CADET_OPTION_RELIABLE,
@@ -627,8 +667,9 @@ get_channel (const struct GNUNET_PeerIdentity *peer)
627 cleanup_destroyed_channel, /* Disconnect handler */ 667 cleanup_destroyed_channel, /* Disconnect handler */
628 cadet_handlers); 668 cadet_handlers);
629 } 669 }
630 GNUNET_assert (NULL != peer_ctx->send_channel); 670 GNUNET_assert (NULL != peer_ctx->send_channel_ctx);
631 return peer_ctx->send_channel; 671 GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel);
672 return peer_ctx->send_channel_ctx->channel;
632} 673}
633 674
634 675
@@ -1045,12 +1086,10 @@ restore_valid_peers ()
1045 */ 1086 */
1046void 1087void
1047Peers_initialise (char* fn_valid_peers, 1088Peers_initialise (char* fn_valid_peers,
1048 struct GNUNET_CADET_Handle *cadet_h, 1089 struct GNUNET_CADET_Handle *cadet_h)
1049 const struct GNUNET_PeerIdentity *own_id)
1050{ 1090{
1051 filename_valid_peers = GNUNET_strdup (fn_valid_peers); 1091 filename_valid_peers = GNUNET_strdup (fn_valid_peers);
1052 cadet_handle = cadet_h; 1092 cadet_handle = cadet_h;
1053 own_identity = *own_id;
1054 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); 1093 peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
1055 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); 1094 valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
1056 restore_valid_peers (); 1095 restore_valid_peers ();
@@ -1136,14 +1175,12 @@ Peers_get_valid_peers (PeersIterator iterator,
1136 * @param peer the new #GNUNET_PeerIdentity 1175 * @param peer the new #GNUNET_PeerIdentity
1137 * 1176 *
1138 * @return #GNUNET_YES if peer was inserted 1177 * @return #GNUNET_YES if peer was inserted
1139 * #GNUNET_NO otherwise (if peer was already known or 1178 * #GNUNET_NO otherwise
1140 * peer was #own_identity)
1141 */ 1179 */
1142int 1180int
1143Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) 1181Peers_insert_peer (const struct GNUNET_PeerIdentity *peer)
1144{ 1182{
1145 if ( (GNUNET_YES == Peers_check_peer_known (peer)) || 1183 if (GNUNET_YES == Peers_check_peer_known (peer))
1146 (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) )
1147 { 1184 {
1148 return GNUNET_NO; /* We already know this peer - nothing to do */ 1185 return GNUNET_NO; /* We already know this peer - nothing to do */
1149 } 1186 }
@@ -1161,8 +1198,7 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl
1161 * 1198 *
1162 * @param peer the peer whose liveliness is to be checked 1199 * @param peer the peer whose liveliness is to be checked
1163 * @return #GNUNET_YES if peer had to be inserted 1200 * @return #GNUNET_YES if peer had to be inserted
1164 * #GNUNET_NO otherwise (if peer was already known or 1201 * #GNUNET_NO otherwise
1165 * peer was #own_identity)
1166 */ 1202 */
1167int 1203int
1168Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) 1204Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
@@ -1170,13 +1206,10 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
1170 struct PeerContext *peer_ctx; 1206 struct PeerContext *peer_ctx;
1171 int ret; 1207 int ret;
1172 1208
1173 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity))
1174 {
1175 return GNUNET_NO;
1176 }
1177 ret = Peers_insert_peer (peer); 1209 ret = Peers_insert_peer (peer);
1178 peer_ctx = get_peer_ctx (peer); 1210 peer_ctx = get_peer_ctx (peer);
1179 if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) 1211 if ( (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) &&
1212 (NULL == peer_ctx->liveliness_check_pending) )
1180 { 1213 {
1181 check_peer_live (peer_ctx); 1214 check_peer_live (peer_ctx);
1182 } 1215 }
@@ -1208,7 +1241,7 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer)
1208 } 1241 }
1209 1242
1210 peer_ctx = get_peer_ctx (peer); 1243 peer_ctx = get_peer_ctx (peer);
1211 if ( (NULL != peer_ctx->recv_channel) || 1244 if ( (NULL != peer_ctx->recv_channel_ctx) ||
1212 (NULL != peer_ctx->pending_messages_head) || 1245 (NULL != peer_ctx->pending_messages_head) ||
1213 (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) 1246 (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) )
1214 { 1247 {
@@ -1225,6 +1258,65 @@ int
1225Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags); 1258Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
1226 1259
1227/** 1260/**
1261 * @brief Callback for the scheduler to destroy the knowledge of a peer.
1262 *
1263 * @param cls Context of the peer
1264 */
1265static void
1266destroy_peer (void *cls)
1267{
1268 struct PeerContext *peer_ctx = cls;
1269
1270 GNUNET_assert (NULL != peer_ctx);
1271 peer_ctx->destruction_task = NULL;
1272 Peers_remove_peer (&peer_ctx->peer_id);
1273}
1274
1275static void
1276destroy_channel (void *cls);
1277
1278
1279/**
1280 * @brief Schedule the destruction of the given channel.
1281 *
1282 * Do so only if it was not already scheduled and not during shutdown.
1283 *
1284 * @param channel_ctx The context of the channel to destroy.
1285 */
1286static void
1287schedule_channel_destruction (struct ChannelCtx *channel_ctx)
1288{
1289 GNUNET_assert (NULL != channel_ctx);
1290 if (NULL != channel_ctx->destruction_task &&
1291 GNUNET_NO == in_shutdown)
1292 {
1293 channel_ctx->destruction_task =
1294 GNUNET_SCHEDULER_add_now (destroy_channel, channel_ctx);
1295 }
1296}
1297
1298
1299/**
1300 * @brief Schedule the destruction of the given peer.
1301 *
1302 * Do so only if it was not already scheduled and not during shutdown.
1303 *
1304 * @param peer_ctx The context of the peer to destroy.
1305 */
1306static void
1307schedule_peer_destruction (struct PeerContext *peer_ctx)
1308{
1309 GNUNET_assert (NULL != peer_ctx);
1310 if (NULL != peer_ctx->destruction_task &&
1311 GNUNET_NO == in_shutdown)
1312 {
1313 peer_ctx->destruction_task =
1314 GNUNET_SCHEDULER_add_now (destroy_peer, peer_ctx);
1315 }
1316}
1317
1318
1319/**
1228 * @brief Remove peer 1320 * @brief Remove peer
1229 * 1321 *
1230 * @param peer the peer to clean 1322 * @param peer the peer to clean
@@ -1235,7 +1327,8 @@ int
1235Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) 1327Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1236{ 1328{
1237 struct PeerContext *peer_ctx; 1329 struct PeerContext *peer_ctx;
1238 uint32_t *channel_flag; 1330
1331 GNUNET_assert (NULL != peer_map);
1239 1332
1240 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) 1333 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
1241 { 1334 {
@@ -1249,7 +1342,12 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1249 GNUNET_i2s (&peer_ctx->peer_id)); 1342 GNUNET_i2s (&peer_ctx->peer_id));
1250 Peers_unset_peer_flag (peer, Peers_ONLINE); 1343 Peers_unset_peer_flag (peer, Peers_ONLINE);
1251 1344
1345 /* Clear list of pending operations */
1346 // TODO this probably leaks memory
1347 // ('only' the cls to the function. Not sure what to do with it)
1252 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); 1348 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
1349
1350 /* Remove all pending messages */
1253 while (NULL != peer_ctx->pending_messages_head) 1351 while (NULL != peer_ctx->pending_messages_head)
1254 { 1352 {
1255 LOG (GNUNET_ERROR_TYPE_DEBUG, 1353 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1261,10 +1359,12 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1261 peer_ctx->liveliness_check_pending, 1359 peer_ctx->liveliness_check_pending,
1262 sizeof (struct PendingMessage))) ) 1360 sizeof (struct PendingMessage))) )
1263 { 1361 {
1362 // TODO this may leak memory
1264 peer_ctx->liveliness_check_pending = NULL; 1363 peer_ctx->liveliness_check_pending = NULL;
1265 } 1364 }
1266 remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); 1365 remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES);
1267 } 1366 }
1367
1268 /* If we are still waiting for notification whether this peer is live 1368 /* If we are still waiting for notification whether this peer is live
1269 * cancel the according task */ 1369 * cancel the according task */
1270 if (NULL != peer_ctx->liveliness_check_pending) 1370 if (NULL != peer_ctx->liveliness_check_pending)
@@ -1277,28 +1377,40 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1277 remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); 1377 remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES);
1278 peer_ctx->liveliness_check_pending = NULL; 1378 peer_ctx->liveliness_check_pending = NULL;
1279 } 1379 }
1280 channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); 1380
1281 if (NULL != peer_ctx->send_channel && 1381
1282 GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING)) 1382 /* Do we still have to wait for destruction of channels
1383 * or issue the destruction? */
1384 if (NULL != peer_ctx->send_channel_ctx &&
1385 NULL != peer_ctx->send_channel_ctx->destruction_task
1386 )
1283 { 1387 {
1284 LOG (GNUNET_ERROR_TYPE_DEBUG, 1388 schedule_peer_destruction (peer_ctx);
1285 "Destroying send channel\n"); 1389 return GNUNET_NO;
1286 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1287 peer_ctx->send_channel = NULL;
1288 peer_ctx->mq = NULL;
1289 } 1390 }
1290 channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); 1391 if (NULL != peer_ctx->recv_channel_ctx &&
1291 if (NULL != peer_ctx->recv_channel && 1392 NULL != peer_ctx->recv_channel_ctx->destruction_task)
1292 GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING))
1293 { 1393 {
1294 LOG (GNUNET_ERROR_TYPE_DEBUG, 1394 schedule_peer_destruction (peer_ctx);
1295 "Destroying recv channel\n"); 1395 return GNUNET_NO;
1296 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); 1396 }
1297 peer_ctx->recv_channel = NULL; 1397 if (NULL != peer_ctx->recv_channel_ctx)
1398 {
1399 schedule_channel_destruction (peer_ctx->recv_channel_ctx);
1400 schedule_peer_destruction (peer_ctx);
1401 return GNUNET_NO;
1402 }
1403 if (NULL != peer_ctx->send_channel_ctx)
1404 {
1405 schedule_channel_destruction (peer_ctx->send_channel_ctx);
1406 schedule_peer_destruction (peer_ctx);
1407 return GNUNET_NO;
1298 } 1408 }
1299 1409
1300 GNUNET_free (peer_ctx->send_channel_flags); 1410 if (NULL != peer_ctx->destruction_task)
1301 GNUNET_free (peer_ctx->recv_channel_flags); 1411 {
1412 GNUNET_SCHEDULER_cancel (peer_ctx->destruction_task);
1413 }
1302 1414
1303 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id)) 1415 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id))
1304 { 1416 {
@@ -1308,7 +1420,6 @@ Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1308 return GNUNET_YES; 1420 return GNUNET_YES;
1309} 1421}
1310 1422
1311
1312/** 1423/**
1313 * @brief set flags on a given peer. 1424 * @brief set flags on a given peer.
1314 * 1425 *
@@ -1364,77 +1475,6 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl
1364 return check_peer_flag_set (peer_ctx, flags); 1475 return check_peer_flag_set (peer_ctx, flags);
1365} 1476}
1366 1477
1367
1368/**
1369 * @brief set flags on a given channel.
1370 *
1371 * @param channel the channel to set flags on
1372 * @param flags the flags
1373 */
1374void
1375Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1376{
1377 set_channel_flag (channel_flags, flags);
1378}
1379
1380
1381/**
1382 * @brief unset flags on a given channel.
1383 *
1384 * @param channel the channel to unset flags on
1385 * @param flags the flags
1386 */
1387void
1388Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1389{
1390 unset_channel_flag (channel_flags, flags);
1391}
1392
1393
1394/**
1395 * @brief Check whether flags on a channel are set.
1396 *
1397 * @param channel the channel to check the flag of
1398 * @param flags the flags to check
1399 *
1400 * @return #GNUNET_YES if all given flags are set
1401 * #GNUNET_NO otherwise
1402 */
1403int
1404Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags)
1405{
1406 return check_channel_flag_set (channel_flags, flags);
1407}
1408
1409/**
1410 * @brief Get the flags for the channel in @a role for @a peer.
1411 *
1412 * @param peer Peer to get the channel flags for.
1413 * @param role Role of channel to get flags for
1414 *
1415 * @return The flags.
1416 */
1417uint32_t *
1418Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
1419 enum Peers_ChannelRole role)
1420{
1421 const struct PeerContext *peer_ctx;
1422
1423 peer_ctx = get_peer_ctx (peer);
1424 if (Peers_CHANNEL_ROLE_SENDING == role)
1425 {
1426 return peer_ctx->send_channel_flags;
1427 }
1428 else if (Peers_CHANNEL_ROLE_RECEIVING == role)
1429 {
1430 return peer_ctx->recv_channel_flags;
1431 }
1432 else
1433 {
1434 GNUNET_assert (0);
1435 }
1436}
1437
1438/** 1478/**
1439 * @brief Check whether we have information about the given peer. 1479 * @brief Check whether we have information about the given peer.
1440 * 1480 *
@@ -1505,7 +1545,7 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1505 const struct PeerContext *peer_ctx; 1545 const struct PeerContext *peer_ctx;
1506 1546
1507 peer_ctx = get_peer_ctx (peer); 1547 peer_ctx = get_peer_ctx (peer);
1508 if (NULL != peer_ctx->recv_channel) 1548 if (NULL != peer_ctx->recv_channel_ctx)
1509 { 1549 {
1510 return GNUNET_YES; 1550 return GNUNET_YES;
1511 } 1551 }
@@ -1530,6 +1570,7 @@ Peers_handle_inbound_channel (void *cls,
1530{ 1570{
1531 struct PeerContext *peer_ctx; 1571 struct PeerContext *peer_ctx;
1532 struct GNUNET_PeerIdentity *ctx_peer; 1572 struct GNUNET_PeerIdentity *ctx_peer;
1573 struct ChannelCtx *channel_ctx;
1533 1574
1534 LOG (GNUNET_ERROR_TYPE_DEBUG, 1575 LOG (GNUNET_ERROR_TYPE_DEBUG,
1535 "New channel was established to us (Peer %s).\n", 1576 "New channel was established to us (Peer %s).\n",
@@ -1540,19 +1581,22 @@ Peers_handle_inbound_channel (void *cls,
1540 set_peer_live (peer_ctx); 1581 set_peer_live (peer_ctx);
1541 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); 1582 ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity);
1542 *ctx_peer = *initiator; 1583 *ctx_peer = *initiator;
1584 channel_ctx = add_channel_ctx (peer_ctx);
1585 channel_ctx->channel = channel;
1543 /* We only accept one incoming channel per peer */ 1586 /* We only accept one incoming channel per peer */
1544 if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) 1587 if (GNUNET_YES == Peers_check_peer_send_intention (initiator))
1545 { 1588 {
1546 set_channel_flag (peer_ctx->recv_channel_flags, 1589 LOG (GNUNET_ERROR_TYPE_WARNING,
1547 Peers_CHANNEL_ESTABLISHED_TWICE); 1590 "Already got one receive channel. Destroying old one.\n");
1548 //GNUNET_CADET_channel_destroy (channel); 1591 GNUNET_break_op (0);
1549 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); 1592 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel_ctx->channel);
1550 peer_ctx->recv_channel = channel; 1593 remove_channel_ctx (peer_ctx->recv_channel_ctx);
1594 peer_ctx->recv_channel_ctx = channel_ctx;
1551 /* return the channel context */ 1595 /* return the channel context */
1552 return ctx_peer; 1596 return channel_ctx;
1553 } 1597 }
1554 peer_ctx->recv_channel = channel; 1598 peer_ctx->recv_channel_ctx = channel_ctx;
1555 return ctx_peer; 1599 return channel_ctx;
1556} 1600}
1557 1601
1558 1602
@@ -1574,7 +1618,7 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
1574 return GNUNET_NO; 1618 return GNUNET_NO;
1575 } 1619 }
1576 peer_ctx = get_peer_ctx (peer); 1620 peer_ctx = get_peer_ctx (peer);
1577 if (NULL == peer_ctx->send_channel) 1621 if (NULL == peer_ctx->send_channel_ctx)
1578 { 1622 {
1579 return GNUNET_NO; 1623 return GNUNET_NO;
1580 } 1624 }
@@ -1607,12 +1651,14 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
1607 } 1651 }
1608 peer_ctx = get_peer_ctx (peer); 1652 peer_ctx = get_peer_ctx (peer);
1609 if ( (Peers_CHANNEL_ROLE_SENDING == role) && 1653 if ( (Peers_CHANNEL_ROLE_SENDING == role) &&
1610 (channel == peer_ctx->send_channel) ) 1654 (NULL != peer_ctx->send_channel_ctx) &&
1655 (channel == peer_ctx->send_channel_ctx->channel) )
1611 { 1656 {
1612 return GNUNET_YES; 1657 return GNUNET_YES;
1613 } 1658 }
1614 if ( (Peers_CHANNEL_ROLE_RECEIVING == role) && 1659 if ( (Peers_CHANNEL_ROLE_RECEIVING == role) &&
1615 (channel == peer_ctx->recv_channel) ) 1660 (NULL != peer_ctx->recv_channel_ctx) &&
1661 (channel == peer_ctx->recv_channel_ctx->channel) )
1616 { 1662 {
1617 return GNUNET_YES; 1663 return GNUNET_YES;
1618 } 1664 }
@@ -1642,12 +1688,9 @@ Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1642 return GNUNET_NO; 1688 return GNUNET_NO;
1643 } 1689 }
1644 peer_ctx = get_peer_ctx (peer); 1690 peer_ctx = get_peer_ctx (peer);
1645 if (NULL != peer_ctx->send_channel) 1691 if (NULL != peer_ctx->send_channel_ctx)
1646 { 1692 {
1647 set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_CLEAN); 1693 schedule_channel_destruction (peer_ctx->send_channel_ctx);
1648 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1649 peer_ctx->send_channel = NULL;
1650 peer_ctx->mq = NULL;
1651 (void) Peers_check_connected (peer); 1694 (void) Peers_check_connected (peer);
1652 return GNUNET_YES; 1695 return GNUNET_YES;
1653 } 1696 }
@@ -1655,6 +1698,25 @@ Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1655} 1698}
1656 1699
1657/** 1700/**
1701 * @brief Callback for scheduler to destroy a channel
1702 *
1703 * @param cls Context of the channel
1704 */
1705static void
1706destroy_channel (void *cls)
1707{
1708 struct ChannelCtx *channel_ctx = cls;
1709 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
1710
1711 GNUNET_assert (channel_ctx == peer_ctx->send_channel_ctx ||
1712 channel_ctx == peer_ctx->recv_channel_ctx);
1713
1714 channel_ctx->destruction_task = NULL;
1715 GNUNET_CADET_channel_destroy (channel_ctx->channel);
1716 remove_channel_ctx (peer_ctx->send_channel_ctx);
1717}
1718
1719/**
1658 * This is called when a channel is destroyed. 1720 * This is called when a channel is destroyed.
1659 * 1721 *
1660 * @param cls The closure 1722 * @param cls The closure
@@ -1664,77 +1726,45 @@ void
1664Peers_cleanup_destroyed_channel (void *cls, 1726Peers_cleanup_destroyed_channel (void *cls,
1665 const struct GNUNET_CADET_Channel *channel) 1727 const struct GNUNET_CADET_Channel *channel)
1666{ 1728{
1667 struct GNUNET_PeerIdentity *peer = cls; 1729 struct ChannelCtx *channel_ctx = cls;
1668 struct PeerContext *peer_ctx; 1730 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
1731 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
1669 1732
1670 if (GNUNET_NO == Peers_check_peer_known (peer)) 1733 if (GNUNET_NO == Peers_check_peer_known (peer))
1671 {/* We don't want to implicitly create a context that we're about to kill */ 1734 {/* We don't want to implicitly create a context that we're about to kill */
1672 LOG (GNUNET_ERROR_TYPE_DEBUG, 1735 LOG (GNUNET_ERROR_TYPE_WARNING,
1673 "channel (%s) without associated context was destroyed\n", 1736 "channel (%s) without associated context was destroyed\n",
1674 GNUNET_i2s (peer)); 1737 GNUNET_i2s (peer));
1675 return; 1738 return;
1676 } 1739 }
1677 peer_ctx = get_peer_ctx (peer);
1678 1740
1679 /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY 1741 /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY
1680 * flag will be set. In this case simply make sure that the channels are 1742 * flag will be set. In this case simply make sure that the channels are
1681 * cleaned. */ 1743 * cleaned. */
1682 /* FIXME This distinction seems to be redundant */ 1744 /* The distinction seems to be redundant */
1683 if (Peers_check_peer_flag (peer, Peers_TO_DESTROY)) 1745 LOG (GNUNET_ERROR_TYPE_DEBUG,
1684 {/* We initiatad the destruction of this particular peer */ 1746 "Peer is NOT in the process of being destroyed\n");
1747 if ( (NULL != peer_ctx->send_channel_ctx) &&
1748 (channel == peer_ctx->send_channel_ctx->channel) )
1749 { /* Something (but us) killd the channel - clean up peer */
1685 LOG (GNUNET_ERROR_TYPE_DEBUG, 1750 LOG (GNUNET_ERROR_TYPE_DEBUG,
1686 "Peer is in the process of being destroyed\n"); 1751 "send channel (%s) was destroyed - cleaning up\n",
1687 if (channel == peer_ctx->send_channel) 1752 GNUNET_i2s (peer));
1688 { 1753 remove_channel_ctx (peer_ctx->send_channel_ctx);
1689 peer_ctx->send_channel = NULL;
1690 peer_ctx->mq = NULL;
1691 }
1692 else if (channel == peer_ctx->recv_channel)
1693 {
1694 peer_ctx->recv_channel = NULL;
1695 }
1696
1697 if (NULL != peer_ctx->send_channel)
1698 {
1699 GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
1700 peer_ctx->send_channel = NULL;
1701 peer_ctx->mq = NULL;
1702 }
1703 if (NULL != peer_ctx->recv_channel)
1704 {
1705 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel);
1706 peer_ctx->recv_channel = NULL;
1707 }
1708 /* Set the #Peers_ONLINE flag accordingly */
1709 (void) Peers_check_connected (peer);
1710 return;
1711 } 1754 }
1712 1755 else if ( (NULL != peer_ctx->recv_channel_ctx) &&
1713 else 1756 (channel == peer_ctx->recv_channel_ctx->channel) )
1714 { /* We did not initiate the destruction of this peer */ 1757 { /* Other peer doesn't want to send us messages anymore */
1715 LOG (GNUNET_ERROR_TYPE_DEBUG, 1758 LOG (GNUNET_ERROR_TYPE_DEBUG,
1716 "Peer is NOT in the process of being destroyed\n"); 1759 "Peer %s destroyed recv channel - cleaning up channel\n",
1717 if (channel == peer_ctx->send_channel) 1760 GNUNET_i2s (peer));
1718 { /* Something (but us) killd the channel - clean up peer */ 1761 remove_channel_ctx (peer_ctx->send_channel_ctx);
1719 LOG (GNUNET_ERROR_TYPE_DEBUG, 1762 }
1720 "send channel (%s) was destroyed - cleaning up\n", 1763 else
1721 GNUNET_i2s (peer)); 1764 {
1722 peer_ctx->send_channel = NULL; 1765 LOG (GNUNET_ERROR_TYPE_WARNING,
1723 peer_ctx->mq = NULL; 1766 "unknown channel (%s) was destroyed\n",
1724 } 1767 GNUNET_i2s (peer));
1725 else if (channel == peer_ctx->recv_channel)
1726 { /* Other peer doesn't want to send us messages anymore */
1727 LOG (GNUNET_ERROR_TYPE_DEBUG,
1728 "Peer %s destroyed recv channel - cleaning up channel\n",
1729 GNUNET_i2s (peer));
1730 peer_ctx->recv_channel = NULL;
1731 }
1732 else
1733 {
1734 LOG (GNUNET_ERROR_TYPE_WARNING,
1735 "unknown channel (%s) was destroyed\n",
1736 GNUNET_i2s (peer));
1737 }
1738 } 1768 }
1739 (void) Peers_check_connected (peer); 1769 (void) Peers_check_connected (peer);
1740} 1770}
@@ -1786,10 +1816,6 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
1786 struct PeerPendingOp pending_op; 1816 struct PeerPendingOp pending_op;
1787 struct PeerContext *peer_ctx; 1817 struct PeerContext *peer_ctx;
1788 1818
1789 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity))
1790 {
1791 return GNUNET_NO;
1792 }
1793 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); 1819 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1794 1820
1795 //TODO if LIVE/ONLINE execute immediately 1821 //TODO if LIVE/ONLINE execute immediately
@@ -1823,7 +1849,7 @@ Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer)
1823 1849
1824 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); 1850 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1825 peer_ctx = get_peer_ctx (peer); 1851 peer_ctx = get_peer_ctx (peer);
1826 return peer_ctx->recv_channel; 1852 return peer_ctx->recv_channel_ctx->channel;
1827} 1853}
1828/*********************************************************************** 1854/***********************************************************************
1829 * /Old gnunet-service-rps_peers.c 1855 * /Old gnunet-service-rps_peers.c
@@ -2484,6 +2510,9 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
2484 2510
2485 Peers_send_message (peer_id, ev, "PULL REPLY"); 2511 Peers_send_message (peer_id, ev, "PULL REPLY");
2486 GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); 2512 GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO);
2513 // TODO check with send intention: as send_channel is used/opened we indicate
2514 // a sending intention without intending it.
2515 // -> clean peer afterwards?
2487} 2516}
2488 2517
2489 2518
@@ -2616,7 +2645,7 @@ remove_peer (const struct GNUNET_PeerIdentity *peer)
2616 CustomPeerMap_remove_peer (push_map, peer); 2645 CustomPeerMap_remove_peer (push_map, peer);
2617 RPS_sampler_reinitialise_by_value (prot_sampler, peer); 2646 RPS_sampler_reinitialise_by_value (prot_sampler, peer);
2618 RPS_sampler_reinitialise_by_value (client_sampler, peer); 2647 RPS_sampler_reinitialise_by_value (client_sampler, peer);
2619 Peers_remove_peer (peer); 2648 schedule_peer_destruction (get_peer_ctx (peer));
2620} 2649}
2621 2650
2622 2651
@@ -2660,6 +2689,58 @@ clean_peer (const struct GNUNET_PeerIdentity *peer)
2660} 2689}
2661 2690
2662/** 2691/**
2692 * @brief Allocate memory for a new channel context and insert it into DLL
2693 *
2694 * @param peer_ctx context of the according peer
2695 *
2696 * @return The channel context
2697 */
2698static struct ChannelCtx *
2699add_channel_ctx (struct PeerContext *peer_ctx)
2700{
2701 struct ChannelCtx *channel_ctx;
2702 channel_ctx = GNUNET_new (struct ChannelCtx);
2703 channel_ctx->peer_ctx = peer_ctx;
2704 return channel_ctx;
2705}
2706
2707/**
2708 * @brief Remove the channel context from the DLL and free the memory.
2709 *
2710 * @param channel_ctx The channel context.
2711 */
2712static void
2713remove_channel_ctx (struct ChannelCtx *channel_ctx)
2714{
2715 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
2716 if (NULL != channel_ctx->destruction_task)
2717 {
2718 GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task);
2719 }
2720 GNUNET_free (channel_ctx);
2721
2722 if (channel_ctx == peer_ctx->send_channel_ctx)
2723 {
2724 peer_ctx->send_channel_ctx = NULL;
2725 peer_ctx->mq = NULL;
2726 }
2727 else if (channel_ctx == peer_ctx->recv_channel_ctx)
2728 {
2729 peer_ctx->recv_channel_ctx = NULL;
2730 }
2731 else
2732 {
2733 LOG (GNUNET_ERROR_TYPE_ERROR,
2734 "Trying to remove channel_ctx that is not associated with a peer\n");
2735 LOG (GNUNET_ERROR_TYPE_ERROR,
2736 "\trecv: %p\n", peer_ctx->recv_channel_ctx);
2737 LOG (GNUNET_ERROR_TYPE_ERROR,
2738 "\tsend: %p\n", peer_ctx->send_channel_ctx);
2739 GNUNET_assert (0);
2740 }
2741}
2742
2743/**
2663 * @brief This is called when a channel is destroyed. 2744 * @brief This is called when a channel is destroyed.
2664 * 2745 *
2665 * Removes peer completely from our knowledge if the send_channel was destroyed 2746 * Removes peer completely from our knowledge if the send_channel was destroyed
@@ -2675,8 +2756,8 @@ static void
2675cleanup_destroyed_channel (void *cls, 2756cleanup_destroyed_channel (void *cls,
2676 const struct GNUNET_CADET_Channel *channel) 2757 const struct GNUNET_CADET_Channel *channel)
2677{ 2758{
2678 struct GNUNET_PeerIdentity *peer = cls; 2759 struct ChannelCtx *channel_ctx = cls;
2679 uint32_t *channel_flag; 2760 struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
2680 struct PeerContext *peer_ctx; 2761 struct PeerContext *peer_ctx;
2681 2762
2682 GNUNET_assert (NULL != peer); 2763 GNUNET_assert (NULL != peer);
@@ -2686,94 +2767,26 @@ cleanup_destroyed_channel (void *cls,
2686 LOG (GNUNET_ERROR_TYPE_WARNING, 2767 LOG (GNUNET_ERROR_TYPE_WARNING,
2687 "channel (%s) without associated context was destroyed\n", 2768 "channel (%s) without associated context was destroyed\n",
2688 GNUNET_i2s (peer)); 2769 GNUNET_i2s (peer));
2689 GNUNET_free (peer); 2770 remove_channel_ctx (channel_ctx);
2690 return; 2771 return;
2691 } 2772 }
2692 2773
2693 peer_ctx = get_peer_ctx (peer); 2774 peer_ctx = get_peer_ctx (peer);
2694 if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING))
2695 {
2696 LOG (GNUNET_ERROR_TYPE_DEBUG,
2697 "Callback on destruction of recv-channel was called (%s)\n",
2698 GNUNET_i2s (peer));
2699 set_channel_flag (peer_ctx->recv_channel_flags, Peers_CHANNEL_DESTROING);
2700 } else if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING))
2701 {
2702 LOG (GNUNET_ERROR_TYPE_DEBUG,
2703 "Callback on destruction of send-channel was called (%s)\n",
2704 GNUNET_i2s (peer));
2705 set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_DESTROING);
2706 } else {
2707 LOG (GNUNET_ERROR_TYPE_ERROR,
2708 "Channel to be destroyed has is neither sending nor receiving role\n");
2709 }
2710 2775
2711 if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY)) 2776 // What should be done here:
2712 { /* We are in the middle of removing that peer from our knowledge. In this 2777 // * cleanup everything related to the channel
2713 case simply make sure that the channels are cleaned. */ 2778 // * memory
2714 Peers_cleanup_destroyed_channel (cls, channel); 2779 // * remove peer if necessary
2715 to_file (file_name_view_log,
2716 "-%s\t(cleanup channel, ourself)",
2717 GNUNET_i2s_full (peer));
2718 GNUNET_free (peer);
2719 return;
2720 }
2721 2780
2722 if (GNUNET_YES == 2781 if (peer_ctx->recv_channel_ctx == channel_ctx)
2723 Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING)) 2782 {
2724 { /* Channel used for sending was destroyed */ 2783 remove_channel_ctx (channel_ctx);
2725 /* Possible causes of channel destruction:
2726 * - ourselves -> cleaning send channel -> clean context
2727 * - other peer -> peer probably went down -> remove
2728 */
2729 channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING);
2730 if (GNUNET_YES == Peers_check_channel_flag (channel_flag, Peers_CHANNEL_CLEAN))
2731 { /* We are about to clean the sending channel. Clean the respective
2732 * context */
2733 Peers_cleanup_destroyed_channel (cls, channel);
2734 GNUNET_free (peer);
2735 return;
2736 }
2737 else
2738 { /* Other peer destroyed our sending channel that it is supposed to keep
2739 * open. It probably went down. Remove it from our knowledge. */
2740 Peers_cleanup_destroyed_channel (cls, channel);
2741 remove_peer (peer);
2742 GNUNET_free (peer);
2743 return;
2744 }
2745 }
2746 else if (GNUNET_YES ==
2747 Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING))
2748 { /* Channel used for receiving was destroyed */
2749 /* Possible causes of channel destruction:
2750 * - ourselves -> peer tried to establish channel twice -> clean context
2751 * - other peer -> peer doesn't want to send us data -> clean
2752 */
2753 channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING);
2754 if (GNUNET_YES ==
2755 Peers_check_channel_flag (channel_flag, Peers_CHANNEL_ESTABLISHED_TWICE))
2756 { /* Other peer tried to establish a channel to us twice. We do not accept
2757 * that. Clean the context. */
2758 Peers_cleanup_destroyed_channel (cls, channel);
2759 GNUNET_free (peer);
2760 return;
2761 }
2762 else
2763 { /* Other peer doesn't want to send us data anymore. We are free to clean
2764 * it. */
2765 Peers_cleanup_destroyed_channel (cls, channel);
2766 clean_peer (peer);
2767 GNUNET_free (peer);
2768 return;
2769 }
2770 } 2784 }
2771 else 2785 else if (peer_ctx->send_channel_ctx == channel_ctx)
2772 { 2786 {
2773 LOG (GNUNET_ERROR_TYPE_WARNING, 2787 remove_channel_ctx (channel_ctx);
2774 "Destroyed channel is neither sending nor receiving channel\n"); 2788 remove_peer (&peer_ctx->peer_id);
2775 } 2789 }
2776 GNUNET_free (peer);
2777} 2790}
2778 2791
2779/*********************************************************************** 2792/***********************************************************************
@@ -3032,8 +3045,6 @@ handle_client_seed (void *cls,
3032 3045
3033 num_peers = ntohl (msg->num_peers); 3046 num_peers = ntohl (msg->num_peers);
3034 peers = (struct GNUNET_PeerIdentity *) &msg[1]; 3047 peers = (struct GNUNET_PeerIdentity *) &msg[1];
3035 //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
3036 //GNUNET_memcpy (peers, &msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity));
3037 3048
3038 LOG (GNUNET_ERROR_TYPE_DEBUG, 3049 LOG (GNUNET_ERROR_TYPE_DEBUG,
3039 "Client seeded peers:\n"); 3050 "Client seeded peers:\n");
@@ -3048,9 +3059,6 @@ handle_client_seed (void *cls,
3048 3059
3049 got_peer (&peers[i]); 3060 got_peer (&peers[i]);
3050 } 3061 }
3051
3052 ////GNUNET_free (peers);
3053
3054 GNUNET_SERVICE_client_continue (cli_ctx->client); 3062 GNUNET_SERVICE_client_continue (cli_ctx->client);
3055} 3063}
3056 3064
@@ -3168,11 +3176,12 @@ static void
3168handle_peer_check (void *cls, 3176handle_peer_check (void *cls,
3169 const struct GNUNET_MessageHeader *msg) 3177 const struct GNUNET_MessageHeader *msg)
3170{ 3178{
3171 const struct GNUNET_PeerIdentity *peer = cls; 3179 const struct ChannelCtx *channel_ctx = cls;
3180 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3172 LOG (GNUNET_ERROR_TYPE_DEBUG, 3181 LOG (GNUNET_ERROR_TYPE_DEBUG,
3173 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); 3182 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer));
3174 3183
3175 GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); 3184 GNUNET_CADET_receive_done (channel_ctx->channel);
3176} 3185}
3177 3186
3178/** 3187/**
@@ -3188,7 +3197,8 @@ static void
3188handle_peer_push (void *cls, 3197handle_peer_push (void *cls,
3189 const struct GNUNET_MessageHeader *msg) 3198 const struct GNUNET_MessageHeader *msg)
3190{ 3199{
3191 const struct GNUNET_PeerIdentity *peer = cls; 3200 const struct ChannelCtx *channel_ctx = cls;
3201 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3192 3202
3193 // (check the proof of work (?)) 3203 // (check the proof of work (?))
3194 3204
@@ -3233,7 +3243,7 @@ handle_peer_push (void *cls,
3233 CustomPeerMap_put (push_map, peer); 3243 CustomPeerMap_put (push_map, peer);
3234 3244
3235 GNUNET_break_op (Peers_check_peer_known (peer)); 3245 GNUNET_break_op (Peers_check_peer_known (peer));
3236 GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); 3246 GNUNET_CADET_receive_done (channel_ctx->channel);
3237} 3247}
3238 3248
3239 3249
@@ -3249,7 +3259,8 @@ static void
3249handle_peer_pull_request (void *cls, 3259handle_peer_pull_request (void *cls,
3250 const struct GNUNET_MessageHeader *msg) 3260 const struct GNUNET_MessageHeader *msg)
3251{ 3261{
3252 struct GNUNET_PeerIdentity *peer = cls; 3262 const struct ChannelCtx *channel_ctx = cls;
3263 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3253 const struct GNUNET_PeerIdentity *view_array; 3264 const struct GNUNET_PeerIdentity *view_array;
3254 3265
3255 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); 3266 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer));
@@ -3272,7 +3283,7 @@ handle_peer_pull_request (void *cls,
3272 #endif /* ENABLE_MALICIOUS */ 3283 #endif /* ENABLE_MALICIOUS */
3273 3284
3274 GNUNET_break_op (Peers_check_peer_known (peer)); 3285 GNUNET_break_op (Peers_check_peer_known (peer));
3275 GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); 3286 GNUNET_CADET_receive_done (channel_ctx->channel);
3276 view_array = View_get_as_array (); 3287 view_array = View_get_as_array ();
3277 send_pull_reply (peer, view_array, View_size ()); 3288 send_pull_reply (peer, view_array, View_size ());
3278} 3289}
@@ -3312,7 +3323,8 @@ check_peer_pull_reply (void *cls,
3312 if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) 3323 if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING))
3313 { 3324 {
3314 LOG (GNUNET_ERROR_TYPE_WARNING, 3325 LOG (GNUNET_ERROR_TYPE_WARNING,
3315 "Received a pull reply from a peer we didn't request one from!\n"); 3326 "Received a pull reply from a peer (%s) we didn't request one from!\n",
3327 GNUNET_i2s (sender));
3316 GNUNET_break_op (0); 3328 GNUNET_break_op (0);
3317 return GNUNET_SYSERR; 3329 return GNUNET_SYSERR;
3318 } 3330 }
@@ -3329,8 +3341,9 @@ static void
3329handle_peer_pull_reply (void *cls, 3341handle_peer_pull_reply (void *cls,
3330 const struct GNUNET_RPS_P2P_PullReplyMessage *msg) 3342 const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
3331{ 3343{
3344 const struct ChannelCtx *channel_ctx = cls;
3345 const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id;
3332 const struct GNUNET_PeerIdentity *peers; 3346 const struct GNUNET_PeerIdentity *peers;
3333 struct GNUNET_PeerIdentity *sender = cls;
3334 uint32_t i; 3347 uint32_t i;
3335#ifdef ENABLE_MALICIOUS 3348#ifdef ENABLE_MALICIOUS
3336 struct AttackedPeer *tmp_att_peer; 3349 struct AttackedPeer *tmp_att_peer;
@@ -3368,9 +3381,7 @@ handle_peer_pull_reply (void *cls,
3368 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, 3381 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set,
3369 &peers[i]) 3382 &peers[i])
3370 && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, 3383 && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set,
3371 &peers[i]) 3384 &peers[i]))
3372 && 0 != GNUNET_CRYPTO_cmp_peer_identity (&peers[i],
3373 &own_identity))
3374 { 3385 {
3375 tmp_att_peer = GNUNET_new (struct AttackedPeer); 3386 tmp_att_peer = GNUNET_new (struct AttackedPeer);
3376 tmp_att_peer->peer_id = peers[i]; 3387 tmp_att_peer->peer_id = peers[i];
@@ -3382,21 +3393,17 @@ handle_peer_pull_reply (void *cls,
3382 continue; 3393 continue;
3383 } 3394 }
3384 #endif /* ENABLE_MALICIOUS */ 3395 #endif /* ENABLE_MALICIOUS */
3385 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, 3396 /* Make sure we 'know' about this peer */
3386 &peers[i])) 3397 (void) Peers_insert_peer (&peers[i]);
3387 {
3388 /* Make sure we 'know' about this peer */
3389 (void) Peers_insert_peer (&peers[i]);
3390 3398
3391 if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) 3399 if (GNUNET_YES == Peers_check_peer_valid (&peers[i]))
3392 { 3400 {
3393 CustomPeerMap_put (pull_map, &peers[i]); 3401 CustomPeerMap_put (pull_map, &peers[i]);
3394 } 3402 }
3395 else 3403 else
3396 { 3404 {
3397 Peers_schedule_operation (&peers[i], insert_in_pull_map); 3405 Peers_schedule_operation (&peers[i], insert_in_pull_map);
3398 (void) Peers_issue_peer_liveliness_check (&peers[i]); 3406 (void) Peers_issue_peer_liveliness_check (&peers[i]);
3399 }
3400 } 3407 }
3401 } 3408 }
3402 3409
@@ -3404,7 +3411,7 @@ handle_peer_pull_reply (void *cls,
3404 clean_peer (sender); 3411 clean_peer (sender);
3405 3412
3406 GNUNET_break_op (Peers_check_peer_known (sender)); 3413 GNUNET_break_op (Peers_check_peer_known (sender));
3407 GNUNET_CADET_receive_done (Peers_get_recv_channel (sender)); 3414 GNUNET_CADET_receive_done (channel_ctx->channel);
3408} 3415}
3409 3416
3410 3417
@@ -3831,10 +3838,8 @@ do_round (void *cls)
3831 for (i = 0; i < a_peers; i++) 3838 for (i = 0; i < a_peers; i++)
3832 { 3839 {
3833 peer = view_array[permut[i]]; 3840 peer = view_array[permut[i]];
3834 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO 3841 // FIXME if this fails schedule/loop this for later
3835 { // FIXME if this fails schedule/loop this for later 3842 send_push (&peer);
3836 send_push (&peer);
3837 }
3838 } 3843 }
3839 3844
3840 /* Send PULL requests */ 3845 /* Send PULL requests */
@@ -3852,8 +3857,7 @@ do_round (void *cls)
3852 for (i = first_border; i < second_border; i++) 3857 for (i = first_border; i < second_border; i++)
3853 { 3858 {
3854 peer = view_array[permut[i]]; 3859 peer = view_array[permut[i]];
3855 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer) && 3860 if ( GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING))
3856 GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) // TODO
3857 { // FIXME if this fails schedule/loop this for later 3861 { // FIXME if this fails schedule/loop this for later
3858 send_pull_request (&peer); 3862 send_pull_request (&peer);
3859 } 3863 }
@@ -3950,7 +3954,6 @@ do_round (void *cls)
3950 "-%s", 3954 "-%s",
3951 GNUNET_i2s_full (&peers_to_clean[i])); 3955 GNUNET_i2s_full (&peers_to_clean[i]));
3952 clean_peer (&peers_to_clean[i]); 3956 clean_peer (&peers_to_clean[i]);
3953 //peer_destroy_channel_send (sender);
3954 } 3957 }
3955 3958
3956 GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); 3959 GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0);
@@ -4006,7 +4009,6 @@ do_round (void *cls)
4006 GNUNET_i2s (update_peer)); 4009 GNUNET_i2s (update_peer));
4007 insert_in_sampler (NULL, update_peer); 4010 insert_in_sampler (NULL, update_peer);
4008 clean_peer (update_peer); /* This cleans only if it is not in the view */ 4011 clean_peer (update_peer); /* This cleans only if it is not in the view */
4009 //peer_destroy_channel_send (sender);
4010 } 4012 }
4011 4013
4012 for (i = 0; i < CustomPeerMap_size (pull_map); i++) 4014 for (i = 0; i < CustomPeerMap_size (pull_map); i++)
@@ -4017,7 +4019,6 @@ do_round (void *cls)
4017 insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); 4019 insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i));
4018 /* This cleans only if it is not in the view */ 4020 /* This cleans only if it is not in the view */
4019 clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); 4021 clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i));
4020 //peer_destroy_channel_send (sender);
4021 } 4022 }
4022 4023
4023 4024
@@ -4120,6 +4121,8 @@ shutdown_task (void *cls)
4120 struct ClientContext *client_ctx; 4121 struct ClientContext *client_ctx;
4121 struct ReplyCls *reply_cls; 4122 struct ReplyCls *reply_cls;
4122 4123
4124 in_shutdown = GNUNET_YES;
4125
4123 LOG (GNUNET_ERROR_TYPE_DEBUG, 4126 LOG (GNUNET_ERROR_TYPE_DEBUG,
4124 "RPS is going down\n"); 4127 "RPS is going down\n");
4125 4128
@@ -4364,10 +4367,17 @@ run (void *cls,
4364 NULL, /* WindowSize handler */ 4367 NULL, /* WindowSize handler */
4365 cleanup_destroyed_channel, /* Disconnect handler */ 4368 cleanup_destroyed_channel, /* Disconnect handler */
4366 cadet_handlers); 4369 cadet_handlers);
4370 if (NULL == cadet_port)
4371 {
4372 LOG (GNUNET_ERROR_TYPE_ERROR,
4373 "Cadet port `%s' is already in use.\n",
4374 GNUNET_APPLICATION_PORT_RPS);
4375 GNUNET_assert (0);
4376 }
4367 4377
4368 4378
4369 peerinfo_handle = GNUNET_PEERINFO_connect (cfg); 4379 peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
4370 Peers_initialise (fn_valid_peers, cadet_handle, &own_identity); 4380 Peers_initialise (fn_valid_peers, cadet_handle);
4371 GNUNET_free (fn_valid_peers); 4381 GNUNET_free (fn_valid_peers);
4372 4382
4373 /* Initialise sampler */ 4383 /* Initialise sampler */
diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c
index 42507655b..9e003eb39 100644
--- a/src/rps/gnunet-service-rps_custommap.c
+++ b/src/rps/gnunet-service-rps_custommap.c
@@ -213,7 +213,7 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map,
213 GNUNET_assert (NULL != last_index); 213 GNUNET_assert (NULL != last_index);
214 GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); 214 GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index);
215 GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, last_p, 215 GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, last_p,
216 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 216 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
217 GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *last_index); 217 GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *last_index);
218 *last_index = *index; 218 *last_index = *index;
219 } 219 }
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index d47e4952f..08fe96097 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -31,6 +31,17 @@
31 31
32#define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__)
33 33
34#define B2B_PAT "%c%c%c%c%c%c%c%c"
35#define B2B(byte) \
36 (byte & 0x80 ? '1' : '0'), \
37 (byte & 0x40 ? '1' : '0'), \
38 (byte & 0x20 ? '1' : '0'), \
39 (byte & 0x10 ? '1' : '0'), \
40 (byte & 0x08 ? '1' : '0'), \
41 (byte & 0x04 ? '1' : '0'), \
42 (byte & 0x02 ? '1' : '0'), \
43 (byte & 0x01 ? '1' : '0')
44
34#ifndef TO_FILE 45#ifndef TO_FILE
35#define TO_FILE 46#define TO_FILE
36#endif /* TO_FILE */ 47#endif /* TO_FILE */
@@ -155,6 +166,9 @@ to_file_raw (const char *file_name, const char *buf, size_t size_buf)
155 166
156 return; 167 return;
157 } 168 }
169 LOG (GNUNET_ERROR_TYPE_WARNING,
170 "Wrote %u bytes raw.\n",
171 size_written);
158 if (GNUNET_YES != GNUNET_DISK_file_close (f)) 172 if (GNUNET_YES != GNUNET_DISK_file_close (f))
159 LOG (GNUNET_ERROR_TYPE_WARNING, 173 LOG (GNUNET_ERROR_TYPE_WARNING,
160 "Unable to close file\n"); 174 "Unable to close file\n");
@@ -180,6 +194,8 @@ to_file_raw_unaligned (const char *file_name,
180 // num_bits_buf_unaligned = bits_needed % 8; 194 // num_bits_buf_unaligned = bits_needed % 8;
181 // return; 195 // return;
182 //} 196 //}
197 LOG (GNUNET_ERROR_TYPE_DEBUG,
198 "Was asked to write %u bits\n", bits_needed);
183 199
184 char buf_write[size_buf + 1]; 200 char buf_write[size_buf + 1];
185 const unsigned bytes_iter = (0 != bits_needed % 8? 201 const unsigned bytes_iter = (0 != bits_needed % 8?
@@ -187,6 +203,14 @@ to_file_raw_unaligned (const char *file_name,
187 bits_needed/8); 203 bits_needed/8);
188 // TODO what if no iteration happens? 204 // TODO what if no iteration happens?
189 unsigned size_buf_write = 0; 205 unsigned size_buf_write = 0;
206 LOG (GNUNET_ERROR_TYPE_DEBUG,
207 "num_bits_buf_unaligned: %u\n",
208 num_bits_buf_unaligned);
209 LOG (GNUNET_ERROR_TYPE_DEBUG,
210 "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n",
211 size_buf,
212 bits_needed,
213 bytes_iter);
190 buf_write[0] = buf_unaligned; 214 buf_write[0] = buf_unaligned;
191 /* Iterate over input bytes */ 215 /* Iterate over input bytes */
192 for (unsigned i = 0; i < bytes_iter; i++) 216 for (unsigned i = 0; i < bytes_iter; i++)
@@ -227,17 +251,57 @@ to_file_raw_unaligned (const char *file_name,
227 { 251 {
228 num_bits_needed_iter = 8; 252 num_bits_needed_iter = 8;
229 } 253 }
254 LOG (GNUNET_ERROR_TYPE_DEBUG,
255 "number of bits needed in this iteration: %u\n",
256 num_bits_needed_iter);
230 mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1; 257 mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1;
258 LOG (GNUNET_ERROR_TYPE_DEBUG,
259 "mask needed bits (current iter): "B2B_PAT"\n",
260 B2B(mask_bits_needed_iter));
261 LOG (GNUNET_ERROR_TYPE_DEBUG,
262 "Unaligned byte: "B2B_PAT" (%u bits)\n",
263 B2B(buf_unaligned),
264 num_bits_buf_unaligned);
231 byte_input = buf[i]; 265 byte_input = buf[i];
266 LOG (GNUNET_ERROR_TYPE_DEBUG,
267 "next whole input byte: "B2B_PAT"\n",
268 B2B(byte_input));
232 byte_input &= mask_bits_needed_iter; 269 byte_input &= mask_bits_needed_iter;
233 num_bits_to_align = 8 - num_bits_buf_unaligned; 270 num_bits_to_align = 8 - num_bits_buf_unaligned;
271 LOG (GNUNET_ERROR_TYPE_DEBUG,
272 "input byte, needed bits: "B2B_PAT"\n",
273 B2B(byte_input));
274 LOG (GNUNET_ERROR_TYPE_DEBUG,
275 "number of bits needed to align unaligned bit: %u\n",
276 num_bits_to_align);
234 num_bits_to_move = min (num_bits_to_align, num_bits_needed_iter); 277 num_bits_to_move = min (num_bits_to_align, num_bits_needed_iter);
278 LOG (GNUNET_ERROR_TYPE_DEBUG,
279 "number of bits of new byte to move: %u\n",
280 num_bits_to_move);
235 mask_input_to_move = ((char) 1 << num_bits_to_move) - 1; 281 mask_input_to_move = ((char) 1 << num_bits_to_move) - 1;
282 LOG (GNUNET_ERROR_TYPE_DEBUG,
283 "mask of bits of new byte to take for moving: "B2B_PAT"\n",
284 B2B(mask_input_to_move));
236 bits_to_move = byte_input & mask_input_to_move; 285 bits_to_move = byte_input & mask_input_to_move;
286 LOG (GNUNET_ERROR_TYPE_DEBUG,
287 "masked bits of new byte to take for moving: "B2B_PAT"\n",
288 B2B(bits_to_move));
237 distance_shift_bits = num_bits_buf_unaligned; 289 distance_shift_bits = num_bits_buf_unaligned;
290 LOG (GNUNET_ERROR_TYPE_DEBUG,
291 "distance needed to shift bits to their correct spot: %u\n",
292 distance_shift_bits);
238 bits_moving = bits_to_move << distance_shift_bits; 293 bits_moving = bits_to_move << distance_shift_bits;
294 LOG (GNUNET_ERROR_TYPE_DEBUG,
295 "shifted, masked bits of new byte being moved: "B2B_PAT"\n",
296 B2B(bits_moving));
239 byte_to_fill = buf_unaligned | bits_moving; 297 byte_to_fill = buf_unaligned | bits_moving;
240 if (num_bits_buf_unaligned + num_bits_needed_iter > 8) 298 LOG (GNUNET_ERROR_TYPE_DEBUG,
299 "byte being filled: "B2B_PAT"\n",
300 B2B(byte_to_fill));
301 LOG (GNUNET_ERROR_TYPE_DEBUG,
302 "pending bytes: %u\n",
303 num_bits_buf_unaligned + num_bits_needed_iter);
304 if (num_bits_buf_unaligned + num_bits_needed_iter >= 8)
241 { 305 {
242 /* buf_unaligned was aligned by filling 306 /* buf_unaligned was aligned by filling
243 * -> can be written to storage */ 307 * -> can be written to storage */
@@ -246,10 +310,22 @@ to_file_raw_unaligned (const char *file_name,
246 310
247 /* store the leftover, unaligned bits in buffer */ 311 /* store the leftover, unaligned bits in buffer */
248 mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move); 312 mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move);
313 LOG (GNUNET_ERROR_TYPE_DEBUG,
314 "mask of leftover bits of new byte: "B2B_PAT"\n",
315 B2B(mask_input_leftover));
249 byte_input_leftover = byte_input & mask_input_leftover; 316 byte_input_leftover = byte_input & mask_input_leftover;
317 LOG (GNUNET_ERROR_TYPE_DEBUG,
318 "masked, leftover bits of new byte: "B2B_PAT"\n",
319 B2B(byte_input_leftover));
250 num_bits_leftover = num_bits_needed_iter - num_bits_to_move; 320 num_bits_leftover = num_bits_needed_iter - num_bits_to_move;
251 num_bits_discard = 8 - num_bits_needed_iter; 321 LOG (GNUNET_ERROR_TYPE_DEBUG,
322 "number of unaligned bits left: %u\n",
323 num_bits_leftover);
324 //num_bits_discard = 8 - num_bits_needed_iter;
252 byte_unaligned_new = byte_input_leftover >> num_bits_to_move; 325 byte_unaligned_new = byte_input_leftover >> num_bits_to_move;
326 LOG (GNUNET_ERROR_TYPE_DEBUG,
327 "new unaligned byte: "B2B_PAT"\n",
328 B2B(byte_unaligned_new));
253 buf_unaligned = byte_unaligned_new; 329 buf_unaligned = byte_unaligned_new;
254 num_bits_buf_unaligned = num_bits_leftover % 8; 330 num_bits_buf_unaligned = num_bits_leftover % 8;
255 } 331 }
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c
index 254763b45..1083384f5 100644
--- a/src/set/gnunet-service-set_intersection.c
+++ b/src/set/gnunet-service-set_intersection.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*/
@@ -23,6 +23,7 @@
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
26#include "gnunet_statistics_service.h"
26#include "gnunet-service-set.h" 27#include "gnunet-service-set.h"
27#include "gnunet_block_lib.h" 28#include "gnunet_block_lib.h"
28#include "gnunet-service-set_protocol.h" 29#include "gnunet-service-set_protocol.h"
@@ -215,6 +216,10 @@ send_client_removed_element (struct Operation *op,
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
216 "Sending removed element (size %u) to client\n", 217 "Sending removed element (size %u) to client\n",
217 element->size); 218 element->size);
219 GNUNET_STATISTICS_update (_GSS_statistics,
220 "# Element removed messages sent",
221 1,
222 GNUNET_NO);
218 GNUNET_assert (0 != op->client_request_id); 223 GNUNET_assert (0 != op->client_request_id);
219 ev = GNUNET_MQ_msg_extra (rm, 224 ev = GNUNET_MQ_msg_extra (rm,
220 element->size, 225 element->size,
@@ -406,6 +411,10 @@ fail_intersection_operation (struct Operation *op)
406 411
407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 412 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
408 "Intersection operation failed\n"); 413 "Intersection operation failed\n");
414 GNUNET_STATISTICS_update (_GSS_statistics,
415 "# Intersection operations failed",
416 1,
417 GNUNET_NO);
409 if (NULL != op->state->my_elements) 418 if (NULL != op->state->my_elements)
410 { 419 {
411 GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements); 420 GNUNET_CONTAINER_multihashmap_destroy (op->state->my_elements);
@@ -466,6 +475,10 @@ send_bloomfilter (struct Operation *op)
466 op); 475 op);
467 476
468 /* send our Bloom filter */ 477 /* send our Bloom filter */
478 GNUNET_STATISTICS_update (_GSS_statistics,
479 "# Intersection Bloom filters sent",
480 1,
481 GNUNET_NO);
469 chunk_size = 60 * 1024 - sizeof (struct BFMessage); 482 chunk_size = 60 * 1024 - sizeof (struct BFMessage);
470 if (bf_size <= chunk_size) 483 if (bf_size <= chunk_size)
471 { 484 {
@@ -534,6 +547,10 @@ send_client_done_and_destroy (void *cls)
534 547
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
536 "Intersection succeeded, sending DONE to local client\n"); 549 "Intersection succeeded, sending DONE to local client\n");
550 GNUNET_STATISTICS_update (_GSS_statistics,
551 "# Intersection operations succeeded",
552 1,
553 GNUNET_NO);
537 ev = GNUNET_MQ_msg (rm, 554 ev = GNUNET_MQ_msg (rm,
538 GNUNET_MESSAGE_TYPE_SET_RESULT); 555 GNUNET_MESSAGE_TYPE_SET_RESULT);
539 rm->request_id = htonl (op->client_request_id); 556 rm->request_id = htonl (op->client_request_id);
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index 8c0c52d64..73d3f5c83 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.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*/
@@ -758,8 +758,8 @@ get_order_from_difference (unsigned int diff)
758 */ 758 */
759static int 759static int
760send_full_element_iterator (void *cls, 760send_full_element_iterator (void *cls,
761 const struct GNUNET_HashCode *key, 761 const struct GNUNET_HashCode *key,
762 void *value) 762 void *value)
763{ 763{
764 struct Operation *op = cls; 764 struct Operation *op = cls;
765 struct GNUNET_SET_ElementMessage *emsg; 765 struct GNUNET_SET_ElementMessage *emsg;
@@ -1367,6 +1367,26 @@ send_client_element (struct Operation *op,
1367 1367
1368 1368
1369/** 1369/**
1370 * Destroy remote channel.
1371 *
1372 * @param op operation
1373 */
1374static void
1375destroy_channel (struct Operation *op)
1376{
1377 struct GNUNET_CADET_Channel *channel;
1378
1379 if (NULL != (channel = op->channel))
1380 {
1381 /* This will free op; called conditionally as this helper function
1382 is also called from within the channel disconnect handler. */
1383 op->channel = NULL;
1384 GNUNET_CADET_channel_destroy (channel);
1385 }
1386}
1387
1388
1389/**
1370 * Signal to the client that the operation has finished and 1390 * Signal to the client that the operation has finished and
1371 * destroy the operation. 1391 * destroy the operation.
1372 * 1392 *
@@ -1379,13 +1399,18 @@ send_client_done (void *cls)
1379 struct GNUNET_MQ_Envelope *ev; 1399 struct GNUNET_MQ_Envelope *ev;
1380 struct GNUNET_SET_ResultMessage *rm; 1400 struct GNUNET_SET_ResultMessage *rm;
1381 1401
1382 if (GNUNET_YES == op->state->client_done_sent) { 1402 if (GNUNET_YES == op->state->client_done_sent)
1403 {
1383 return; 1404 return;
1384 } 1405 }
1385 1406
1386 if (PHASE_DONE != op->state->phase) { 1407 if (PHASE_DONE != op->state->phase) {
1387 LOG (GNUNET_ERROR_TYPE_WARNING, 1408 LOG (GNUNET_ERROR_TYPE_WARNING,
1388 "union operation failed\n"); 1409 "Union operation failed\n");
1410 GNUNET_STATISTICS_update (_GSS_statistics,
1411 "# Union operations failed",
1412 1,
1413 GNUNET_NO);
1389 ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT); 1414 ev = GNUNET_MQ_msg (rm, GNUNET_MESSAGE_TYPE_SET_RESULT);
1390 rm->result_status = htons (GNUNET_SET_STATUS_FAILURE); 1415 rm->result_status = htons (GNUNET_SET_STATUS_FAILURE);
1391 rm->request_id = htonl (op->client_request_id); 1416 rm->request_id = htonl (op->client_request_id);
@@ -1397,6 +1422,10 @@ send_client_done (void *cls)
1397 1422
1398 op->state->client_done_sent = GNUNET_YES; 1423 op->state->client_done_sent = GNUNET_YES;
1399 1424
1425 GNUNET_STATISTICS_update (_GSS_statistics,
1426 "# Union operations succeeded",
1427 1,
1428 GNUNET_NO);
1400 LOG (GNUNET_ERROR_TYPE_INFO, 1429 LOG (GNUNET_ERROR_TYPE_INFO,
1401 "Signalling client that union operation is done\n"); 1430 "Signalling client that union operation is done\n");
1402 ev = GNUNET_MQ_msg (rm, 1431 ev = GNUNET_MQ_msg (rm,
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 0ef3c864a..cd93ff855 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.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*/
@@ -65,6 +65,8 @@ report ()
65 unsigned long long datarate; 65 unsigned long long datarate;
66 66
67 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 67 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
68 if (0 == delta)
69 delta = 1;
68 datarate = (total_bytes_recv * 1000 * 1000) / delta; 70 datarate = (total_bytes_recv * 1000 * 1000) / delta;
69 71
70 FPRINTF (stderr, 72 FPRINTF (stderr,
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 86e2a7e9d..c6e77bae0 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.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*/
@@ -174,6 +174,8 @@ custom_shutdown (void *cls)
174 174
175 /* Calculcate statistics */ 175 /* Calculcate statistics */
176 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 176 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
177 if (0 == delta)
178 delta = 1;
177 rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); 179 rate = (1000LL* 1000ll * total_bytes) / (1024 * delta);
178 FPRINTF (stderr, 180 FPRINTF (stderr,
179 "\nThroughput was %llu KiBytes/s\n", 181 "\nThroughput was %llu KiBytes/s\n",
diff --git a/src/util/.gitignore b/src/util/.gitignore
index 23139a1ab..7b190ca76 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -69,3 +69,7 @@ perf_crypto_hash
69perf_crypto_symmetric 69perf_crypto_symmetric
70perf_crypto_rsa 70perf_crypto_rsa
71perf_crypto_ecc_dlog 71perf_crypto_ecc_dlog
72test_hexcoder
73test_regex
74test_tun
75gnunet-timeout
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index ec7bcb016..4ae073c2c 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -166,6 +166,7 @@ lib_LTLIBRARIES = libgnunetutil.la
166 166
167libexec_PROGRAMS = \ 167libexec_PROGRAMS = \
168 gnunet-service-resolver \ 168 gnunet-service-resolver \
169 gnunet-timeout \
169 $(W32CONSOLEHELPER) 170 $(W32CONSOLEHELPER)
170 171
171bin_SCRIPTS =\ 172bin_SCRIPTS =\
@@ -192,6 +193,15 @@ endif
192endif 193endif
193 194
194 195
196if !MINGW
197gnunet_timeout_SOURCES = \
198 gnunet-timeout.c
199else
200gnunet_timeout_SOURCES = \
201 gnunet-timeout-w32.c
202endif
203
204
195do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' 205do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g'
196 206
197gnunet-qr: gnunet-qr.py.in Makefile 207gnunet-qr: gnunet-qr.py.in Makefile
@@ -334,12 +344,12 @@ test_hexcoder_LDADD = \
334test_tun_SOURCES = \ 344test_tun_SOURCES = \
335 test_tun.c 345 test_tun.c
336test_tun_LDADD = \ 346test_tun_LDADD = \
337 libgnunetutil.la 347 libgnunetutil.la
338 348
339test_regex_SOURCES = \ 349test_regex_SOURCES = \
340 test_regex.c 350 test_regex.c
341test_regex_LDADD = \ 351test_regex_LDADD = \
342 libgnunetutil.la 352 libgnunetutil.la
343 353
344test_os_start_process_SOURCES = \ 354test_os_start_process_SOURCES = \
345 test_os_start_process.c 355 test_os_start_process.c
@@ -622,4 +632,4 @@ EXTRA_DIST = \
622 test_resolver_api_data.conf \ 632 test_resolver_api_data.conf \
623 test_service_data.conf \ 633 test_service_data.conf \
624 test_speedup_data.conf \ 634 test_speedup_data.conf \
625 gnunet-qr.py.in 635 gnunet-qr.py.in
diff --git a/src/util/client.c b/src/util/client.c
index 44e326eab..1f569255a 100644
--- a/src/util/client.c
+++ b/src/util/client.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*/
@@ -721,6 +721,17 @@ test_service_configuration (const char *service_name,
721 &unixpath)) && 721 &unixpath)) &&
722 (0 < strlen (unixpath))) 722 (0 < strlen (unixpath)))
723 ret = GNUNET_OK; 723 ret = GNUNET_OK;
724 else if ((GNUNET_OK ==
725 GNUNET_CONFIGURATION_have_value (cfg,
726 service_name,
727 "UNIXPATH")))
728 {
729 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
730 service_name,
731 "UNIXPATH",
732 _("not a valid filename"));
733 return GNUNET_SYSERR; /* UNIXPATH specified but invalid! */
734 }
724 GNUNET_free_non_null (unixpath); 735 GNUNET_free_non_null (unixpath);
725#endif 736#endif
726 737
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 8410b7835..fe1f58df7 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -365,14 +365,17 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
365 365
366/** 366/**
367 * Calculate HMAC of a message (RFC 2104) 367 * Calculate HMAC of a message (RFC 2104)
368 * TODO: Shouldn' this be the standard hmac function and
369 * the above be renamed?
368 * 370 *
369 * @param key secret key 371 * @param key secret key
372 * @param key_len secret key length
370 * @param plaintext input plaintext 373 * @param plaintext input plaintext
371 * @param plaintext_len length of @a plaintext 374 * @param plaintext_len length of @a plaintext
372 * @param hmac where to store the hmac 375 * @param hmac where to store the hmac
373 */ 376 */
374void 377void
375GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 378GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
376 const void *plaintext, size_t plaintext_len, 379 const void *plaintext, size_t plaintext_len,
377 struct GNUNET_HashCode *hmac) 380 struct GNUNET_HashCode *hmac)
378{ 381{
@@ -390,7 +393,7 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
390 { 393 {
391 gcry_md_reset (md); 394 gcry_md_reset (md);
392 } 395 }
393 gcry_md_setkey (md, key->key, sizeof (key->key)); 396 gcry_md_setkey (md, key, key_len);
394 gcry_md_write (md, plaintext, plaintext_len); 397 gcry_md_write (md, plaintext, plaintext_len);
395 mc = gcry_md_read (md, GCRY_MD_SHA512); 398 mc = gcry_md_read (md, GCRY_MD_SHA512);
396 GNUNET_assert (NULL != mc); 399 GNUNET_assert (NULL != mc);
@@ -399,6 +402,25 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
399 402
400 403
401/** 404/**
405 * Calculate HMAC of a message (RFC 2104)
406 *
407 * @param key secret key
408 * @param plaintext input plaintext
409 * @param plaintext_len length of @a plaintext
410 * @param hmac where to store the hmac
411 */
412void
413GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
414 const void *plaintext, size_t plaintext_len,
415 struct GNUNET_HashCode *hmac)
416{
417 GNUNET_CRYPTO_hmac_raw ((void*) key->key, sizeof (key->key),
418 plaintext, plaintext_len,
419 hmac);
420}
421
422
423/**
402 * Context for cummulative hashing. 424 * Context for cummulative hashing.
403 */ 425 */
404struct GNUNET_HashContext 426struct GNUNET_HashContext
diff --git a/src/util/dnsparser.c b/src/util/dnsparser.c
index cce68f2ee..24f1b18cf 100644
--- a/src/util/dnsparser.c
+++ b/src/util/dnsparser.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 */
@@ -759,6 +759,122 @@ GNUNET_DNSPARSER_parse (const char *udp_payload,
759 759
760 760
761/** 761/**
762 * Duplicate (deep-copy) the given DNS record
763 *
764 * @param r the record
765 * @return the newly allocated record
766 */
767struct GNUNET_DNSPARSER_Record *
768GNUNET_DNSPARSER_duplicate_record (const struct GNUNET_DNSPARSER_Record *r)
769{
770 struct GNUNET_DNSPARSER_Record *dup = GNUNET_memdup (r, sizeof (*r));
771
772 dup->name = GNUNET_strdup (r->name);
773 switch (r->type)
774 {
775 case GNUNET_DNSPARSER_TYPE_NS:
776 case GNUNET_DNSPARSER_TYPE_CNAME:
777 case GNUNET_DNSPARSER_TYPE_PTR:
778 {
779 dup->data.hostname = GNUNET_strdup (r->data.hostname);
780 break;
781 }
782 case GNUNET_DNSPARSER_TYPE_SOA:
783 {
784 dup->data.soa = GNUNET_DNSPARSER_duplicate_soa_record (r->data.soa);
785 break;
786 }
787 case GNUNET_DNSPARSER_TYPE_CERT:
788 {
789 dup->data.cert = GNUNET_DNSPARSER_duplicate_cert_record (r->data.cert);
790 break;
791 }
792 case GNUNET_DNSPARSER_TYPE_MX:
793 {
794 dup->data.mx = GNUNET_DNSPARSER_duplicate_mx_record (r->data.mx);
795 break;
796 }
797 case GNUNET_DNSPARSER_TYPE_SRV:
798 {
799 dup->data.srv = GNUNET_DNSPARSER_duplicate_srv_record (r->data.srv);
800 break;
801 }
802 default:
803 {
804 dup->data.raw.data = GNUNET_memdup (r->data.raw.data,
805 r->data.raw.data_len);
806 }
807 }
808 return dup;
809}
810
811
812/**
813 * Duplicate (deep-copy) the given DNS record
814 *
815 * @param r the record
816 * @return the newly allocated record
817 */
818struct GNUNET_DNSPARSER_SoaRecord *
819GNUNET_DNSPARSER_duplicate_soa_record (const struct GNUNET_DNSPARSER_SoaRecord *r)
820{
821 struct GNUNET_DNSPARSER_SoaRecord *dup = GNUNET_memdup (r, sizeof (*r));
822
823 dup->mname = GNUNET_strdup (r->mname);
824 dup->rname = GNUNET_strdup (r->rname);
825 return dup;
826}
827
828
829/**
830 * Duplicate (deep-copy) the given DNS record
831 *
832 * @param r the record
833 * @return the newly allocated record
834 */
835struct GNUNET_DNSPARSER_CertRecord *
836GNUNET_DNSPARSER_duplicate_cert_record (const struct GNUNET_DNSPARSER_CertRecord *r)
837{
838 struct GNUNET_DNSPARSER_CertRecord *dup = GNUNET_memdup (r, sizeof (*r));
839
840 dup->certificate_data = GNUNET_strdup (r->certificate_data);
841 return dup;
842}
843
844
845/**
846 * Duplicate (deep-copy) the given DNS record
847 *
848 * @param r the record
849 * @return the newly allocated record
850 */
851struct GNUNET_DNSPARSER_MxRecord *
852GNUNET_DNSPARSER_duplicate_mx_record (const struct GNUNET_DNSPARSER_MxRecord *r)
853{
854 struct GNUNET_DNSPARSER_MxRecord *dup = GNUNET_memdup (r, sizeof (*r));
855
856 dup->mxhost = GNUNET_strdup (r->mxhost);
857 return dup;
858}
859
860
861/**
862 * Duplicate (deep-copy) the given DNS record
863 *
864 * @param r the record
865 * @return the newly allocated record
866 */
867struct GNUNET_DNSPARSER_SrvRecord *
868GNUNET_DNSPARSER_duplicate_srv_record (const struct GNUNET_DNSPARSER_SrvRecord *r)
869{
870 struct GNUNET_DNSPARSER_SrvRecord *dup = GNUNET_memdup (r, sizeof (*r));
871
872 dup->target = GNUNET_strdup (r->target);
873 return dup;
874}
875
876
877/**
762 * Free memory taken by a packet. 878 * Free memory taken by a packet.
763 * 879 *
764 * @param p packet to free 880 * @param p packet to free
@@ -840,8 +956,11 @@ GNUNET_DNSPARSER_builder_add_name (char *dst,
840 len = dot - idna_name; 956 len = dot - idna_name;
841 if ( (len >= 64) || (0 == len) ) 957 if ( (len >= 64) || (0 == len) )
842 { 958 {
843 GNUNET_break (0); 959 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
844 goto fail; /* segment too long or empty */ 960 "Invalid DNS name `%s': label with %u characters encountered\n",
961 name,
962 (unsigned int) len);
963 goto fail; /* label too long or empty */
845 } 964 }
846 dst[pos++] = (char) (uint8_t) len; 965 dst[pos++] = (char) (uint8_t) len;
847 GNUNET_memcpy (&dst[pos], 966 GNUNET_memcpy (&dst[pos],
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index d90d8ec10..5b890261b 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -27,721 +27,559 @@
27#include "gnunet_statistics_service.h" 27#include "gnunet_statistics_service.h"
28#include "resolver.h" 28#include "resolver.h"
29 29
30
31struct Record
32{
33 struct Record *next;
34
35 struct Record *prev;
36
37 struct GNUNET_DNSPARSER_Record *record;
38};
39
30/** 40/**
31 * A cached DNS lookup result (for reverse lookup). 41 * A cached DNS lookup result.
32 */ 42 */
33struct IPCache 43struct ResolveCache
34{ 44{
35 /** 45 /**
36 * This is a doubly linked list. 46 * This is a doubly linked list.
37 */ 47 */
38 struct IPCache *next; 48 struct ResolveCache *next;
39 49
40 /** 50 /**
41 * This is a doubly linked list. 51 * This is a doubly linked list.
42 */ 52 */
43 struct IPCache *prev; 53 struct ResolveCache *prev;
44 54
45 /** 55 /**
46 * Hostname in human-readable form. 56 * type of queried DNS record
47 */ 57 */
48 char *addr; 58 uint16_t record_type;
49 59
50 /** 60 /**
51 * Binary IP address, allocated at the end of this struct. 61 * a pointer to the request_id if a query for this hostname/record_type
62 * is currently pending, NULL otherwise.
52 */ 63 */
53 const void *ip; 64 int16_t *request_id;
54 65
55 /** 66 /**
56 * Last time this entry was updated. 67 * The client that queried the records contained in this cache entry.
57 */ 68 */
58 struct GNUNET_TIME_Absolute last_refresh; 69 struct GNUNET_SERVICE_Client *client;
59 70
60 /** 71 /**
61 * Last time this entry was requested. 72 * head of a double linked list containing the lookup results
62 */ 73 */
63 struct GNUNET_TIME_Absolute last_request; 74 struct Record *records_head;
64 75
65 /** 76 /**
66 * Number of bytes in ip. 77 * tail of a double linked list containing the lookup results
67 */ 78 */
68 size_t ip_len; 79 struct Record *records_tail;
69 80
70 /** 81 /**
71 * Address family of the IP. 82 * handle for cancelling a request
72 */ 83 */
73 int af; 84 struct GNUNET_DNSSTUB_RequestSocket *resolve_handle;
85
86 /**
87 * handle for the resolution timeout task
88 */
89 struct GNUNET_SCHEDULER_Task *timeout_task;
90
74}; 91};
75 92
76 93
77/** 94/**
78 * Start of the linked list of cached DNS lookup results. 95 * Start of the linked list of cached DNS lookup results.
79 */ 96 */
80static struct IPCache *cache_head; 97static struct ResolveCache *cache_head;
81 98
82/** 99/**
83 * Tail of the linked list of cached DNS lookup results. 100 * Tail of the linked list of cached DNS lookup results.
84 */ 101 */
85static struct IPCache *cache_tail; 102static struct ResolveCache *cache_tail;
86 103
87/** 104/**
88 * Pipe for asynchronously notifying about resolve result 105 * context of dnsstub library
89 */ 106 */
90static struct GNUNET_DISK_PipeHandle *resolve_result_pipe; 107static struct GNUNET_DNSSTUB_Context *dnsstub_ctx;
91 108
92/**
93 * Task for reading from resolve_result_pipe
94 */
95static struct GNUNET_SCHEDULER_Task *resolve_result_pipe_task;
96 109
97 110void free_cache_entry (struct ResolveCache *entry)
98#if HAVE_GETNAMEINFO
99/**
100 * Resolve the given request using getnameinfo
101 *
102 * @param cache the request to resolve (and where to store the result)
103 */
104static void
105getnameinfo_resolve (struct IPCache *cache)
106{ 111{
107 char hostname[256]; 112 struct Record *pos;
108 const struct sockaddr *sa; 113 struct Record *next;
109 struct sockaddr_in v4; 114
110 struct sockaddr_in6 v6; 115 next = entry->records_head;
111 size_t salen; 116 while (NULL != (pos = next))
112 int ret;
113
114 switch (cache->af)
115 { 117 {
116 case AF_INET: 118 next = pos->next;
117 GNUNET_assert (cache->ip_len == sizeof (struct in_addr)); 119 GNUNET_CONTAINER_DLL_remove (entry->records_head,
118 sa = (const struct sockaddr*) &v4; 120 entry->records_tail,
119 memset (&v4, 0, sizeof (v4)); 121 pos);
120 v4.sin_addr = * (const struct in_addr*) cache->ip; 122 if (NULL != pos->record)
121 v4.sin_family = AF_INET; 123 {
122#if HAVE_SOCKADDR_IN_SIN_LEN 124 GNUNET_DNSPARSER_free_record (pos->record);
123 v4.sin_len = sizeof (v4); 125 GNUNET_free (pos->record);
124#endif 126 }
125 salen = sizeof (v4); 127 GNUNET_free (pos);
126 break;
127 case AF_INET6:
128 GNUNET_assert (cache->ip_len == sizeof (struct in6_addr));
129 sa = (const struct sockaddr*) &v6;
130 memset (&v6, 0, sizeof (v6));
131 v6.sin6_addr = * (const struct in6_addr*) cache->ip;
132 v6.sin6_family = AF_INET6;
133#if HAVE_SOCKADDR_IN_SIN_LEN
134 v6.sin6_len = sizeof (v6);
135#endif
136 salen = sizeof (v6);
137 break;
138 default:
139 GNUNET_assert (0);
140 } 128 }
141 129 if (NULL != entry->resolve_handle)
142 if (0 ==
143 (ret = getnameinfo (sa, salen,
144 hostname, sizeof (hostname),
145 NULL,
146 0, 0)))
147 { 130 {
148 cache->addr = GNUNET_strdup (hostname); 131 GNUNET_DNSSTUB_resolve_cancel (entry->resolve_handle);
132 entry->resolve_handle = NULL;
149 } 133 }
150 else 134 if (NULL != entry->timeout_task)
151 { 135 {
152 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 136 GNUNET_SCHEDULER_cancel (entry->timeout_task);
153 "getnameinfo failed: %s\n", 137 entry->timeout_task = NULL;
154 gai_strerror (ret));
155 } 138 }
139 GNUNET_free_non_null (entry->request_id);
140 GNUNET_free (entry);
156} 141}
157#endif
158 142
159 143
160#if HAVE_GETHOSTBYADDR 144static char*
145extract_dns_server (const char* line, size_t line_len)
146{
147 if (0 == strncmp (line, "nameserver ", 11))
148 return GNUNET_strndup (line + 11, line_len - 11);
149 return NULL;
150}
151
152
161/** 153/**
162 * Resolve the given request using gethostbyaddr 154 * reads the list of nameservers from /etc/resolve.conf
163 * 155 *
164 * @param cache the request to resolve (and where to store the result) 156 * @param server_addrs[out] a list of null-terminated server address strings
157 * @return the number of server addresses in @server_addrs, -1 on error
165 */ 158 */
166static void 159static ssize_t
167gethostbyaddr_resolve (struct IPCache *cache) 160lookup_dns_servers (char ***server_addrs)
168{ 161{
169 struct hostent *ent; 162 struct GNUNET_DISK_FileHandle *fh;
170 163 char buf[2048];
171 ent = gethostbyaddr (cache->ip, 164 ssize_t bytes_read;
172 cache->ip_len, 165 size_t read_offset = 0;
173 cache->af); 166 unsigned int num_dns_servers = 0;
174 if (NULL != ent) 167
168 fh = GNUNET_DISK_file_open ("/etc/resolv.conf",
169 GNUNET_DISK_OPEN_READ,
170 GNUNET_DISK_PERM_NONE);
171 if (NULL == fh)
175 { 172 {
176 cache->addr = GNUNET_strdup (ent->h_name); 173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
174 "Could not open /etc/resolv.conf. "
175 "DNS resolution will not be possible.\n");
176 return -1;
177 } 177 }
178 else 178 bytes_read = GNUNET_DISK_file_read (fh,
179 buf,
180 sizeof (buf));
181 *server_addrs = NULL;
182 while (read_offset < bytes_read)
179 { 183 {
180 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 184 char *newline;
181 "gethostbyaddr failed: %s\n", 185 size_t line_len;
182 hstrerror (h_errno)); 186 char *dns_server;
187
188 newline = strchr (buf + read_offset, '\n');
189 if (NULL == newline)
190 {
191 break;
192 }
193 line_len = newline - buf - read_offset;
194 dns_server = extract_dns_server (buf + read_offset, line_len);
195 if (NULL != dns_server)
196 {
197 GNUNET_array_append (*server_addrs,
198 num_dns_servers,
199 dns_server);
200 }
201 read_offset += line_len + 1;
183 } 202 }
203 GNUNET_DISK_file_close (fh);
204 return num_dns_servers;
184} 205}
185#endif
186 206
187 207
188/** 208static char *
189 * Resolve the given request using the available methods. 209make_reverse_hostname (const void *ip, int af)
190 *
191 * @param cache the request to resolve (and where to store the result)
192 */
193static void
194cache_resolve (struct IPCache *cache)
195{ 210{
196#if HAVE_GETNAMEINFO 211 char *buf = GNUNET_new_array (80, char);
197 if (NULL == cache->addr) 212 int pos = 0;
198 getnameinfo_resolve (cache); 213 if (AF_INET == af)
199#endif 214 {
200#if HAVE_GETHOSTBYADDR 215 struct in_addr *addr = (struct in_addr *)ip;
201 if (NULL == cache->addr) 216 uint32_t ip_int = addr->s_addr;
202 gethostbyaddr_resolve (cache); 217 for (int i = 3; i >= 0; i--)
203#endif 218 {
219 int n = GNUNET_snprintf (buf + pos,
220 80 - pos,
221 "%u.",
222 ((uint8_t *)&ip_int)[i]);
223 if (n < 0)
224 {
225 GNUNET_free (buf);
226 return NULL;
227 }
228 pos += n;
229 }
230 pos += GNUNET_snprintf (buf + pos, 80 - pos, "in-addr.arpa");
231 }
232 else if (AF_INET6 == af)
233 {
234 struct in6_addr *addr = (struct in6_addr *)ip;
235 for (int i = 15; i >= 0; i--)
236 {
237 int n = GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] & 0xf);
238 if (n < 0)
239 {
240 GNUNET_free (buf);
241 return NULL;
242 }
243 pos += n;
244 n = GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] >> 4);
245 if (n < 0)
246 {
247 GNUNET_free (buf);
248 return NULL;
249 }
250 pos += n;
251 }
252 pos += GNUNET_snprintf (buf + pos, 80 - pos, "ip6.arpa");
253 }
254 buf[pos] = '\0';
255 return buf;
204} 256}
205 257
206 258
207/**
208 * Function called after the replies for the request have all
209 * been transmitted to the client, and we can now read the next
210 * request from the client.
211 *
212 * @param cls the `struct GNUNET_SERVICE_Client` to continue with
213 */
214static void 259static void
215notify_service_client_done (void *cls) 260send_reply (struct GNUNET_DNSPARSER_Record *record,
261 uint16_t request_id,
262 struct GNUNET_SERVICE_Client *client)
216{ 263{
217 struct GNUNET_SERVICE_Client *client = cls;
218
219 GNUNET_SERVICE_client_continue (client);
220}
221
222
223/**
224 * Get an IP address as a string (works for both IPv4 and IPv6). Note
225 * that the resolution happens asynchronously and that the first call
226 * may not immediately result in the FQN (but instead in a
227 * human-readable IP address).
228 *
229 * @param client handle to the client making the request (for sending the reply)
230 * @param af AF_INET or AF_INET6
231 * @param ip `struct in_addr` or `struct in6_addr`
232 */
233static void
234get_ip_as_string (struct GNUNET_SERVICE_Client *client,
235 int af,
236 const void *ip,
237 uint32_t request_id)
238{
239 struct IPCache *pos;
240 struct IPCache *next;
241 struct GNUNET_TIME_Absolute now;
242 struct GNUNET_MQ_Envelope *env;
243 struct GNUNET_MQ_Handle *mq;
244 struct GNUNET_RESOLVER_ResponseMessage *msg; 264 struct GNUNET_RESOLVER_ResponseMessage *msg;
245 size_t ip_len; 265 struct GNUNET_MQ_Envelope *env;
246 struct in6_addr ix; 266 void *payload;
247 size_t alen; 267 size_t payload_len;
248 268
249 switch (af) 269 switch (record->type)
250 {
251 case AF_INET:
252 ip_len = sizeof (struct in_addr);
253 break;
254 case AF_INET6:
255 ip_len = sizeof (struct in6_addr);
256 break;
257 default:
258 GNUNET_assert (0);
259 }
260 now = GNUNET_TIME_absolute_get ();
261 next = cache_head;
262 while ( (NULL != (pos = next)) &&
263 ( (pos->af != af) ||
264 (pos->ip_len != ip_len) ||
265 (0 != memcmp (pos->ip, ip, ip_len))) )
266 { 270 {
267 next = pos->next; 271 case GNUNET_DNSPARSER_TYPE_PTR:
268 if (GNUNET_TIME_absolute_get_duration (pos->last_request).rel_value_us <
269 60 * 60 * 1000 * 1000LL)
270 { 272 {
271 GNUNET_CONTAINER_DLL_remove (cache_head, 273 char *hostname = record->data.hostname;
272 cache_tail, 274 payload = hostname;
273 pos); 275 payload_len = strlen (hostname) + 1;
274 GNUNET_free_non_null (pos->addr); 276 break;
275 GNUNET_free (pos);
276 continue;
277 } 277 }
278 } 278 case GNUNET_DNSPARSER_TYPE_A:
279 if (NULL != pos) 279 case GNUNET_DNSPARSER_TYPE_AAAA:
280 {
281 if ( (1 == inet_pton (af,
282 pos->ip,
283 &ix)) &&
284 (GNUNET_TIME_absolute_get_duration (pos->last_request).rel_value_us >
285 120 * 1000 * 1000LL) )
286 { 280 {
287 /* try again if still numeric AND 2 minutes have expired */ 281 payload = record->data.raw.data;
288 GNUNET_free_non_null (pos->addr); 282 payload_len = record->data.raw.data_len;
289 pos->addr = NULL; 283 break;
290 cache_resolve (pos); 284 }
291 pos->last_request = now; 285 default:
286 {
287 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
288 "Cannot handle DNS response type: unimplemented\n");
289 return;
292 } 290 }
293 } 291 }
294 else
295 {
296 pos = GNUNET_malloc (sizeof (struct IPCache) + ip_len);
297 pos->ip = &pos[1];
298 GNUNET_memcpy (&pos[1],
299 ip,
300 ip_len);
301 pos->last_request = now;
302 pos->last_refresh = now;
303 pos->ip_len = ip_len;
304 pos->af = af;
305 GNUNET_CONTAINER_DLL_insert (cache_head,
306 cache_tail,
307 pos);
308 cache_resolve (pos);
309 }
310 if (NULL != pos->addr)
311 alen = strlen (pos->addr) + 1;
312 else
313 alen = 0;
314 mq = GNUNET_SERVICE_client_get_mq (client);
315 env = GNUNET_MQ_msg_extra (msg, 292 env = GNUNET_MQ_msg_extra (msg,
316 alen, 293 payload_len,
317 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 294 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
318 msg->id = request_id; 295 msg->id = request_id;
319 GNUNET_memcpy (&msg[1], 296 GNUNET_memcpy (&msg[1],
320 pos->addr, 297 payload,
321 alen); 298 payload_len);
322 GNUNET_MQ_send (mq, 299 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
323 env); 300 env);
324 // send end message
325 env = GNUNET_MQ_msg (msg,
326 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
327 msg->id = request_id;
328 GNUNET_MQ_notify_sent (env,
329 &notify_service_client_done,
330 client);
331 GNUNET_MQ_send (mq,
332 env);
333} 301}
334 302
335 303
336#if HAVE_GETADDRINFO_A
337struct AsyncCls
338{
339 struct gaicb *host;
340 struct sigevent *sig;
341 struct GNUNET_MQ_Handle *mq;
342 uint32_t request_id;
343};
344
345
346static void 304static void
347resolve_result_pipe_cb (void *cls) 305send_end_msg (uint16_t request_id,
306 struct GNUNET_SERVICE_Client *client)
348{ 307{
349 struct AsyncCls *async_cls;
350 struct gaicb *host;
351 struct GNUNET_RESOLVER_ResponseMessage *msg; 308 struct GNUNET_RESOLVER_ResponseMessage *msg;
352 struct GNUNET_MQ_Envelope *env; 309 struct GNUNET_MQ_Envelope *env;
353 310
354 GNUNET_DISK_file_read (GNUNET_DISK_pipe_handle (resolve_result_pipe, 311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
355 GNUNET_DISK_PIPE_END_READ), 312 "Sending end message\n");
356 &async_cls, 313 env = GNUNET_MQ_msg (msg,
357 sizeof (struct AsyncCls *)); 314 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
358 resolve_result_pipe_task = 315 msg->id = request_id;
359 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 316 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
360 GNUNET_DISK_pipe_handle (resolve_result_pipe, 317 env);
361 GNUNET_DISK_PIPE_END_READ), 318}
362 &resolve_result_pipe_cb, 319
363 NULL); 320
364 host = async_cls->host; 321static void
365 for (struct addrinfo *pos = host->ar_result; pos != NULL; pos = pos->ai_next) 322handle_resolve_result (void *cls,
323 const struct GNUNET_TUN_DnsHeader *dns,
324 size_t dns_len)
325{
326 struct ResolveCache *cache = cls;
327 struct GNUNET_DNSPARSER_Packet *parsed;
328 uint16_t request_id = *cache->request_id;
329 struct GNUNET_SERVICE_Client *client = cache->client;
330
331 parsed = GNUNET_DNSPARSER_parse ((const char *)dns,
332 dns_len);
333 if (NULL == parsed)
334 {
335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
336 "Failed to parse DNS reply (request ID %u\n",
337 request_id);
338 return;
339 }
340 if (request_id != ntohs (parsed->id))
341 {
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
343 "Request ID in DNS reply does not match\n");
344 return;
345 }
346 else if (0 == parsed->num_answers)
347 {
348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
349 "DNS reply (request ID %u) contains no answers\n",
350 request_id);
351 GNUNET_CONTAINER_DLL_remove (cache_head,
352 cache_tail,
353 cache);
354 free_cache_entry (cache);
355 cache = NULL;
356 }
357 else
366 { 358 {
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "Lookup result for hostname %s: %s (request ID %u)\n", 360 "Got reply for request ID %u\n",
369 host->ar_name, 361 request_id);
370 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen), 362 for (unsigned int i = 0; i != parsed->num_answers; i++)
371 async_cls->request_id);
372 switch (pos->ai_family)
373 { 363 {
374 case AF_INET: 364 struct Record *cache_entry = GNUNET_new (struct Record);
375 env = GNUNET_MQ_msg_extra (msg, 365 struct GNUNET_DNSPARSER_Record *record = &parsed->answers[i];
376 sizeof (struct in_addr), 366 cache_entry->record = GNUNET_DNSPARSER_duplicate_record (record);
377 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 367 GNUNET_CONTAINER_DLL_insert (cache->records_head,
378 msg->id = async_cls->request_id; 368 cache->records_tail,
379 GNUNET_memcpy (&msg[1], 369 cache_entry);
380 &((struct sockaddr_in*) pos->ai_addr)->sin_addr, 370 send_reply (cache_entry->record,
381 sizeof (struct in_addr)); 371 request_id,
382 GNUNET_MQ_send (async_cls->mq, 372 cache->client);
383 env);
384 break;
385 case AF_INET6:
386 env = GNUNET_MQ_msg_extra (msg,
387 sizeof (struct in6_addr),
388 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
389 msg->id = async_cls->request_id;
390 GNUNET_memcpy (&msg[1],
391 &((struct sockaddr_in6*) pos->ai_addr)->sin6_addr,
392 sizeof (struct in6_addr));
393 GNUNET_MQ_send (async_cls->mq,
394 env);
395 break;
396 default:
397 /* unsupported, skip */
398 break;
399 } 373 }
374 GNUNET_free_non_null (cache->request_id);
375 cache->request_id = NULL;
400 } 376 }
401 // send end message 377 send_end_msg (request_id,
402 env = GNUNET_MQ_msg (msg, 378 client);
403 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 379 if (NULL != cache)
404 msg->id = async_cls->request_id; 380 cache->client = NULL;
405 GNUNET_MQ_send (async_cls->mq, 381 if (NULL != cache)
406 env); 382 {
407 freeaddrinfo (host->ar_result); 383 if (NULL != cache->timeout_task)
408 GNUNET_free ((struct gaicb *)host->ar_request); // free hints 384 {
409 GNUNET_free (host); 385 GNUNET_SCHEDULER_cancel (cache->timeout_task);
410 GNUNET_free (async_cls->sig); 386 cache->timeout_task = NULL;
411 GNUNET_free (async_cls); 387 }
388 if (NULL != cache->resolve_handle)
389 {
390 GNUNET_DNSSTUB_resolve_cancel (cache->resolve_handle);
391 cache->resolve_handle = NULL;
392 }
393 }
394 GNUNET_DNSPARSER_free_packet (parsed);
412} 395}
413 396
414 397
415static void 398static void
416handle_async_result (union sigval val) 399handle_resolve_timeout (void *cls)
417{ 400{
418 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (resolve_result_pipe, 401 struct ResolveCache *cache = cls;
419 GNUNET_DISK_PIPE_END_WRITE), 402
420 &val.sival_ptr, 403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
421 sizeof (val.sival_ptr)); 404 "timeout!\n");
405 if (NULL != cache->resolve_handle)
406 {
407 GNUNET_DNSSTUB_resolve_cancel (cache->resolve_handle);
408 cache->resolve_handle = NULL;
409 }
410 GNUNET_CONTAINER_DLL_remove (cache_head,
411 cache_tail,
412 cache);
413 free_cache_entry (cache);
422} 414}
423 415
424 416
425static int 417static int
426getaddrinfo_a_resolve (struct GNUNET_MQ_Handle *mq, 418resolve_and_cache (const char* hostname,
427 const char *hostname, 419 uint16_t record_type,
428 int af, 420 uint16_t request_id,
429 uint32_t request_id) 421 struct GNUNET_SERVICE_Client *client)
430{ 422{
431 int ret; 423 char *packet_buf;
432 struct gaicb *host; 424 size_t packet_size;
433 struct addrinfo *hints; 425 struct GNUNET_DNSPARSER_Query query;
434 struct sigevent *sig; 426 struct GNUNET_DNSPARSER_Packet packet;
435 struct AsyncCls *async_cls; 427 struct ResolveCache *cache;
436 428 struct GNUNET_TIME_Relative timeout =
437 host = GNUNET_new (struct gaicb); 429 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5);
438 hints = GNUNET_new (struct addrinfo); 430
439 sig = GNUNET_new (struct sigevent); 431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 async_cls = GNUNET_new (struct AsyncCls); 432 "resolve_and_cache\n");
441 memset (hints, 433 query.name = (char *)hostname;
434 query.type = record_type;
435 query.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
436 memset (&packet,
442 0, 437 0,
443 sizeof (struct addrinfo)); 438 sizeof (packet));
444 memset (sig, 439 packet.num_queries = 1;
445 0, 440 packet.queries = &query;
446 sizeof (struct sigevent)); 441 packet.id = htons (request_id);
447 hints->ai_family = af; 442 packet.flags.recursion_desired = 1;
448 hints->ai_socktype = SOCK_STREAM; /* go for TCP */ 443 if (GNUNET_OK !=
449 host->ar_name = hostname; 444 GNUNET_DNSPARSER_pack (&packet,
450 host->ar_service = NULL; 445 UINT16_MAX,
451 host->ar_request = hints; 446 &packet_buf,
452 host->ar_result = NULL; 447 &packet_size))
453 sig->sigev_notify = SIGEV_THREAD; 448 {
454 sig->sigev_value.sival_ptr = async_cls; 449 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
455 sig->sigev_notify_function = &handle_async_result; 450 "Failed to pack query for hostname `%s'\n",
456 async_cls->host = host; 451 hostname);
457 async_cls->sig = sig;
458 async_cls->mq = mq;
459 async_cls->request_id = request_id;
460 ret = getaddrinfo_a (GAI_NOWAIT,
461 &host,
462 1,
463 sig);
464 if (0 != ret)
465 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
453
454 }
455 cache = GNUNET_malloc (sizeof (struct ResolveCache));
456 cache->record_type = record_type;
457 cache->request_id = GNUNET_memdup (&request_id, sizeof (request_id));
458 cache->client = client;
459 cache->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
460 &handle_resolve_timeout,
461 cache);
462 cache->resolve_handle =
463 GNUNET_DNSSTUB_resolve (dnsstub_ctx,
464 packet_buf,
465 packet_size,
466 &handle_resolve_result,
467 cache);
468 GNUNET_CONTAINER_DLL_insert (cache_head,
469 cache_tail,
470 cache);
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "resolve %s, request_id = %u\n",
473 hostname,
474 request_id);
475 GNUNET_free (packet_buf);
466 return GNUNET_OK; 476 return GNUNET_OK;
467} 477}
468 478
469 479
470#elif HAVE_GETADDRINFO 480static const char *
471static int 481get_hostname (struct ResolveCache *cache_entry)
472getaddrinfo_resolve (struct GNUNET_MQ_Handle *mq,
473 const char *hostname,
474 int af,
475 uint32_t request_id)
476{ 482{
477 int s; 483 if (NULL != cache_entry->records_head)
478 struct addrinfo hints;
479 struct addrinfo *result;
480 struct addrinfo *pos;
481 struct GNUNET_RESOLVER_ResponseMessage *msg;
482 struct GNUNET_MQ_Envelope *env;
483
484#ifdef WINDOWS
485 /* Due to a bug, getaddrinfo will not return a mix of different families */
486 if (AF_UNSPEC == af)
487 { 484 {
488 int ret1; 485 GNUNET_assert (NULL != cache_entry->records_head);
489 int ret2; 486 GNUNET_assert (NULL != cache_entry->records_head->record);
490 ret1 = getaddrinfo_resolve (mq, 487 GNUNET_assert (NULL != cache_entry->records_head->record->name);
491 hostname, 488 return cache_entry->records_head->record->name;
492 AF_INET,
493 request_id);
494 ret2 = getaddrinfo_resolve (mq,
495 hostname,
496 AF_INET6,
497 request_id);
498 if ( (ret1 == GNUNET_OK) ||
499 (ret2 == GNUNET_OK) )
500 return GNUNET_OK;
501 if ( (ret1 == GNUNET_SYSERR) ||
502 (ret2 == GNUNET_SYSERR) )
503 return GNUNET_SYSERR;
504 return GNUNET_NO;
505 } 489 }
506#endif 490 return NULL;
507
508 memset (&hints,
509 0,
510 sizeof (struct addrinfo));
511 hints.ai_family = af;
512 hints.ai_socktype = SOCK_STREAM; /* go for TCP */
513
514 if (0 != (s = getaddrinfo (hostname,
515 NULL,
516 &hints,
517 &result)))
518 {
519 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
520 _("Could not resolve `%s' (%s): %s\n"),
521 hostname,
522 (af ==
523 AF_INET) ? "IPv4" : ((af == AF_INET6) ? "IPv6" : "any"),
524 gai_strerror (s));
525 if ( (s == EAI_BADFLAGS) ||
526#ifndef WINDOWS
527 (s == EAI_SYSTEM) ||
528#endif
529 (s == EAI_MEMORY) )
530 return GNUNET_NO; /* other function may still succeed */
531 return GNUNET_SYSERR;
532 }
533 if (NULL == result)
534 return GNUNET_SYSERR;
535 for (pos = result; pos != NULL; pos = pos->ai_next)
536 {
537 switch (pos->ai_family)
538 {
539 case AF_INET:
540 env = GNUNET_MQ_msg_extra (msg,
541 sizeof (struct in_addr),
542 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
543 msg->id = request_id;
544 GNUNET_memcpy (&msg[1],
545 &((struct sockaddr_in*) pos->ai_addr)->sin_addr,
546 sizeof (struct in_addr));
547 GNUNET_MQ_send (mq,
548 env);
549 break;
550 case AF_INET6:
551 env = GNUNET_MQ_msg_extra (msg,
552 sizeof (struct in6_addr),
553 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
554 msg->id = request_id;
555 GNUNET_memcpy (&msg[1],
556 &((struct sockaddr_in6*) pos->ai_addr)->sin6_addr,
557 sizeof (struct in6_addr));
558 GNUNET_MQ_send (mq,
559 env);
560 break;
561 default:
562 /* unsupported, skip */
563 break;
564 }
565 }
566 freeaddrinfo (result);
567 return GNUNET_OK;
568} 491}
569 492
570 493
571#elif HAVE_GETHOSTBYNAME2 494static const uint16_t *
572 495get_record_type (struct ResolveCache *cache_entry)
573
574static int
575gethostbyname2_resolve (struct GNUNET_MQ_Handle *mq,
576 const char *hostname,
577 int af,
578 uint32_t request_id)
579{ 496{
580 struct hostent *hp; 497 if (NULL != cache_entry->records_head)
581 int ret1; 498 return &cache_entry->record_type;
582 int ret2; 499 return NULL;
583 struct GNUNET_MQ_Envelope *env; 500}
584 struct GNUNET_RESOLVER_ResponseMessage *msg;
585 501
586#ifdef WINDOWS
587 /* gethostbyname2() in plibc is a compat dummy that calls gethostbyname(). */
588 return GNUNET_NO;
589#endif
590 502
591 if (af == AF_UNSPEC) 503static const struct GNUNET_TIME_Absolute *
592 { 504get_expiration_time (struct ResolveCache *cache_entry)
593 ret1 = gethostbyname2_resolve (mq, 505{
594 hostname, 506 if (NULL != cache_entry->records_head)
595 AF_INET, 507 return &cache_entry->records_head->record->expiration_time;
596 request_id); 508 return NULL;
597 ret2 = gethostbyname2_resolve (mq,
598 hostname,
599 AF_INET6,
600 request_id);
601 if ( (ret1 == GNUNET_OK) ||
602 (ret2 == GNUNET_OK) )
603 return GNUNET_OK;
604 if ( (ret1 == GNUNET_SYSERR) ||
605 (ret2 == GNUNET_SYSERR) )
606 return GNUNET_SYSERR;
607 return GNUNET_NO;
608 }
609 hp = gethostbyname2 (hostname,
610 af);
611 if (hp == NULL)
612 {
613 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
614 _("Could not find IP of host `%s': %s\n"),
615 hostname,
616 hstrerror (h_errno));
617 return GNUNET_SYSERR;
618 }
619 GNUNET_assert (hp->h_addrtype == af);
620 switch (af)
621 {
622 case AF_INET:
623 GNUNET_assert (hp->h_length == sizeof (struct in_addr));
624 env = GNUNET_MQ_msg_extra (msg,
625 hp->h_length,
626 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
627 msg->id = request_id;
628 GNUNET_memcpy (&msg[1],
629 hp->h_addr_list[0],
630 hp->h_length);
631 GNUNET_MQ_send (mq,
632 env);
633 break;
634 case AF_INET6:
635 GNUNET_assert (hp->h_length == sizeof (struct in6_addr));
636 env = GNUNET_MQ_msg_extra (msg,
637 hp->h_length,
638 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
639 msg->id = request_id;
640 GNUNET_memcpy (&msg[1],
641 hp->h_addr_list[0],
642 hp->h_length);
643 GNUNET_MQ_send (mq,
644 env);
645 break;
646 default:
647 GNUNET_break (0);
648 return GNUNET_SYSERR;
649 }
650 return GNUNET_OK;
651} 509}
652 510
653#elif HAVE_GETHOSTBYNAME
654
655 511
656static int 512static int
657gethostbyname_resolve (struct GNUNET_MQ_Handle *mq, 513remove_if_expired (struct ResolveCache *cache_entry)
658 const char *hostname,
659 uint32_t request_id)
660{ 514{
661 struct hostent *hp; 515 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
662 struct GNUNET_RESOLVER_ResponseMessage *msg;
663 struct GNUNET_MQ_Envelope *env;
664 516
665 hp = GETHOSTBYNAME (hostname); 517 if ( (NULL != cache_entry->records_head) &&
666 if (NULL == hp) 518 (now.abs_value_us > get_expiration_time (cache_entry)->abs_value_us) )
667 { 519 {
668 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 520 GNUNET_CONTAINER_DLL_remove (cache_head,
669 _("Could not find IP of host `%s': %s\n"), 521 cache_tail,
670 hostname, 522 cache_entry);
671 hstrerror (h_errno)); 523 free_cache_entry (cache_entry);
672 return GNUNET_SYSERR; 524 return GNUNET_YES;
673 }
674 if (hp->h_addrtype != AF_INET)
675 {
676 GNUNET_break (0);
677 return GNUNET_SYSERR;
678 } 525 }
679 GNUNET_assert (hp->h_length == sizeof (struct in_addr)); 526 return GNUNET_NO;
680 env = GNUNET_MQ_msg_extra (msg,
681 hp->h_length,
682 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
683 msg->id = request_id;
684 GNUNET_memcpy (&msg[1],
685 hp->h_addr_list[0],
686 hp->h_length);
687 GNUNET_MQ_send (mq,
688 env);
689 return GNUNET_OK;
690} 527}
691#endif
692 528
693 529
694/** 530/**
695 * Convert a string to an IP address. 531 * Get an IP address as a string (works for both IPv4 and IPv6). Note
532 * that the resolution happens asynchronously and that the first call
533 * may not immediately result in the FQN (but instead in a
534 * human-readable IP address).
696 * 535 *
697 * @param client where to send the IP address 536 * @param client handle to the client making the request (for sending the reply)
698 * @param hostname the hostname to resolve 537 * @param af AF_INET or AF_INET6
699 * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" 538 * @param ip `struct in_addr` or `struct in6_addr`
700 */ 539 */
701static void 540static int
702get_ip_from_hostname (struct GNUNET_SERVICE_Client *client, 541try_cache (const char *hostname,
703 const char *hostname, 542 uint16_t record_type,
704 int af, 543 uint16_t request_id,
705 uint32_t request_id) 544 struct GNUNET_SERVICE_Client *client)
706{ 545{
707 struct GNUNET_MQ_Envelope *env; 546 struct ResolveCache *pos;
708 struct GNUNET_RESOLVER_ResponseMessage *msg; 547 struct ResolveCache *next;
709 struct GNUNET_MQ_Handle *mq; 548
710 549 next = cache_head;
711 mq = GNUNET_SERVICE_client_get_mq (client); 550 while ( (NULL != (pos = next)) &&
712#if HAVE_GETADDRINFO_A 551 ( (NULL == pos->records_head) ||
713 getaddrinfo_a_resolve (mq, 552 (0 != strcmp (get_hostname (pos), hostname)) ||
714 hostname, 553 (*get_record_type (pos) != record_type) ) )
715 af, 554 {
716 request_id); 555 next = pos->next;
717 GNUNET_SERVICE_client_continue (client); 556 remove_if_expired (pos);
718 return; 557 }
719#elif HAVE_GETADDRINFO 558 if (NULL != pos)
720 getaddrinfo_resolve (mq, 559 {
721 hostname, 560 if (GNUNET_NO == remove_if_expired (pos))
722 af, 561 {
723 request_id); 562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724#elif HAVE_GETHOSTBYNAME2 563 "found cache entry for '%s', record type '%u'\n",
725 gethostbyname2_resolve (mq, 564 hostname,
726 hostname, 565 record_type);
727 af, 566 struct Record *cache_pos = pos->records_head;
728 request_id); 567 while (NULL != cache_pos)
729#elif HAVE_GETHOSTBYNAME 568 {
730 if ( ( (af == AF_UNSPEC) || 569 send_reply (cache_pos->record,
731 (af == PF_INET) ) ) 570 request_id,
732 gethostbyname_resolve (mq, 571 client);
733 hostname, 572 cache_pos = cache_pos->next;
734 request_id); 573 }
735#endif 574 send_end_msg (request_id,
736 // send end message 575 client);
737 env = GNUNET_MQ_msg (msg, 576 return GNUNET_YES;
738 GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); 577 }
739 msg->id = request_id; 578 }
740 GNUNET_MQ_notify_sent (env, 579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
741 &notify_service_client_done, 580 "no cache entry for '%s'\n",
742 client); 581 hostname);
743 GNUNET_MQ_send (mq, 582 return GNUNET_NO;
744 env);
745} 583}
746 584
747 585
@@ -801,6 +639,23 @@ check_get (void *cls,
801} 639}
802 640
803 641
642static void
643process_get (const char *hostname,
644 uint16_t record_type,
645 uint16_t request_id,
646 struct GNUNET_SERVICE_Client *client)
647{
648 if (GNUNET_NO == try_cache (hostname, record_type, request_id, client))
649 {
650 int result = resolve_and_cache (hostname,
651 record_type,
652 request_id,
653 client);
654 GNUNET_assert (GNUNET_OK == result);
655 }
656}
657
658
804/** 659/**
805 * Handle GET-message. 660 * Handle GET-message.
806 * 661 *
@@ -812,45 +667,100 @@ handle_get (void *cls,
812 const struct GNUNET_RESOLVER_GetMessage *msg) 667 const struct GNUNET_RESOLVER_GetMessage *msg)
813{ 668{
814 struct GNUNET_SERVICE_Client *client = cls; 669 struct GNUNET_SERVICE_Client *client = cls;
815 const void *ip;
816 int direction; 670 int direction;
817 int af; 671 int af;
818 uint32_t id; 672 uint16_t request_id;
673 const char *hostname;
819 674
820 direction = ntohl (msg->direction); 675 direction = ntohl (msg->direction);
821 af = ntohl (msg->af); 676 af = ntohl (msg->af);
822 id = ntohl (msg->id); 677 request_id = ntohs (msg->id);
823 if (GNUNET_NO == direction) 678 if (GNUNET_NO == direction)
824 { 679 {
825 /* IP from hostname */ 680 /* IP from hostname */
826 const char *hostname; 681 hostname = GNUNET_strdup ((const char *) &msg[1]);
827 682 switch (af)
828 hostname = (const char *) &msg[1]; 683 {
829 get_ip_from_hostname (client, 684 case AF_UNSPEC:
830 hostname, 685 {
831 af, 686 process_get (hostname, GNUNET_DNSPARSER_TYPE_ALL, request_id, client);
832 id); 687 break;
833 return; 688 }
689 case AF_INET:
690 {
691 process_get (hostname, GNUNET_DNSPARSER_TYPE_A, request_id, client);
692 break;
693 }
694 case AF_INET6:
695 {
696 process_get (hostname, GNUNET_DNSPARSER_TYPE_AAAA, request_id, client);
697 break;
698 }
699 default:
700 {
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
702 "got invalid af: %d\n",
703 af);
704 GNUNET_assert (0);
705 }
706 }
707 }
708 else
709 {
710 /* hostname from IP */
711 hostname = make_reverse_hostname (&msg[1], af);
712 process_get (hostname, GNUNET_DNSPARSER_TYPE_PTR, request_id, client);
834 } 713 }
835 ip = &msg[1]; 714 GNUNET_free_non_null ((char *)hostname);
715 GNUNET_SERVICE_client_continue (client);
716}
836 717
837#if !defined(GNUNET_CULL_LOGGING) 718
719static void
720shutdown_task (void *cls)
721{
722 (void) cls;
723 struct ResolveCache *pos;
724
725 while (NULL != (pos = cache_head))
838 { 726 {
839 char buf[INET6_ADDRSTRLEN]; 727 GNUNET_CONTAINER_DLL_remove (cache_head,
728 cache_tail,
729 pos);
730 free_cache_entry (pos);
731 }
732 GNUNET_DNSSTUB_stop (dnsstub_ctx);
733}
734
840 735
736static void
737init_cb (void *cls,
738 const struct GNUNET_CONFIGURATION_Handle *cfg,
739 struct GNUNET_SERVICE_Handle *sh)
740{
741 (void) cfg;
742 (void) sh;
743
744 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
745 cls);
746 dnsstub_ctx = GNUNET_DNSSTUB_start (128);
747 char **dns_servers;
748 ssize_t num_dns_servers = lookup_dns_servers (&dns_servers);
749 if (0 == num_dns_servers)
750 {
751 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
752 "no DNS server available. DNS resolution will not be possible.\n");
753 }
754 for (int i = 0; i != num_dns_servers; i++)
755 {
756 int result = GNUNET_DNSSTUB_add_dns_ip (dnsstub_ctx, dns_servers[i]);
841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
842 "Resolver asked to look up IP address `%s (request ID %u)'.\n", 758 "Adding DNS server '%s': %s\n",
843 inet_ntop (af, 759 dns_servers[i],
844 ip, 760 GNUNET_OK == result ? "success" : "failure");
845 buf, 761 GNUNET_free (dns_servers[i]);
846 sizeof (buf)),
847 id);
848 } 762 }
849#endif 763 GNUNET_free_non_null (dns_servers);
850 get_ip_as_string (client,
851 af,
852 ip,
853 id);
854} 764}
855 765
856 766
@@ -870,19 +780,6 @@ connect_cb (void *cls,
870 (void) cls; 780 (void) cls;
871 (void) mq; 781 (void) mq;
872 782
873#if HAVE_GETADDRINFO_A
874 resolve_result_pipe = GNUNET_DISK_pipe (GNUNET_NO,
875 GNUNET_NO,
876 GNUNET_NO,
877 GNUNET_NO);
878 GNUNET_assert (NULL != resolve_result_pipe);
879 resolve_result_pipe_task =
880 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
881 GNUNET_DISK_pipe_handle (resolve_result_pipe,
882 GNUNET_DISK_PIPE_END_READ),
883 &resolve_result_pipe_cb,
884 NULL);
885#endif
886 return c; 783 return c;
887} 784}
888 785
@@ -900,19 +797,16 @@ disconnect_cb (void *cls,
900 void *internal_cls) 797 void *internal_cls)
901{ 798{
902 (void) cls; 799 (void) cls;
800 struct ResolveCache *pos = cache_head;
903 801
904#if HAVE_GETADDRINFO_A 802 while (NULL != pos)
905 if (NULL != resolve_result_pipe_task)
906 {
907 GNUNET_SCHEDULER_cancel (resolve_result_pipe_task);
908 resolve_result_pipe_task = NULL;
909 }
910 if (NULL != resolve_result_pipe)
911 { 803 {
912 GNUNET_DISK_pipe_close (resolve_result_pipe); 804 if (pos->client == c)
913 resolve_result_pipe = NULL; 805 {
806 pos->client = NULL;
807 }
808 pos = pos->next;
914 } 809 }
915#endif
916 GNUNET_assert (c == internal_cls); 810 GNUNET_assert (c == internal_cls);
917} 811}
918 812
@@ -923,7 +817,7 @@ disconnect_cb (void *cls,
923GNUNET_SERVICE_MAIN 817GNUNET_SERVICE_MAIN
924("resolver", 818("resolver",
925 GNUNET_SERVICE_OPTION_NONE, 819 GNUNET_SERVICE_OPTION_NONE,
926 NULL, 820 &init_cb,
927 &connect_cb, 821 &connect_cb,
928 &disconnect_cb, 822 &disconnect_cb,
929 NULL, 823 NULL,
@@ -950,23 +844,4 @@ GNUNET_RESOLVER_memory_init ()
950#endif 844#endif
951 845
952 846
953/**
954 * Free globals on exit.
955 */
956void __attribute__ ((destructor))
957GNUNET_RESOLVER_memory_done ()
958{
959 struct IPCache *pos;
960
961 while (NULL != (pos = cache_head))
962 {
963 GNUNET_CONTAINER_DLL_remove (cache_head,
964 cache_tail,
965 pos);
966 GNUNET_free_non_null (pos->addr);
967 GNUNET_free (pos);
968 }
969}
970
971
972/* end of gnunet-service-resolver.c */ 847/* end of gnunet-service-resolver.c */
diff --git a/src/util/gnunet-timeout-w32.c b/src/util/gnunet-timeout-w32.c
new file mode 100644
index 000000000..78b268fe2
--- /dev/null
+++ b/src/util/gnunet-timeout-w32.c
@@ -0,0 +1,191 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17*/
18
19/**
20 * @file src/util/gnunet-timeout-w32.c
21 * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period
22 * @author LRN
23 */
24
25#include <windows.h>
26#include <sys/types.h>
27#include <stdio.h>
28
29int
30main (int argc, char *argv[])
31{
32 int i;
33 DWORD wait_result;
34 wchar_t *commandline;
35 wchar_t **wargv;
36 wchar_t *arg;
37 unsigned int cmdlen;
38 STARTUPINFOW start;
39 PROCESS_INFORMATION proc;
40
41 wchar_t wpath[MAX_PATH + 1];
42
43 wchar_t *pathbuf;
44 DWORD pathbuf_len, alloc_len;
45 wchar_t *ptr;
46 wchar_t *non_const_filename;
47 wchar_t *wcmd;
48 int wargc;
49 int timeout = 0;
50 ssize_t wrote;
51
52 HANDLE job;
53
54 if (argc < 3)
55 {
56 printf
57 ("arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
58 exit (1);
59 }
60
61 timeout = atoi (argv[1]);
62
63 if (timeout == 0)
64 timeout = 600;
65
66 commandline = GetCommandLineW ();
67 if (commandline == NULL)
68 {
69 printf ("Failed to get commandline: %lu\n", GetLastError ());
70 exit (2);
71 }
72
73 wargv = CommandLineToArgvW (commandline, &wargc);
74 if (wargv == NULL || wargc <= 1)
75 {
76 printf ("Failed to get parse commandline: %lu\n", GetLastError ());
77 exit (3);
78 }
79
80 job = CreateJobObject (NULL, NULL);
81 if (job == NULL)
82 {
83 printf ("Failed to create a job: %lu\n", GetLastError ());
84 exit (4);
85 }
86
87 pathbuf_len = GetEnvironmentVariableW (L"PATH", (wchar_t *) &pathbuf, 0);
88
89 alloc_len = pathbuf_len + 1;
90
91 pathbuf = malloc (alloc_len * sizeof (wchar_t));
92
93 ptr = pathbuf;
94
95 alloc_len = GetEnvironmentVariableW (L"PATH", ptr, pathbuf_len);
96
97 cmdlen = wcslen (wargv[2]);
98 if (cmdlen < 5 || wcscmp (&wargv[2][cmdlen - 4], L".exe") != 0)
99 {
100 non_const_filename = malloc (sizeof (wchar_t) * (cmdlen + 5));
101 swprintf (non_const_filename, cmdlen + 5, L"%S.exe", wargv[2]);
102 }
103 else
104 {
105 non_const_filename = wcsdup (wargv[2]);
106 }
107
108 /* Check that this is the full path. If it isn't, search. */
109 if (non_const_filename[1] == L':')
110 swprintf (wpath, sizeof (wpath) / sizeof (wchar_t), L"%S", non_const_filename);
111 else if (!SearchPathW
112 (pathbuf, non_const_filename, NULL, sizeof (wpath) / sizeof (wchar_t),
113 wpath, NULL))
114 {
115 printf ("Failed to get find executable: %lu\n", GetLastError ());
116 exit (5);
117 }
118 free (pathbuf);
119 free (non_const_filename);
120
121 cmdlen = wcslen (wpath) + 4;
122 i = 3;
123 while (NULL != (arg = wargv[i++]))
124 cmdlen += wcslen (arg) + 4;
125
126 wcmd = malloc (sizeof (wchar_t) * (cmdlen + 1));
127 wrote = 0;
128 i = 2;
129 while (NULL != (arg = wargv[i++]))
130 {
131 /* This is to escape trailing slash */
132 wchar_t arg_lastchar = arg[wcslen (arg) - 1];
133 if (wrote == 0)
134 {
135 wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"\"%S%S\" ", wpath,
136 arg_lastchar == L'\\' ? L"\\" : L"");
137 }
138 else
139 {
140 if (wcschr (arg, L' ') != NULL)
141 wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"\"%S%S\"%S", arg,
142 arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
143 else
144 wrote += swprintf (&wcmd[wrote], cmdlen + 1 - wrote, L"%S%S%S", arg,
145 arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
146 }
147 }
148
149 LocalFree (wargv);
150
151 memset (&start, 0, sizeof (start));
152 start.cb = sizeof (start);
153
154 if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, CREATE_SUSPENDED,
155 NULL, NULL, &start, &proc))
156 {
157 wprintf (L"Failed to get spawn process `%S' with arguments `%S': %lu\n", wpath, wcmd, GetLastError ());
158 exit (6);
159 }
160
161 AssignProcessToJobObject (job, proc.hProcess);
162
163 ResumeThread (proc.hThread);
164 CloseHandle (proc.hThread);
165
166 free (wcmd);
167
168 wait_result = WaitForSingleObject (proc.hProcess, timeout * 1000);
169 if (wait_result == WAIT_OBJECT_0)
170 {
171 DWORD status;
172 wait_result = GetExitCodeProcess (proc.hProcess, &status);
173 CloseHandle (proc.hProcess);
174 if (wait_result != 0)
175 {
176 printf ("Test process exited with result %lu\n", status);
177 TerminateJobObject (job, status);
178 exit (status);
179 }
180 printf ("Test process exited (failed to obtain exit status)\n");
181 TerminateJobObject (job, 0);
182 exit (0);
183 }
184 printf ("Child processes were killed after timeout of %u seconds\n",
185 timeout);
186 TerminateJobObject (job, 1);
187 CloseHandle (proc.hProcess);
188 exit (1);
189}
190
191/* end of timeout_watchdog_w32.c */
diff --git a/src/util/gnunet-timeout.c b/src/util/gnunet-timeout.c
new file mode 100644
index 000000000..8dfb6ad17
--- /dev/null
+++ b/src/util/gnunet-timeout.c
@@ -0,0 +1,128 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17*/
18
19/**
20 * @file src/util/gnunet-timeout.c
21 * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period
22 * @author Matthias Wachs
23 */
24
25#include <sys/types.h>
26#include <sys/wait.h>
27#include <signal.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <unistd.h>
31
32static pid_t child;
33
34
35static void
36sigchld_handler (int val)
37{
38 int status = 0;
39 int ret = 0;
40
41 (void) val;
42 waitpid (child,
43 &status,
44 0);
45 if (WIFEXITED (status) != 0)
46 {
47 ret = WEXITSTATUS (status);
48 fprintf (stderr,
49 "Process exited with result %u\n",
50 ret);
51 exit (ret); /* return same status code */
52 }
53 if (WIFSIGNALED (status) != 0)
54 {
55 ret = WTERMSIG (status);
56 fprintf (stderr,
57 "Process received signal %u\n",
58 ret);
59 kill (getpid (),
60 ret); /* kill self with the same signal */
61 }
62 exit (-1);
63}
64
65
66static void
67sigint_handler (int val)
68{
69 kill (0,
70 val);
71 exit (val);
72}
73
74
75int
76main (int argc,
77 char *argv[])
78{
79 int timeout = 0;
80 pid_t gpid = 0;
81
82 if (argc < 3)
83 {
84 fprintf (stderr,
85 "arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
86 exit (-1);
87 }
88
89 timeout = atoi (argv[1]);
90
91 if (timeout == 0)
92 timeout = 600;
93
94 /* with getpgid() it does not compile, but getpgrp is the BSD version and working */
95 gpid = getpgrp ();
96
97 signal (SIGCHLD, sigchld_handler);
98 signal (SIGABRT, sigint_handler);
99 signal (SIGFPE, sigint_handler);
100 signal (SIGILL, sigint_handler);
101 signal (SIGINT, sigint_handler);
102 signal (SIGSEGV, sigint_handler);
103 signal (SIGTERM, sigint_handler);
104
105 child = fork ();
106 if (child == 0)
107 {
108 /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */
109 //setpgrp (0, pid_t gpid);
110 if (-1 != gpid)
111 setpgid (0, gpid);
112 execvp (argv[2],
113 &argv[2]);
114 exit (-1);
115 }
116 if (child > 0)
117 {
118 sleep (timeout);
119 printf ("Child processes were killed after timeout of %u seconds\n",
120 timeout);
121 kill (0,
122 SIGTERM);
123 exit (3);
124 }
125 exit (-1);
126}
127
128/* end of timeout_watchdog.c */
diff --git a/src/util/resolver.h b/src/util/resolver.h
index a0f105afa..07851d052 100644
--- a/src/util/resolver.h
+++ b/src/util/resolver.h
@@ -60,7 +60,7 @@ struct GNUNET_RESOLVER_GetMessage
60 * identifies the request and is contained in the response message. The 60 * identifies the request and is contained in the response message. The
61 * client has to match response to request by this identifier. 61 * client has to match response to request by this identifier.
62 */ 62 */
63 uint32_t id GNUNET_PACKED; 63 uint16_t id GNUNET_PACKED;
64 64
65 /* followed by 0-terminated string for A/AAAA-lookup or 65 /* followed by 0-terminated string for A/AAAA-lookup or
66 by 'struct in_addr' / 'struct in6_addr' for reverse lookup */ 66 by 'struct in_addr' / 'struct in6_addr' for reverse lookup */
@@ -79,7 +79,7 @@ struct GNUNET_RESOLVER_ResponseMessage
79 * identifies the request this message responds to. The client 79 * identifies the request this message responds to. The client
80 * has to match response to request by this identifier. 80 * has to match response to request by this identifier.
81 */ 81 */
82 uint32_t id GNUNET_PACKED; 82 uint16_t id GNUNET_PACKED;
83 83
84 /* followed by 0-terminated string for response to a reverse lookup 84 /* followed by 0-terminated string for response to a reverse lookup
85 * or by 'struct in_addr' / 'struct in6_addr' for response to 85 * or by 'struct in_addr' / 'struct in6_addr' for response to
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index b94819f06..8a054327b 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -68,10 +68,10 @@ static struct GNUNET_RESOLVER_RequestHandle *req_head;
68 */ 68 */
69static struct GNUNET_RESOLVER_RequestHandle *req_tail; 69static struct GNUNET_RESOLVER_RequestHandle *req_tail;
70 70
71/** 71///**
72 * ID of the last request we sent to the service 72// * ID of the last request we sent to the service
73 */ 73// */
74static uint32_t last_request_id; 74//static uint16_t last_request_id;
75 75
76/** 76/**
77 * How long should we wait to reconnect? 77 * How long should we wait to reconnect?
@@ -445,7 +445,7 @@ process_requests ()
445 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); 445 GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
446 msg->direction = htonl (rh->direction); 446 msg->direction = htonl (rh->direction);
447 msg->af = htonl (rh->af); 447 msg->af = htonl (rh->af);
448 msg->id = htonl (rh->id); 448 msg->id = htons (rh->id);
449 GNUNET_memcpy (&msg[1], 449 GNUNET_memcpy (&msg[1],
450 &rh[1], 450 &rh[1],
451 rh->data_len); 451 rh->data_len);
@@ -491,7 +491,7 @@ handle_response (void *cls,
491 struct GNUNET_RESOLVER_RequestHandle *rh = req_head; 491 struct GNUNET_RESOLVER_RequestHandle *rh = req_head;
492 uint16_t size; 492 uint16_t size;
493 char *nret; 493 char *nret;
494 uint32_t request_id = msg->id; 494 uint16_t request_id = msg->id;
495 495
496 for (; rh != NULL; rh = rh->next) 496 for (; rh != NULL; rh = rh->next)
497 { 497 {
@@ -911,6 +911,14 @@ handle_lookup_timeout (void *cls)
911} 911}
912 912
913 913
914static uint16_t
915get_request_id ()
916{
917 return (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
918 UINT16_MAX);
919}
920
921
914/** 922/**
915 * Convert a string to one or more IP addresses. 923 * Convert a string to one or more IP addresses.
916 * 924 *
@@ -945,7 +953,8 @@ GNUNET_RESOLVER_ip_get (const char *hostname,
945 hostname); 953 hostname);
946 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); 954 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
947 rh->af = af; 955 rh->af = af;
948 rh->id = ++last_request_id; 956 //rh->id = ++last_request_id;
957 rh->id = get_request_id ();
949 rh->addr_callback = callback; 958 rh->addr_callback = callback;
950 rh->cls = callback_cls; 959 rh->cls = callback_cls;
951 GNUNET_memcpy (&rh[1], 960 GNUNET_memcpy (&rh[1],
@@ -1092,7 +1101,8 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
1092 rh->name_callback = callback; 1101 rh->name_callback = callback;
1093 rh->cls = cls; 1102 rh->cls = cls;
1094 rh->af = sa->sa_family; 1103 rh->af = sa->sa_family;
1095 rh->id = ++last_request_id; 1104 //rh->id = ++last_request_id;
1105 rh->id = get_request_id ();
1096 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1106 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1097 GNUNET_memcpy (&rh[1], 1107 GNUNET_memcpy (&rh[1],
1098 ip, 1108 ip,
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 93d133d1b..5d3836639 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -965,8 +965,6 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
965 965
966 /* scheduler must be running */ 966 /* scheduler must be running */
967 GNUNET_assert (NULL != scheduler_driver); 967 GNUNET_assert (NULL != scheduler_driver);
968 GNUNET_assert ( (NULL != active_task) ||
969 (GNUNET_NO == task->lifeness) );
970 is_fd_task = (NULL != task->fds); 968 is_fd_task = (NULL != task->fds);
971 if (is_fd_task) 969 if (is_fd_task)
972 { 970 {
@@ -1056,9 +1054,9 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
1056{ 1054{
1057 struct GNUNET_SCHEDULER_Task *t; 1055 struct GNUNET_SCHEDULER_Task *t;
1058 1056
1057 /* scheduler must be running */
1058 GNUNET_assert (NULL != scheduler_driver);
1059 GNUNET_assert (NULL != task); 1059 GNUNET_assert (NULL != task);
1060 GNUNET_assert ((NULL != active_task) ||
1061 (GNUNET_SCHEDULER_REASON_STARTUP == reason));
1062 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1060 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1063 t->read_fd = -1; 1061 t->read_fd = -1;
1064 t->write_fd = -1; 1062 t->write_fd = -1;
@@ -1099,7 +1097,8 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1099 struct GNUNET_SCHEDULER_Task *pos; 1097 struct GNUNET_SCHEDULER_Task *pos;
1100 struct GNUNET_SCHEDULER_Task *prev; 1098 struct GNUNET_SCHEDULER_Task *prev;
1101 1099
1102 GNUNET_assert (NULL != active_task); 1100 /* scheduler must be running */
1101 GNUNET_assert (NULL != scheduler_driver);
1103 GNUNET_assert (NULL != task); 1102 GNUNET_assert (NULL != task);
1104 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1103 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1105 t->callback = task; 1104 t->callback = task;
@@ -1286,7 +1285,8 @@ GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
1286{ 1285{
1287 struct GNUNET_SCHEDULER_Task *t; 1286 struct GNUNET_SCHEDULER_Task *t;
1288 1287
1289 GNUNET_assert (NULL != active_task); 1288 /* scheduler must be running */
1289 GNUNET_assert (NULL != scheduler_driver);
1290 GNUNET_assert (NULL != task); 1290 GNUNET_assert (NULL != task);
1291 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1291 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1292 t->callback = task; 1292 t->callback = task;
@@ -1403,7 +1403,8 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1403{ 1403{
1404 struct GNUNET_SCHEDULER_Task *t; 1404 struct GNUNET_SCHEDULER_Task *t;
1405 1405
1406 GNUNET_assert (NULL != active_task); 1406 /* scheduler must be running */
1407 GNUNET_assert (NULL != scheduler_driver);
1407 GNUNET_assert (NULL != task); 1408 GNUNET_assert (NULL != task);
1408 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1409 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1409 init_fd_info (t, 1410 init_fd_info (t,
@@ -1832,7 +1833,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1832 1833
1833 /* scheduler must be running */ 1834 /* scheduler must be running */
1834 GNUNET_assert (NULL != scheduler_driver); 1835 GNUNET_assert (NULL != scheduler_driver);
1835 GNUNET_assert (NULL != active_task);
1836 GNUNET_assert (NULL != task); 1836 GNUNET_assert (NULL != task);
1837 int no_rs = (NULL == rs); 1837 int no_rs = (NULL == rs);
1838 int no_ws = (NULL == ws); 1838 int no_ws = (NULL == ws);
@@ -2022,99 +2022,109 @@ GNUNET_SCHEDULER_do_work (struct GNUNET_SCHEDULER_Handle *sh)
2022 if (timeout.abs_value_us > now.abs_value_us) 2022 if (timeout.abs_value_us > now.abs_value_us)
2023 { 2023 {
2024 /** 2024 /**
2025 * The driver called this function before the current timeout was 2025 * The event loop called this function before the current timeout was
2026 * reached (and no FD tasks are ready). This can happen in the 2026 * reached (and no FD tasks are ready). This is acceptable if
2027 * rare case when the system time is changed while the driver is 2027 *
2028 * waiting for the timeout, so we handle this gracefully. It might 2028 * - the system time was changed while the driver was waiting for
2029 * also be a programming error in the driver though. 2029 * the timeout
2030 * - an external event loop called GNUnet API functions outside of
2031 * the callbacks called in GNUNET_SCHEDULER_do_work and thus
2032 * wasn't notified about the new timeout
2033 *
2034 * It might also mean we are busy-waiting because of a programming
2035 * error in the external event loop.
2030 */ 2036 */
2031 LOG (GNUNET_ERROR_TYPE_DEBUG, 2037 LOG (GNUNET_ERROR_TYPE_DEBUG,
2032 "GNUNET_SCHEDULER_do_work did not find any ready " 2038 "GNUNET_SCHEDULER_do_work did not find any ready "
2033 "tasks and timeout has not been reached yet.\n"); 2039 "tasks and timeout has not been reached yet.\n");
2034 return GNUNET_NO;
2035 } 2040 }
2036 /** 2041 else
2037 * the current timeout was reached but no ready tasks were found, 2042 {
2038 * internal scheduler error! 2043 /**
2039 */ 2044 * the current timeout was reached but no ready tasks were found,
2040 GNUNET_assert (0); 2045 * internal scheduler error!
2041 } 2046 */
2042 2047 GNUNET_assert (0);
2043 /* find out which task priority level we are going to 2048 }
2044 process this time */
2045 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
2046 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]);
2047 /* yes, p>0 is correct, 0 is "KEEP" which should
2048 * always be an empty queue (see assertion)! */
2049 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
2050 {
2051 pos = ready_head[p];
2052 if (NULL != pos)
2053 break;
2054 } 2049 }
2055 GNUNET_assert (NULL != pos); /* ready_count wrong? */ 2050 else
2056
2057 /* process all tasks at this priority level, then yield */
2058 while (NULL != (pos = ready_head[p]))
2059 { 2051 {
2060 GNUNET_CONTAINER_DLL_remove (ready_head[p], 2052 /* find out which task priority level we are going to
2061 ready_tail[p], 2053 process this time */
2062 pos); 2054 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
2063 ready_count--; 2055 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]);
2064 current_priority = pos->priority; 2056 /* yes, p>0 is correct, 0 is "KEEP" which should
2065 current_lifeness = pos->lifeness; 2057 * always be an empty queue (see assertion)! */
2066 active_task = pos; 2058 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
2067#if PROFILE_DELAYS
2068 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us >
2069 DELAY_THRESHOLD.rel_value_us)
2070 { 2059 {
2071 LOG (GNUNET_ERROR_TYPE_DEBUG, 2060 pos = ready_head[p];
2072 "Task %p took %s to be scheduled\n", 2061 if (NULL != pos)
2073 pos, 2062 break;
2074 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time),
2075 GNUNET_YES));
2076 } 2063 }
2077#endif 2064 GNUNET_assert (NULL != pos); /* ready_count wrong? */
2078 tc.reason = pos->reason; 2065
2079 GNUNET_NETWORK_fdset_zero (sh->rs); 2066 /* process all tasks at this priority level, then yield */
2080 GNUNET_NETWORK_fdset_zero (sh->ws); 2067 while (NULL != (pos = ready_head[p]))
2081 // FIXME: do we have to remove FdInfos from fds if they are not ready?
2082 tc.fds_len = pos->fds_len;
2083 tc.fds = pos->fds;
2084 for (unsigned int i = 0; i != pos->fds_len; ++i)
2085 { 2068 {
2086 struct GNUNET_SCHEDULER_FdInfo *fdi = &pos->fds[i]; 2069 GNUNET_CONTAINER_DLL_remove (ready_head[p],
2087 if (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et)) 2070 ready_tail[p],
2071 pos);
2072 ready_count--;
2073 current_priority = pos->priority;
2074 current_lifeness = pos->lifeness;
2075 active_task = pos;
2076#if PROFILE_DELAYS
2077 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us >
2078 DELAY_THRESHOLD.rel_value_us)
2088 { 2079 {
2089 GNUNET_NETWORK_fdset_set_native (sh->rs, 2080 LOG (GNUNET_ERROR_TYPE_DEBUG,
2090 fdi->sock); 2081 "Task %p took %s to be scheduled\n",
2082 pos,
2083 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time),
2084 GNUNET_YES));
2091 } 2085 }
2092 if (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et)) 2086#endif
2087 tc.reason = pos->reason;
2088 GNUNET_NETWORK_fdset_zero (sh->rs);
2089 GNUNET_NETWORK_fdset_zero (sh->ws);
2090 // FIXME: do we have to remove FdInfos from fds if they are not ready?
2091 tc.fds_len = pos->fds_len;
2092 tc.fds = pos->fds;
2093 for (unsigned int i = 0; i != pos->fds_len; ++i)
2093 { 2094 {
2094 GNUNET_NETWORK_fdset_set_native (sh->ws, 2095 struct GNUNET_SCHEDULER_FdInfo *fdi = &pos->fds[i];
2095 fdi->sock); 2096 if (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et))
2097 {
2098 GNUNET_NETWORK_fdset_set_native (sh->rs,
2099 fdi->sock);
2100 }
2101 if (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et))
2102 {
2103 GNUNET_NETWORK_fdset_set_native (sh->ws,
2104 fdi->sock);
2105 }
2096 } 2106 }
2097 } 2107 tc.read_ready = sh->rs;
2098 tc.read_ready = sh->rs; 2108 tc.write_ready = sh->ws;
2099 tc.write_ready = sh->ws; 2109 LOG (GNUNET_ERROR_TYPE_DEBUG,
2100 LOG (GNUNET_ERROR_TYPE_DEBUG, 2110 "Running task %p\n",
2101 "Running task %p\n", 2111 pos);
2102 pos); 2112 GNUNET_assert (NULL != pos->callback);
2103 GNUNET_assert (NULL != pos->callback); 2113 pos->callback (pos->callback_cls);
2104 pos->callback (pos->callback_cls); 2114 if (NULL != pos->fds)
2105 if (NULL != pos->fds)
2106 {
2107 int del_result = scheduler_driver->del (scheduler_driver->cls, pos);
2108 if (GNUNET_OK != del_result)
2109 { 2115 {
2110 LOG (GNUNET_ERROR_TYPE_ERROR, 2116 int del_result = scheduler_driver->del (scheduler_driver->cls, pos);
2111 "driver could not delete task %p\n", pos); 2117 if (GNUNET_OK != del_result)
2112 GNUNET_assert (0); 2118 {
2119 LOG (GNUNET_ERROR_TYPE_ERROR,
2120 "driver could not delete task %p\n", pos);
2121 GNUNET_assert (0);
2122 }
2113 } 2123 }
2124 active_task = NULL;
2125 dump_backtrace (pos);
2126 destroy_task (pos);
2114 } 2127 }
2115 active_task = NULL;
2116 dump_backtrace (pos);
2117 destroy_task (pos);
2118 } 2128 }
2119 shutdown_if_no_lifeness (); 2129 shutdown_if_no_lifeness ();
2120 if (0 == ready_count) 2130 if (0 == ready_count)
@@ -2164,12 +2174,12 @@ struct GNUNET_SCHEDULER_Handle *
2164GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver) 2174GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver)
2165{ 2175{
2166 struct GNUNET_SCHEDULER_Handle *sh; 2176 struct GNUNET_SCHEDULER_Handle *sh;
2167 struct GNUNET_SCHEDULER_Task tsk;
2168 const struct GNUNET_DISK_FileHandle *pr; 2177 const struct GNUNET_DISK_FileHandle *pr;
2169 2178
2170 /* general set-up */ 2179 /* scheduler must not be running */
2171 GNUNET_assert (NULL == active_task); 2180 GNUNET_assert (NULL == scheduler_driver);
2172 GNUNET_assert (NULL == shutdown_pipe_handle); 2181 GNUNET_assert (NULL == shutdown_pipe_handle);
2182 /* general set-up */
2173 sh = GNUNET_new (struct GNUNET_SCHEDULER_Handle); 2183 sh = GNUNET_new (struct GNUNET_SCHEDULER_Handle);
2174 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, 2184 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO,
2175 GNUNET_NO, 2185 GNUNET_NO,
@@ -2204,10 +2214,6 @@ GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver)
2204 /* Setup initial tasks */ 2214 /* Setup initial tasks */
2205 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 2215 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
2206 current_lifeness = GNUNET_NO; 2216 current_lifeness = GNUNET_NO;
2207 memset (&tsk,
2208 0,
2209 sizeof (tsk));
2210 active_task = &tsk;
2211 install_parent_control_task = 2217 install_parent_control_task =
2212 GNUNET_SCHEDULER_add_now (&install_parent_control_handler, 2218 GNUNET_SCHEDULER_add_now (&install_parent_control_handler,
2213 NULL); 2219 NULL);
@@ -2217,7 +2223,6 @@ GNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver)
2217 &shutdown_pipe_cb, 2223 &shutdown_pipe_cb,
2218 NULL); 2224 NULL);
2219 current_lifeness = GNUNET_YES; 2225 current_lifeness = GNUNET_YES;
2220 active_task = NULL;
2221 scheduler_driver->set_wakeup (scheduler_driver->cls, 2226 scheduler_driver->set_wakeup (scheduler_driver->cls,
2222 get_timeout ()); 2227 get_timeout ());
2223 /* begin main event loop */ 2228 /* begin main event loop */
diff --git a/src/util/strings.c b/src/util/strings.c
index 5ed195933..ea3c8cfb9 100644
--- a/src/util/strings.c
+++ b/src/util/strings.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*/
@@ -1947,27 +1947,27 @@ static char *cvt =
1947/** 1947/**
1948 * Encode into Base64. 1948 * Encode into Base64.
1949 * 1949 *
1950 * @param data the data to encode 1950 * @param in the data to encode
1951 * @param len the length of the input 1951 * @param len the length of the input
1952 * @param output where to write the output (*output should be NULL, 1952 * @param output where to write the output (*output should be NULL,
1953 * is allocated) 1953 * is allocated)
1954 * @return the size of the output 1954 * @return the size of the output
1955 */ 1955 */
1956size_t 1956size_t
1957GNUNET_STRINGS_base64_encode (const char *data, 1957GNUNET_STRINGS_base64_encode (const void *in,
1958 size_t len, 1958 size_t len,
1959 char **output) 1959 char **output)
1960{ 1960{
1961 size_t i; 1961 const char *data = in;
1962 char c;
1963 size_t ret; 1962 size_t ret;
1964 char *opt; 1963 char *opt;
1965 1964
1966 ret = 0; 1965 ret = 0;
1967 opt = GNUNET_malloc (2 + (len * 4 / 3) + 8); 1966 opt = GNUNET_malloc (2 + (len * 4 / 3) + 8);
1968 *output = opt; 1967 for (size_t i = 0; i < len; ++i)
1969 for (i = 0; i < len; ++i)
1970 { 1968 {
1969 char c;
1970
1971 c = (data[i] >> 2) & 0x3f; 1971 c = (data[i] >> 2) & 0x3f;
1972 opt[ret++] = cvt[(int) c]; 1972 opt[ret++] = cvt[(int) c];
1973 c = (data[i] << 4) & 0x3f; 1973 c = (data[i] << 4) & 0x3f;
@@ -1997,6 +1997,7 @@ GNUNET_STRINGS_base64_encode (const char *data,
1997 } 1997 }
1998 } 1998 }
1999 opt[ret++] = FILLCHAR; 1999 opt[ret++] = FILLCHAR;
2000 *output = opt;
2000 return ret; 2001 return ret;
2001} 2002}
2002 2003
@@ -2018,11 +2019,10 @@ GNUNET_STRINGS_base64_encode (const char *data,
2018 */ 2019 */
2019size_t 2020size_t
2020GNUNET_STRINGS_base64_decode (const char *data, 2021GNUNET_STRINGS_base64_decode (const char *data,
2021 size_t len, char **output) 2022 size_t len,
2023 void **out)
2022{ 2024{
2023 size_t i; 2025 char *output;
2024 char c;
2025 char c1;
2026 size_t ret = 0; 2026 size_t ret = 0;
2027 2027
2028#define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\ 2028#define CHECK_CRLF while (data[i] == '\r' || data[i] == '\n') {\
@@ -2031,12 +2031,15 @@ GNUNET_STRINGS_base64_decode (const char *data,
2031 if (i >= len) goto END; \ 2031 if (i >= len) goto END; \
2032 } 2032 }
2033 2033
2034 *output = GNUNET_malloc ((len * 3 / 4) + 8); 2034 output = GNUNET_malloc ((len * 3 / 4) + 8);
2035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2036 "base64_decode decoding len=%d\n", 2036 "base64_decode decoding len=%d\n",
2037 (int) len); 2037 (int) len);
2038 for (i = 0; i < len; ++i) 2038 for (size_t i = 0; i < len; ++i)
2039 { 2039 {
2040 char c;
2041 char c1;
2042
2040 CHECK_CRLF; 2043 CHECK_CRLF;
2041 if (FILLCHAR == data[i]) 2044 if (FILLCHAR == data[i])
2042 break; 2045 break;
@@ -2045,7 +2048,7 @@ GNUNET_STRINGS_base64_decode (const char *data,
2045 CHECK_CRLF; 2048 CHECK_CRLF;
2046 c1 = (char) cvtfind (data[i]); 2049 c1 = (char) cvtfind (data[i]);
2047 c = (c << 2) | ((c1 >> 4) & 0x3); 2050 c = (c << 2) | ((c1 >> 4) & 0x3);
2048 (*output)[ret++] = c; 2051 output[ret++] = c;
2049 if (++i < len) 2052 if (++i < len)
2050 { 2053 {
2051 CHECK_CRLF; 2054 CHECK_CRLF;
@@ -2054,7 +2057,7 @@ GNUNET_STRINGS_base64_decode (const char *data,
2054 break; 2057 break;
2055 c = (char) cvtfind (c); 2058 c = (char) cvtfind (c);
2056 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf); 2059 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
2057 (*output)[ret++] = c1; 2060 output[ret++] = c1;
2058 } 2061 }
2059 if (++i < len) 2062 if (++i < len)
2060 { 2063 {
@@ -2065,15 +2068,13 @@ GNUNET_STRINGS_base64_decode (const char *data,
2065 2068
2066 c1 = (char) cvtfind (c1); 2069 c1 = (char) cvtfind (c1);
2067 c = ((c << 6) & 0xc0) | c1; 2070 c = ((c << 6) & 0xc0) | c1;
2068 (*output)[ret++] = c; 2071 output[ret++] = c;
2069 } 2072 }
2070 } 2073 }
2071END: 2074END:
2075 *out = output;
2072 return ret; 2076 return ret;
2073} 2077}
2074 2078
2075 2079
2076
2077
2078
2079/* end of strings.c */ 2080/* end of strings.c */