LpdMessageReceiver.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * aria2 - The high speed download utility
  3. *
  4. * Copyright (C) 2010 Tatsuhiro Tsujikawa
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * In addition, as a special exception, the copyright holders give
  21. * permission to link the code of portions of this program with the
  22. * OpenSSL library under certain conditions as described in each
  23. * individual source file, and distribute linked combinations
  24. * including the two.
  25. * You must obey the GNU General Public License in all respects
  26. * for all of the code used other than OpenSSL. If you modify
  27. * file(s) with this exception, you may extend this exception to your
  28. * version of the file(s), but you are not obligated to do so. If you
  29. * do not wish to do so, delete this exception statement from your
  30. * version. If you delete this exception statement from all source
  31. * files in the program, then also delete it here.
  32. */
  33. #ifndef _LPD_MESSAGE_RECEIVER_H_
  34. #define _LPD_MESSAGE_RECEIVER_H_
  35. #include "common.h"
  36. #include <string>
  37. #include "SharedHandle.h"
  38. namespace aria2 {
  39. class SocketCore;
  40. class Logger;
  41. class LpdMessage;
  42. class LpdMessageReceiver {
  43. private:
  44. SharedHandle<SocketCore> _socket;
  45. std::string _multicastAddress;
  46. uint16_t _multicastPort;
  47. std::string _localAddress;
  48. Logger* _logger;
  49. public:
  50. // Currently only IPv4 multicastAddresses are supported.
  51. LpdMessageReceiver
  52. (const std::string& multicastAddress, uint16_t multicastPort);
  53. // No throw.
  54. bool init(const std::string& localAddr);
  55. // Receives LPD message and returns LpdMessage which contains
  56. // sender(peer) and infohash. If no data is available on socket,
  57. // returns SharedHandle<LpdMessage>(). If received data is bad,
  58. // then returns SharedHandle<LpdMessage>(new LpdMessage())
  59. SharedHandle<LpdMessage> receiveMessage();
  60. const SharedHandle<SocketCore>& getSocket() const
  61. {
  62. return _socket;
  63. }
  64. const std::string& getLocalAddress() const
  65. {
  66. return _localAddress;
  67. }
  68. };
  69. } // namespace aria2
  70. #endif // _LPD_MESSAGE_RECEIVER_H_