1d67c568c9052e005a299512153364cf957999bc
[oweals/gnunet.git] / src / include / gnunet_identity_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /** 
22  * @file include/gnunet_identity_service.h
23  * @brief Identity service; implements identity management for GNUnet
24  * @author Christian Grothoff
25  *
26  * Identities in GNUnet are ECDSA keys.  You assume an identity by
27  * using (signing with) a particular private key.  As GNUnet users are
28  * expected to have many egos, we need an identity service to
29  * allow users to manage their egos.  The identity service
30  * manages the egos (private keys) of the local user; it does
31  * NOT manage identities of other users (public keys).  For giving
32  * names to other users and manage their public keys securely, we
33  * use GADS/GNS.
34  */
35 #ifndef GNUNET_IDENTITY_SERVICE_H
36 #define GNUNET_IDENTITY_SERVICE_H
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0                           /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45
46 #include "gnunet_util_lib.h"
47
48
49 /** 
50  * Version number of GNUnet Identity API.
51  */
52 #define GNUNET_IDENTITY_VERSION 0x00000000
53
54 /** 
55  * Handle to access the identity service.
56  */
57 struct GNUNET_IDENTITY_Handle;
58
59 /** 
60  * Handle for a ego.
61  */
62 struct GNUNET_IDENTITY_Ego;
63
64 /** 
65  * Handle for an operation with the identity service.
66  */
67 struct GNUNET_IDENTITY_Operation;
68
69
70 /**
71  * Obtain the ECC key associated with a ego.
72  *
73  * @param ego the ego
74  * @return associated ECC key, valid as long as the ego is valid
75  */
76 const struct GNUNET_CRYPTO_EccPrivateKey *
77 GNUNET_IDENTITY_ego_get_key (struct GNUNET_IDENTITY_Ego *ego);
78
79
80 /** 
81  * Method called to inform about the egos of
82  * this peer. 
83  *
84  * When used with 'GNUNET_IDENTITY_connect', this function is
85  * initially called for all egos and then again whenever a
86  * ego's identifier changes or if it is deleted.  At the end of
87  * the initial pass over all egos, the function is once called
88  * with 'NULL' for 'ego'. That does NOT mean that the callback won't
89  * be invoked in the future or that there was an error.
90  *
91  * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
92  * this function is only called ONCE, and 'NULL' being passed in
93  * 'ego' does indicate an error (i.e. name is taken or no default
94  * value is known).  If 'ego' is non-NULL and if '*ctx'
95  * is set in those callbacks, the value WILL be passed to a subsequent
96  * call to the identity callback of 'GNUNET_IDENTITY_connect' (if 
97  * that one was not NULL).
98  *
99  * When an identity is renamed, this function is called with the
100  * (known) ego but the NEW identifier.  
101  *
102  * When an identity is deleted, this function is called with the
103  * (known) ego and "NULL" for the 'identifier'.  In this case,
104  * the 'ego' is henceforth invalid (and the 'ctx' should also be
105  * cleaned up).
106  *
107  * @param cls closure
108  * @param ego ego handle
109  * @param ego_ctx context for application to store data for this ego
110  *                 (during the lifetime of this process, initially NULL)
111  * @param identifier identifier assigned by the user for this ego,
112  *                   NULL if the user just deleted the ego and it
113  *                   must thus no longer be used
114  */
115 typedef void (*GNUNET_IDENTITY_Callback)(void *cls,
116                                          struct GNUNET_IDENTITY_Ego *ego,
117                                          void **ctx,
118                                          const char *identifier);
119
120
121 /** 
122  * Connect to the identity service.
123  *
124  * @param cfg Configuration to contact the identity service.
125  * @param cb function to call on all identity events, can be NULL
126  * @param cb_cls closure for 'cb'
127  * @return handle to communicate with identity service
128  */
129 struct GNUNET_IDENTITY_Handle *
130 GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
131                          GNUNET_IDENTITY_Callback cb,
132                          void *cb_cls);
133
134
135 /**
136  * Obtain the identity that is currently preferred/default
137  * for a service.
138  *
139  * @param id identity service to query
140  * @param service_name for which service is an identity wanted
141  * @param cb function to call with the result (will only be called once)
142  * @param cb_cls closure for cb
143  * @return handle to abort the operation
144  */
145 struct GNUNET_IDENTITY_Operation *
146 GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *id,
147                      const char *service_name,
148                      GNUNET_IDENTITY_Callback cb,
149                      void *cb_cls);
150
151
152 /**
153  * Function called once the requested operation has
154  * been completed.
155  *
156  * @param cls closure
157  * @param emsg NULL on success, otherwise an error message
158  */
159 typedef void (*GNUNET_IDENTITY_Continuation)(void *cls,
160                                              const char *emsg);
161
162
163 /**
164  * Set the preferred/default identity for a service.
165  *
166  * @param id identity service to inform
167  * @param service_name for which service is an identity set
168  * @param ego new default identity to be set for this service
169  * @param cont function to call once the operation finished
170  * @param cont_cls closure for cont
171  * @return handle to abort the operation
172  */
173 struct GNUNET_IDENTITY_Operation *
174 GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
175                      const char *service_name,
176                      struct GNUNET_IDENTITY_Ego *ego,
177                      GNUNET_IDENTITY_Continuation cont,
178                      void *cont_cls);
179
180
181 /**
182  * Disconnect from identity service.
183  *
184  * @param h identity service to disconnect
185  */ 
186 void
187 GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h);
188
189
190 /** 
191  * Create a new identity with the given identifier.
192  *
193  * @param id identity service to use
194  * @param identifier desired identifier
195  * @param cont function to call with the result (will only be called once)
196  * @param cont_cls closure for cont
197  * @return handle to abort the operation
198  */
199 struct GNUNET_IDENTITY_Operation *
200 GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
201                         const char *identifier,
202                         GNUNET_IDENTITY_Continuation cont,
203                         void *cont_cls);
204
205
206 /** 
207  * Renames an existing identity.
208  *
209  * @param id identity service to use
210  * @param old_identifier old identifier
211  * @param new_identifier desired new identifier
212  * @param cb function to call with the result (will only be called once)
213  * @param cb_cls closure for cb
214  * @return handle to abort the operation
215  */
216 struct GNUNET_IDENTITY_Operation *
217 GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *id,
218                         const char *old_identifier,
219                         const char *new_identifier,
220                         GNUNET_IDENTITY_Continuation cb,
221                         void *cb_cls);
222
223
224 /** 
225  * Delete an existing identity.
226  *
227  * @param id identity service to use
228  * @param identifier identifier of the identity to delete
229  * @param cb function to call with the result (will only be called once)
230  * @param cb_cls closure for cb
231  * @return handle to abort the operation
232  */
233 struct GNUNET_IDENTITY_Operation *
234 GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id,
235                         const char *identifier,
236                         GNUNET_IDENTITY_Continuation cb,
237                         void *cb_cls);
238
239
240 /**
241  * Cancel an identity operation.  Note that the operation MAY still
242  * be executed; this merely cancels the continuation; if the request
243  * was already transmitted, the service may still choose to complete
244  * the operation.
245  *
246  * @param op operation to cancel
247  */
248 void
249 GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op);
250
251
252 #if 0                           /* keep Emacsens' auto-indent happy */
253 {
254 #endif
255 #ifdef __cplusplus
256 }
257 #endif
258
259 /* ifndef GNUNET_IDENTITY_SERVICE_H */
260 #endif
261 /* end of gnunet_identity_service.h */