aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-15 21:10:01 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-15 21:10:01 +0000
commit2939ad56c07b0077a511fa8e6b8ce4937d891a03 (patch)
tree449b736def90616aff1abc71664dfc5714b69a6a /src
parent67c9e0fb6ec5b7c0b5053fba41ac69114d01c213 (diff)
downloadgnunet-2939ad56c07b0077a511fa8e6b8ce4937d891a03.tar.gz
gnunet-2939ad56c07b0077a511fa8e6b8ce4937d891a03.zip
-code to generate some of the responses
Diffstat (limited to 'src')
-rw-r--r--src/identity/gnunet-service-identity.c76
1 files changed, 72 insertions, 4 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index daf50d450..9be5e0698 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -143,6 +143,66 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
143 143
144 144
145/** 145/**
146 * Send a result code back to the client.
147 *
148 * @param client client that should receive the result code
149 * @param result_code code to transmit
150 * @param emsg error message to include (or NULL for none)
151 */
152static void
153send_result_code (struct GNUNET_SERVER_Client *client,
154 uint32_t result_code,
155 const char *emsg)
156{
157 struct GNUNET_IDENTITY_ResultCodeMessage *rcm;
158 size_t elen;
159
160 if (NULL == emsg)
161 elen = 0;
162 else
163 elen = strlen (emsg) + 1;
164 rcm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) + elen);
165 rcm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
166 rcm->header.size = htons (sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) + elen);
167 rcm->result_code = htonl (result_code);
168 memcpy (&rcm[1], emsg, elen);
169 GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header, GNUNET_YES);
170 GNUNET_free (rcm);
171}
172
173
174/**
175 * Create an update message with information about the current state of an ego.
176 *
177 * @param ego ego to create message for
178 * @return corresponding update message
179 */
180static struct GNUNET_IDENTITY_UpdateMessage *
181create_update_message (struct Ego *ego)
182{
183 struct GNUNET_IDENTITY_UpdateMessage *um;
184 char *str;
185 uint16_t pk_len;
186 size_t name_len;
187 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
188
189 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
190 enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
191 pk_len = ntohs (enc->size);
192 um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
193 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
194 um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + pk_len + name_len);
195 um->name_len = htons (name_len);
196 um->pk_len = htons (pk_len);
197 str = (char *) &um[1];
198 memcpy (str, enc, pk_len);
199 memcpy (&str[pk_len], ego->identifier, name_len);
200 GNUNET_free (enc);
201 return um;
202}
203
204
205/**
146 * Handler for START message from client, sends information 206 * Handler for START message from client, sends information
147 * about all identities to the client immediately and 207 * about all identities to the client immediately and
148 * adds the client to the notification context for future 208 * adds the client to the notification context for future
@@ -156,12 +216,18 @@ static void
156handle_start_message (void *cls, struct GNUNET_SERVER_Client *client, 216handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
157 const struct GNUNET_MessageHeader *message) 217 const struct GNUNET_MessageHeader *message)
158{ 218{
219 struct GNUNET_IDENTITY_UpdateMessage *um;
220 struct Ego *ego;
221
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 "Received START message from client\n"); 223 "Received START message from client\n");
161 GNUNET_SERVER_notification_context_add (nc, client); 224 GNUNET_SERVER_notification_context_add (nc, client);
162 GNUNET_break (0); // not implemented! 225 for (ego = ego_head; NULL != ego; ego = ego->next)
163 // setup_estimate_message (&em); 226 {
164 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); 227 um = create_update_message (ego);
228 GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_YES);
229 GNUNET_free (um);
230 }
165 GNUNET_SERVER_receive_done (client, GNUNET_OK); 231 GNUNET_SERVER_receive_done (client, GNUNET_OK);
166} 232}
167 233
@@ -268,7 +334,9 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
268 // setup_estimate_message (&em); 334 // setup_estimate_message (&em);
269 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); 335 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES);
270 GNUNET_break (0); // not implemented! 336 GNUNET_break (0); // not implemented!
271 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 337
338 send_result_code (client, 1, gettext_noop ("no matching ego found"));
339 GNUNET_SERVER_receive_done (client, GNUNET_OK);
272} 340}
273 341
274 342