PeerMessageFactory.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - a simple utility for downloading files faster
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /* copyright --> */
  22. #ifndef _D_PEER_MESSAGE_FACTORY_H_
  23. #define _D_PEER_MESSAGE_FACTORY_H_
  24. #include "common.h"
  25. #include "PeerMessage.h"
  26. #include "HandshakeMessage.h"
  27. class PeerInteraction;
  28. class PeerMessageFactory {
  29. private:
  30. int cuid;
  31. PeerInteraction* peerInteraction;
  32. PeerHandle peer;
  33. void setPeerMessageCommonProperty(PeerMessageHandle& peerMessage) const;
  34. public:
  35. PeerMessageFactory(int cuid,
  36. PeerInteraction* peerInteraction,
  37. const PeerHandle& peer);
  38. ~PeerMessageFactory();
  39. PeerMessageHandle
  40. createPeerMessage(const char* msg, int msgLength) const;
  41. PeerMessageHandle
  42. createHandshakeMessage(const char* msg,
  43. int msgLength) const;
  44. PeerMessageHandle
  45. createHandshakeMessage(const unsigned char* infoHash,
  46. const char* peerId) const;
  47. PeerMessageHandle createRequestMessage(const Piece& piece,
  48. int blockIndex) const;
  49. PeerMessageHandle createCancelMessage(int index, int begin, int length) const;
  50. PeerMessageHandle createPieceMessage(int index, int begin, int length) const;
  51. PeerMessageHandle createHaveMessage(int index) const;
  52. PeerMessageHandle createChokeMessage() const;
  53. PeerMessageHandle createUnchokeMessage() const;
  54. PeerMessageHandle createInterestedMessage() const;
  55. PeerMessageHandle createNotInterestedMessage() const;
  56. PeerMessageHandle createBitfieldMessage() const;
  57. PeerMessageHandle createKeepAliveMessage() const;
  58. PeerMessageHandle createHaveAllMessage() const;
  59. PeerMessageHandle createHaveNoneMessage() const;
  60. PeerMessageHandle createRejectMessage(int index, int begin, int length) const;
  61. PeerMessageHandle createAllowedFastMessage(int index) const;
  62. };
  63. #endif // _D_PEER_MESSAGE_FACTORY_H_