/* */ #ifndef _D_PEER_MESSAGE_H_ #define _D_PEER_MESSAGE_H_ #include "common.h" #include class PeerMessage { private: int id; int index; int begin; int length; unsigned char* bitfield; int bitfieldLength; char* block; int blockLength; public: PeerMessage():bitfield(NULL), bitfieldLength(0), block(NULL), blockLength(0) {} ~PeerMessage() { if(bitfield != NULL) { delete [] bitfield; } if(block != NULL) { delete [] block; } } void setBitfield(const unsigned char* bitfield, int bitfieldLength); const unsigned char* getBitfield() const { return bitfield; } void setBlock(const char* block, int blockLength); const char* getBlock() const { return block; } int getBitfieldLength() const { return bitfieldLength; } int getBlockLength() const { return blockLength; } string toString() const; int getId() const { return id; } void setId(int id) { this->id = id; } int getIndex() const { return index; } void setIndex(int index) { this->index = index; } int getBegin() const { return begin; } void setBegin(int begin) { this->begin = begin; } int getLength() const { return length; } void setLength(int length) { this->length = length; } enum ID { CHOKE = 0, UNCHOKE = 1, INTERESTED = 2, NOT_INTERESTED = 3, HAVE = 4, BITFIELD = 5, REQUEST = 6, PIECE = 7, CANCEL = 8, KEEP_ALIVE = 99}; }; #endif // _D_PEER_MESSAGE_H_