diff options
author | Gabor X Toth <*@tg-x.net> | 2013-08-27 07:29:59 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-08-27 07:29:59 +0000 |
commit | 0f87ae3787762ea32fb3d9580d13782cb2aacdd2 (patch) | |
tree | d56c234e6e33be730ca02bb79da65caae28efd23 /src/psycstore/gnunet-service-psycstore.c | |
parent | dff71f18889ee5ca515ab096c8f925858968f1fc (diff) | |
download | gnunet-0f87ae3787762ea32fb3d9580d13782cb2aacdd2.tar.gz gnunet-0f87ae3787762ea32fb3d9580d13782cb2aacdd2.zip |
psycstore service skeleton
Diffstat (limited to 'src/psycstore/gnunet-service-psycstore.c')
-rw-r--r-- | src/psycstore/gnunet-service-psycstore.c | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c new file mode 100644 index 000000000..977f77e06 --- /dev/null +++ b/src/psycstore/gnunet-service-psycstore.c | |||
@@ -0,0 +1,169 @@ | |||
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 psycstore/gnunet-service-psycstore.c | ||
23 | * @brief PSYCstore service | ||
24 | * @author Gabor X Toth | ||
25 | * @author Christian Grothoff | ||
26 | * | ||
27 | * The purpose of this service is to manage private keys that | ||
28 | * represent the various egos/pseudonyms/identities of a GNUnet user. | ||
29 | * | ||
30 | */ | ||
31 | #include "platform.h" | ||
32 | #include "gnunet_util_lib.h" | ||
33 | #include "gnunet_constants.h" | ||
34 | #include "gnunet_protocols.h" | ||
35 | #include "gnunet_statistics_service.h" | ||
36 | #include "gnunet_psycstore_service.h" | ||
37 | #include "psycstore.h" | ||
38 | |||
39 | |||
40 | /** | ||
41 | * Handle to our current configuration. | ||
42 | */ | ||
43 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | /** | ||
46 | * Handle to the statistics service. | ||
47 | */ | ||
48 | static struct GNUNET_STATISTICS_Handle *stats; | ||
49 | |||
50 | /** | ||
51 | * Notification context, simplifies client broadcasts. | ||
52 | */ | ||
53 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
54 | |||
55 | /** | ||
56 | * Database file. | ||
57 | */ | ||
58 | static char *db_file; | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Task run during shutdown. | ||
63 | * | ||
64 | * @param cls unused | ||
65 | * @param tc unused | ||
66 | */ | ||
67 | static void | ||
68 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
69 | { | ||
70 | if (NULL != nc) | ||
71 | { | ||
72 | GNUNET_SERVER_notification_context_destroy (nc); | ||
73 | nc = NULL; | ||
74 | } | ||
75 | if (NULL != stats) | ||
76 | { | ||
77 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
78 | stats = NULL; | ||
79 | } | ||
80 | GNUNET_free (db_file); | ||
81 | db_file = NULL; | ||
82 | } | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Send a result code back to the client. | ||
87 | * | ||
88 | * @param client client that should receive the result code | ||
89 | * @param result_code code to transmit | ||
90 | * @param emsg error message to include (or NULL for none) | ||
91 | */ | ||
92 | static void | ||
93 | send_result_code (struct GNUNET_SERVER_Client *client, | ||
94 | uint32_t result_code, | ||
95 | const char *emsg) | ||
96 | { | ||
97 | struct GNUNET_PSYCSTORE_ResultCodeMessage *rcm; | ||
98 | size_t elen; | ||
99 | |||
100 | if (NULL == emsg) | ||
101 | elen = 0; | ||
102 | else | ||
103 | elen = strlen (emsg) + 1; | ||
104 | rcm = GNUNET_malloc (sizeof (struct GNUNET_PSYCSTORE_ResultCodeMessage) + elen); | ||
105 | rcm->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE); | ||
106 | rcm->header.size = htons (sizeof (struct GNUNET_PSYCSTORE_ResultCodeMessage) + elen); | ||
107 | rcm->result_code = htonl (result_code); | ||
108 | memcpy (&rcm[1], emsg, elen); | ||
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
110 | "Sending result %d (%s) to client\n", | ||
111 | (int) result_code, | ||
112 | emsg); | ||
113 | GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header, GNUNET_NO); | ||
114 | GNUNET_free (rcm); | ||
115 | } | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Handle PSYCstore clients. | ||
120 | * | ||
121 | * @param cls closure | ||
122 | * @param server the initialized server | ||
123 | * @param c configuration to use | ||
124 | */ | ||
125 | static void | ||
126 | run (void *cls, | ||
127 | struct GNUNET_SERVER_Handle *server, | ||
128 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
129 | { | ||
130 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
131 | {NULL, NULL, 0, 0} | ||
132 | }; | ||
133 | |||
134 | cfg = c; | ||
135 | if (GNUNET_OK != | ||
136 | GNUNET_CONFIGURATION_get_value_filename (cfg, "psycstore", | ||
137 | "DB_FILE", | ||
138 | &db_file)) | ||
139 | { | ||
140 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "psycstore", "DB_FILE"); | ||
141 | GNUNET_SCHEDULER_shutdown (); | ||
142 | return; | ||
143 | } | ||
144 | stats = GNUNET_STATISTICS_create ("psycstore", cfg); | ||
145 | GNUNET_SERVER_add_handlers (server, handlers); | ||
146 | nc = GNUNET_SERVER_notification_context_create (server, 1); | ||
147 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | ||
148 | NULL); | ||
149 | } | ||
150 | |||
151 | |||
152 | /** | ||
153 | * The main function for the network size estimation service. | ||
154 | * | ||
155 | * @param argc number of arguments from the command line | ||
156 | * @param argv command line arguments | ||
157 | * @return 0 ok, 1 on error | ||
158 | */ | ||
159 | int | ||
160 | main (int argc, char *const *argv) | ||
161 | { | ||
162 | return (GNUNET_OK == | ||
163 | GNUNET_SERVICE_run (argc, argv, "psycstore", | ||
164 | GNUNET_SERVICE_OPTION_NONE, | ||
165 | &run, NULL)) ? 0 : 1; | ||
166 | } | ||
167 | |||
168 | |||
169 | /* end of gnunet-service-psycstore.c */ | ||