gnunet-service-auction.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file auction/gnunet-service-auction.c
  18. * @brief service for executing auctions
  19. * @author Markus Teich
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include "auction.h"
  24. /**
  25. * Check AUCTION CREATE messages from the client.
  26. *
  27. * @param cls the client we received this message from
  28. * @param msg the actual message received
  29. * @return #GNUNET_OK (always)
  30. */
  31. static int
  32. check_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
  33. {
  34. /* always well-formed due to arbitrary length description */
  35. return GNUNET_OK;
  36. }
  37. /**
  38. * Handler for CREATE messages.
  39. *
  40. * @param cls the client we received this message from
  41. * @param msg the actual message received
  42. */
  43. static void
  44. handle_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
  45. {
  46. struct GNUNET_SERVICE_Client *client = cls;
  47. // struct GNUNET_MQ_Handle *mq;
  48. // struct GNUNET_MQ_Envelope *env;
  49. // struct GNUNET_AUCTION_blabla em;
  50. uint16_t size;
  51. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  52. "Received CREATE message from client\n");
  53. size = ntohs (msg->header.size);
  54. /**TODO: create auction and return auction object */
  55. // mq = GNUNET_SERVICE_client_get_mq (client);
  56. // setup_info_message (&em);
  57. // env = GNUNET_MQ_msg_copy (&em.header);
  58. // GNUNET_MQ_send (mq, env);
  59. GNUNET_SERVICE_client_continue (client);
  60. }
  61. /**
  62. * Task run during shutdown.
  63. *
  64. * @param cls unused
  65. */
  66. static void
  67. cleanup_task (void *cls)
  68. {
  69. /* FIXME: do clean up here */
  70. }
  71. /**
  72. * Callback called when a client connects to the service.
  73. *
  74. * @param cls closure for the service
  75. * @param c the new client that connected to the service
  76. * @param mq the message queue used to send messages to the client
  77. * @return @a c
  78. */
  79. static void *
  80. client_connect_cb (void *cls,
  81. struct GNUNET_SERVICE_Client *c,
  82. struct GNUNET_MQ_Handle *mq)
  83. {
  84. return c;
  85. }
  86. /**
  87. * Callback called when a client disconnected from the service
  88. *
  89. * @param cls closure for the service
  90. * @param c the client that disconnected
  91. * @param internal_cls should be equal to @a c
  92. */
  93. static void
  94. client_disconnect_cb (void *cls,
  95. struct GNUNET_SERVICE_Client *c,
  96. void *internal_cls)
  97. {
  98. GNUNET_assert (c == internal_cls);
  99. }
  100. /**
  101. * Process auction requests.
  102. *
  103. * @param cls closure
  104. * @param cfg configuration to use
  105. * @param service the initialized service
  106. */
  107. static void
  108. run (void *cls,
  109. const struct GNUNET_CONFIGURATION_Handle *cfg,
  110. struct GNUNET_SERVICE_Handle *service)
  111. {
  112. /* FIXME: do setup here */
  113. GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
  114. }
  115. /**
  116. * Define "main" method using service macro.
  117. */
  118. GNUNET_SERVICE_MAIN
  119. ("auction",
  120. GNUNET_SERVICE_OPTION_NONE,
  121. &run,
  122. &client_connect_cb,
  123. &client_disconnect_cb,
  124. NULL,
  125. GNUNET_MQ_hd_var_size (create,
  126. GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE,
  127. struct GNUNET_AUCTION_ClientCreateMessage,
  128. NULL),
  129. GNUNET_MQ_handler_end ())
  130. /* end of gnunet-service-auction.c */