gnunet-service-ats_feedback.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file ats/gnunet-service-ats_feedback.c
  19. * @brief ats service, handling of feedback
  20. * @author Matthias Wachs
  21. * @author Christian Grothoff
  22. */
  23. #include "platform.h"
  24. #include "gnunet-service-ats_plugins.h"
  25. #include "gnunet-service-ats_feedback.h"
  26. #include "ats.h"
  27. /**
  28. * Change the preference for a peer
  29. *
  30. * @param application the client sending this request
  31. * @param peer the peer id
  32. * @param scope the time interval for this feedback: [now - scope .. now]
  33. * @param kind the preference kind to change
  34. * @param score_abs the new preference score
  35. */
  36. static void
  37. preference_feedback (struct GNUNET_SERVER_Client *application,
  38. const struct GNUNET_PeerIdentity *peer,
  39. const struct GNUNET_TIME_Relative scope,
  40. enum GNUNET_ATS_PreferenceKind kind,
  41. float score_abs)
  42. {
  43. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  44. "Received PREFERENCE FEEDBACK for peer `%s'\n",
  45. GNUNET_i2s (peer));
  46. GAS_plugin_preference_feedback (application,
  47. peer,
  48. scope,
  49. kind,
  50. score_abs);
  51. }
  52. /**
  53. * Handle 'preference feedback' messages from clients.
  54. *
  55. * @param cls unused, NULL
  56. * @param client client that sent the request
  57. * @param message the request message
  58. */
  59. void
  60. GAS_handle_preference_feedback (void *cls,
  61. struct GNUNET_SERVER_Client *client,
  62. const struct GNUNET_MessageHeader *message)
  63. {
  64. const struct FeedbackPreferenceMessage *msg;
  65. const struct PreferenceInformation *pi;
  66. uint16_t msize;
  67. uint32_t nump;
  68. uint32_t i;
  69. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
  70. "Received PREFERENCE_FEEDBACK message\n");
  71. msize = ntohs (message->size);
  72. if (msize < sizeof (struct FeedbackPreferenceMessage))
  73. {
  74. GNUNET_break (0);
  75. GNUNET_SERVER_receive_done (client,
  76. GNUNET_SYSERR);
  77. return;
  78. }
  79. msg = (const struct FeedbackPreferenceMessage *) message;
  80. nump = ntohl (msg->num_feedback);
  81. if (msize !=
  82. sizeof (struct FeedbackPreferenceMessage) +
  83. nump * sizeof (struct PreferenceInformation))
  84. {
  85. GNUNET_break (0);
  86. GNUNET_SERVER_receive_done (client,
  87. GNUNET_SYSERR);
  88. return;
  89. }
  90. if (GNUNET_NO ==
  91. GNUNET_CONTAINER_multipeermap_contains (GSA_addresses,
  92. &msg->peer))
  93. {
  94. GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
  95. "Received PREFERENCE FEEDBACK for unknown peer `%s'\n",
  96. GNUNET_i2s (&msg->peer));
  97. return;
  98. }
  99. GNUNET_STATISTICS_update (GSA_stats,
  100. "# preference feedbacks requests processed",
  101. 1,
  102. GNUNET_NO);
  103. pi = (const struct PreferenceInformation *) &msg[1];
  104. for (i = 0; i < nump; i++)
  105. preference_feedback (client,
  106. &msg->peer,
  107. GNUNET_TIME_relative_ntoh(msg->scope),
  108. (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind),
  109. pi[i].preference_value);
  110. GNUNET_SERVER_receive_done (client,
  111. GNUNET_OK);
  112. }
  113. /* end of gnunet-service-ats_feedback.c */