2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
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 2, or (at your
8 option) any later version.
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.
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.
22 * @file lockmanager/gnunet-service-lockmanager.c
23 * @brief implementation of the LOCKMANAGER service
24 * @author Sree Harsha Totakura
28 #include "gnunet_common.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_service_lib.h"
31 #include "gnunet_server_lib.h"
33 #include "lockmanager.h"
35 #define VERBOSE GNUNET_YES
37 #define LOG(kind,...) \
38 GNUNET_log (kind, __VA_ARGS__)
40 #define TIME_REL_MINS(min) \
41 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, min)
43 #define TIMEOUT TIME_REL_MINS(3)
46 * Transmit notify for sending message to client
48 * @param cls the message to send
49 * @param size number of bytes available in buf
50 * @param buf where the callee should write the message
51 * @return number of bytes written to buf
54 transmit_notify (void *cls, size_t size, void *buf)
56 struct GNUNET_LOCKMANAGER_Message *msg = cls;
59 if ((0 == size) || (NULL == buf))
61 /* FIXME: Timed out -- requeue? */
64 msg_size = ntohs (msg->header.size);
65 GNUNET_assert (size >= msg_size);
66 memcpy (buf, msg, msg_size);
68 LOG (GNUNET_ERROR_TYPE_DEBUG,
69 "Message of size %u sent\n", msg_size);
75 * Handler for GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE
78 * @param client the client sending this message
79 * @param message GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE message
82 handle_acquire (void *cls,
83 struct GNUNET_SERVER_Client *client,
84 const struct GNUNET_MessageHeader *message)
86 const struct GNUNET_LOCKMANAGER_Message *request;
87 struct GNUNET_LOCKMANAGER_Message *reply;
91 LOG (GNUNET_ERROR_TYPE_DEBUG,
92 "Received an ACQUIRE message\n");
94 request = (struct GNUNET_LOCKMANAGER_Message *) message;
96 /* FIXME: Dummy implementation; just echos success for every lock */
97 request_size = ntohs (message->size);
98 reply = GNUNET_malloc (request_size);
99 memcpy (reply, request, request_size);
100 reply->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS);
101 GNUNET_SERVER_notify_transmit_ready (client,
107 GNUNET_SERVER_receive_done (client, GNUNET_OK);
112 * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE
115 * @param client the client sending this message
116 * @param message the LOCKMANAGER_RELEASE message
119 handle_release (void *cls,
120 struct GNUNET_SERVER_Client *client,
121 const struct GNUNET_MessageHeader *message)
123 LOG (GNUNET_ERROR_TYPE_DEBUG,
124 "Received a RELEASE message\n");
126 GNUNET_SERVER_receive_done (client, GNUNET_OK);
134 * @param server the initialized server
135 * @param cfg configuration to use
138 lockmanager_run (void *cls,
139 struct GNUNET_SERVER_Handle * server,
140 const struct GNUNET_CONFIGURATION_Handle *cfg)
142 static const struct GNUNET_SERVER_MessageHandler message_handlers[] =
144 {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0},
145 {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0},
149 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lockmanager\n");
150 GNUNET_SERVER_add_handlers (server,
156 * The starting point of execution
158 int main (int argc, char *const *argv)
162 GNUNET_log_setup ("lockmanager",
170 LOG (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
173 GNUNET_SERVICE_run (argc,
176 GNUNET_SERVICE_OPTION_NONE,
179 LOG (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");