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 LOG(kind,...) \
36 GNUNET_log_from (kind, "gnunet-service-lockmanager",__VA_ARGS__)
38 #define TIME_REL_MINS(min) \
39 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, min)
41 #define TIMEOUT TIME_REL_MINS(3)
44 * Transmit notify for sending message to client
46 * @param cls the message to send
47 * @param size number of bytes available in buf
48 * @param buf where the callee should write the message
49 * @return number of bytes written to buf
52 transmit_notify (void *cls, size_t size, void *buf)
54 struct GNUNET_LOCKMANAGER_Message *msg = cls;
57 if ((0 == size) || (NULL == buf))
59 /* FIXME: Timed out -- requeue? */
62 msg_size = ntohs (msg->header.size);
63 GNUNET_assert (size >= msg_size);
64 memcpy (buf, msg, msg_size);
66 LOG (GNUNET_ERROR_TYPE_DEBUG,
67 "Message of size %u sent\n", msg_size);
73 * Handler for GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE
76 * @param client the client sending this message
77 * @param message GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE message
80 handle_acquire (void *cls,
81 struct GNUNET_SERVER_Client *client,
82 const struct GNUNET_MessageHeader *message)
84 const struct GNUNET_LOCKMANAGER_Message *request;
85 struct GNUNET_LOCKMANAGER_Message *reply;
89 LOG (GNUNET_ERROR_TYPE_DEBUG,
90 "Received an ACQUIRE message\n");
92 request = (struct GNUNET_LOCKMANAGER_Message *) message;
94 /* FIXME: Dummy implementation; just echos success for every lock */
95 request_size = ntohs (message->size);
96 reply = GNUNET_malloc (request_size);
97 memcpy (reply, request, request_size);
98 reply->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS);
99 GNUNET_SERVER_notify_transmit_ready (client,
105 GNUNET_SERVER_receive_done (client, GNUNET_OK);
110 * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE
116 handle_release (void *cls,
117 struct GNUNET_SERVER_Client *client,
118 const struct GNUNET_MessageHeader *message)
120 LOG (GNUNET_ERROR_TYPE_DEBUG,
121 "Received a RELEASE message\n");
123 GNUNET_SERVER_receive_done (client, GNUNET_OK);
131 * @param server the initialized server
132 * @param cfg configuration to use
135 lockmanager_run (void *cls,
136 struct GNUNET_SERVER_Handle * server,
137 const struct GNUNET_CONFIGURATION_Handle *cfg)
139 static const struct GNUNET_SERVER_MessageHandler message_handlers[] =
141 {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0},
142 {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0},
146 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lockmanager\n");
147 GNUNET_SERVER_add_handlers (server,
153 * The starting point of execution
155 int main (int argc, char *const *argv)
159 LOG (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
162 GNUNET_SERVICE_run (argc,
165 GNUNET_SERVICE_OPTION_NONE,
168 LOG (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");