PeerMessageUtil.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_UTIL_H_
  23. #define _D_PEER_MESSAGE_UTIL_H_
  24. #include "ChokeMessage.h"
  25. #include "UnchokeMessage.h"
  26. #include "InterestedMessage.h"
  27. #include "NotInterestedMessage.h"
  28. #include "HaveMessage.h"
  29. #include "BitfieldMessage.h"
  30. #include "RequestMessage.h"
  31. #include "CancelMessage.h"
  32. #include "PieceMessage.h"
  33. #include "HandshakeMessage.h"
  34. #include "KeepAliveMessage.h"
  35. #include "PortMessage.h"
  36. #include "HaveAllMessage.h"
  37. #include "HaveNoneMessage.h"
  38. #include "PeerConnection.h"
  39. #include "common.h"
  40. #define MAX_BLOCK_LENGTH (128*1024)
  41. class PeerMessageUtil {
  42. private:
  43. PeerMessageUtil() {}
  44. public:
  45. static int getIntParam(const char* msg, int offset);
  46. static int getShortIntParam(const char* msg, int offset);
  47. static void setIntParam(char* dest, int param);
  48. static int getId(const char* msg);
  49. static void checkIndex(int index, int pieces);
  50. static void checkBegin(int begin, int pieceLength);
  51. static void checkLength(int length);
  52. static void checkRange(int begin, int length, int pieceLength);
  53. static void checkBitfield(const unsigned char* bitfield,
  54. int bitfieldLength,
  55. int pieces);
  56. static void checkHandshake(const HandshakeMessage* message,
  57. const unsigned char* infoHash);
  58. static void createPeerMessageString(char* msg, int msgLength,
  59. int payloadLength, int messageId);
  60. };
  61. #endif // _D_PEER_MESSAGE_UTIL_H_