Jelajahi Sumber

Use int32_t for begin, length in RangeBtMessage

Tatsuhiro Tsujikawa 14 tahun lalu
induk
melakukan
b97a7c8ecf

+ 1 - 1
src/BtCancelMessage.cc

@@ -40,7 +40,7 @@ namespace aria2 {
 const std::string BtCancelMessage::NAME("cancel");
 
 BtCancelMessage::BtCancelMessage
-(size_t index, uint32_t begin, size_t length)
+(size_t index, int32_t begin, int32_t length)
   :RangeBtMessage(ID, NAME, index, begin, length) {}
 
 SharedHandle<BtCancelMessage> BtCancelMessage::create

+ 1 - 1
src/BtCancelMessage.h

@@ -45,7 +45,7 @@ typedef SharedHandle<BtCancelMessage> BtCancelMessageHandle;
 
 class BtCancelMessage : public RangeBtMessage {
 public:
-  BtCancelMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0);
+  BtCancelMessage(size_t index = 0, int32_t begin = 0, int32_t length = 0);
 
   static const int8_t ID = 8;
 

+ 5 - 5
src/BtCancelSendingPieceEvent.h

@@ -42,17 +42,17 @@ namespace aria2 {
 class BtCancelSendingPieceEvent {
 private:
   size_t index_;
-  uint32_t begin_;
-  size_t length_;
+  int32_t begin_;
+  int32_t length_;
 public:
-  BtCancelSendingPieceEvent(size_t index, uint32_t begin, size_t length):
+  BtCancelSendingPieceEvent(size_t index, int32_t begin, int32_t length):
     index_(index), begin_(begin), length_(length) {}
 
   size_t getIndex() const { return index_; }
 
-  uint32_t getBegin() const { return begin_; }
+  int32_t getBegin() const { return begin_; }
 
-  size_t getLength() const { return length_; }
+  int32_t getLength() const { return length_; }
 };
 
 } // namespace aria2

+ 4 - 2
src/BtMessageDispatcher.h

@@ -58,7 +58,8 @@ public:
 
   virtual void sendMessages() = 0;
 
-  virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) = 0;
+  virtual void doCancelSendingPieceAction
+  (size_t index, int32_t begin, int32_t length) = 0;
 
   virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece) = 0;
 
@@ -78,7 +79,8 @@ public:
 
   virtual bool isOutstandingRequest(size_t index, size_t blockIndex) = 0;
 
-  virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length) = 0;
+  virtual RequestSlot getOutstandingRequest
+  (size_t index, int32_t begin, int32_t length) = 0;
 
   virtual void removeOutstandingRequest(const RequestSlot& slot) = 0;
 

+ 3 - 3
src/BtMessageFactory.h

@@ -63,10 +63,10 @@ public:
   createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) = 0;
 
   virtual SharedHandle<BtMessage>
-  createCancelMessage(size_t index, uint32_t begin, size_t length) = 0;
+  createCancelMessage(size_t index, int32_t begin, int32_t length) = 0;
 
   virtual SharedHandle<BtMessage>
-  createPieceMessage(size_t index, uint32_t begin, size_t length) = 0;
+  createPieceMessage(size_t index, int32_t begin, int32_t length) = 0;
 
   virtual SharedHandle<BtMessage> createHaveMessage(size_t index) = 0;
 
@@ -87,7 +87,7 @@ public:
   virtual SharedHandle<BtMessage> createHaveNoneMessage() = 0;
 
   virtual SharedHandle<BtMessage>
-  createRejectMessage(size_t index, uint32_t begin, size_t length) = 0;
+  createRejectMessage(size_t index, int32_t begin, int32_t length) = 0;
 
   virtual SharedHandle<BtMessage> createAllowedFastMessage(size_t index) = 0;
 

+ 11 - 14
src/BtPieceMessage.cc

@@ -62,27 +62,25 @@ namespace aria2 {
 const std::string BtPieceMessage::NAME("piece");
 
 BtPieceMessage::BtPieceMessage
-(size_t index, uint32_t begin, size_t blockLength)
+(size_t index, int32_t begin, int32_t blockLength)
   : AbstractBtMessage(ID, NAME),
     index_(index),
     begin_(begin),
     blockLength_(blockLength),
-    block_(0),
-    rawData_(0)
+    data_(0)
 {
   setUploading(true);
 }
 
 BtPieceMessage::~BtPieceMessage()
 {
-  delete [] rawData_;
+  delete [] data_;
 }
 
 void BtPieceMessage::setRawMessage(unsigned char* data)
 {
-  delete [] rawData_;
-  rawData_ = data;
-  block_ = data+9;
+  delete [] data_;
+  data_ = data;
 }
 
 BtPieceMessageHandle BtPieceMessage::create
@@ -121,12 +119,12 @@ void BtPieceMessage::doReceivedAction()
       return;
     }
     getPieceStorage()->getDiskAdaptor()->writeData
-      (block_, blockLength_, offset);
+      (data_+9, blockLength_, offset);
     piece->completeBlock(slot.getBlockIndex());
     A2_LOG_DEBUG(fmt(MSG_PIECE_BITFIELD, getCuid(),
                      util::toHex(piece->getBitfield(),
                                  piece->getBitfieldLength()).c_str()));
-    piece->updateHash(begin_, block_, blockLength_);
+    piece->updateHash(begin_, data_+9, blockLength_);
     getBtMessageDispatcher()->removeOutstandingRequest(slot);
     if(piece->pieceComplete()) {
       if(checkPieceHash(piece)) {
@@ -195,7 +193,7 @@ void BtPieceMessage::send()
   setSendingInProgress(!getPeerConnection()->sendBufferIsEmpty());
 }
 
-void BtPieceMessage::pushPieceData(off_t offset, size_t length) const
+void BtPieceMessage::pushPieceData(off_t offset, int32_t length) const
 {
   assert(length <= 16*1024);
   unsigned char* buf = new unsigned char[length];
@@ -206,7 +204,7 @@ void BtPieceMessage::pushPieceData(off_t offset, size_t length) const
     delete [] buf;
     throw;
   }
-  if(r == static_cast<ssize_t>(length)) {
+  if(r == length) {
     getPeerConnection()->pushBytes(buf, length);
   } else {
     throw DL_ABORT_EX(EX_DATA_READ);
@@ -215,11 +213,10 @@ void BtPieceMessage::pushPieceData(off_t offset, size_t length) const
 
 std::string BtPieceMessage::toString() const
 {
-  return fmt("%s index=%lu, begin=%u, length=%lu",
+  return fmt("%s index=%lu, begin=%d, length=%d",
              NAME.c_str(),
              static_cast<unsigned long>(index_),
-             begin_,
-             static_cast<unsigned long>(blockLength_));
+             begin_, blockLength_);
 }
 
 bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)

+ 10 - 11
src/BtPieceMessage.h

@@ -49,10 +49,9 @@ typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
 class BtPieceMessage : public AbstractBtMessage {
 private:
   size_t index_;
-  uint32_t begin_;
-  uint32_t blockLength_;
-  unsigned char* block_;
-  unsigned char* rawData_;
+  int32_t begin_;
+  int32_t blockLength_;
+  unsigned char* data_;
   SharedHandle<DownloadContext> downloadContext_;
   SharedHandle<PeerStorage> peerStorage_;
 
@@ -66,9 +65,9 @@ private:
 
   void erasePieceOnDisk(const SharedHandle<Piece>& piece);
 
-  void pushPieceData(off_t offset, size_t length) const;
+  void pushPieceData(off_t offset, int32_t length) const;
 public:
-  BtPieceMessage(size_t index = 0, uint32_t begin = 0, size_t blockLength = 0);
+  BtPieceMessage(size_t index = 0, int32_t begin = 0, int32_t blockLength = 0);
 
   virtual ~BtPieceMessage();
 
@@ -80,20 +79,20 @@ public:
 
   void setIndex(size_t index) { index_ = index; }
 
-  uint32_t getBegin() const { return begin_; }
+  int32_t getBegin() const { return begin_; }
 
-  void setBegin(uint32_t begin) { begin_ = begin; }
+  void setBegin(int32_t begin) { begin_ = begin; }
 
-  const unsigned char* getBlock() const { return block_; }
+  const unsigned char* getBlock() const { return data_+9; }
 
-  size_t getBlockLength() const { return blockLength_; }
+  int32_t getBlockLength() const { return blockLength_; }
 
   // Stores raw message data. After this function call, this object
   // has ownership of data. Caller must not be free or alter data.
   // Member block is pointed to block starting position in data.
   void setRawMessage(unsigned char* data);
 
-  void setBlockLength(size_t blockLength) { blockLength_ = blockLength; }
+  void setBlockLength(int32_t blockLength) { blockLength_ = blockLength; }
 
   void setDownloadContext(const SharedHandle<DownloadContext>& downloadContext);
 

+ 1 - 1
src/BtRejectMessage.cc

@@ -44,7 +44,7 @@ namespace aria2 {
 const std::string BtRejectMessage::NAME("reject");
 
 BtRejectMessage::BtRejectMessage
-(size_t index, uint32_t begin, size_t length):
+(size_t index, int32_t begin, int32_t length):
   RangeBtMessage(ID, NAME, index, begin, length) {}
 
 SharedHandle<BtRejectMessage> BtRejectMessage::create

+ 1 - 1
src/BtRejectMessage.h

@@ -45,7 +45,7 @@ typedef SharedHandle<BtRejectMessage> BtRejectMessageHandle;
 
 class BtRejectMessage : public RangeBtMessage {
 public:
-  BtRejectMessage(size_t index = 0, uint32_t begin = 0, size_t length = 0);
+  BtRejectMessage(size_t index = 0, int32_t begin = 0, int32_t length = 0);
 
   static const uint8_t ID = 16;
 

+ 1 - 1
src/BtRequestMessage.cc

@@ -44,7 +44,7 @@ namespace aria2 {
 const std::string BtRequestMessage::NAME("request");
 
 BtRequestMessage::BtRequestMessage
-(size_t index, uint32_t begin, uint32_t length, size_t blockIndex):
+(size_t index, int32_t begin, int32_t length, size_t blockIndex):
   RangeBtMessage(ID, NAME, index, begin, length),
   blockIndex_(blockIndex) {}
 

+ 2 - 2
src/BtRequestMessage.h

@@ -48,8 +48,8 @@ private:
   size_t blockIndex_;
 public:
   BtRequestMessage(size_t index = 0,
-                   uint32_t begin = 0,
-                   uint32_t length = 0,
+                   int32_t begin = 0,
+                   int32_t length = 0,
                    size_t blockIndex = 0);
 
   static const uint8_t ID = 6;

+ 2 - 2
src/DefaultBtMessageDispatcher.cc

@@ -123,7 +123,7 @@ void DefaultBtMessageDispatcher::sendMessages() {
 
 // Cancel sending piece message to peer.
 void DefaultBtMessageDispatcher::doCancelSendingPieceAction
-(size_t index, uint32_t begin, size_t length)
+(size_t index, int32_t begin, int32_t length)
 {
   BtCancelSendingPieceEvent event(index, begin, length);
 
@@ -381,7 +381,7 @@ bool DefaultBtMessageDispatcher::isOutstandingRequest
 
 RequestSlot
 DefaultBtMessageDispatcher::getOutstandingRequest
-(size_t index, uint32_t begin, size_t length)
+(size_t index, int32_t begin, int32_t length)
 {
   for(std::deque<RequestSlot>::const_iterator itr = requestSlots_.begin(),
         eoi = requestSlots_.end(); itr != eoi; ++itr) {

+ 4 - 2
src/DefaultBtMessageDispatcher.h

@@ -77,7 +77,8 @@ public:
 
   virtual void sendMessages();
 
-  virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length);
+  virtual void doCancelSendingPieceAction
+  (size_t index, int32_t begin, int32_t length);
 
   virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece);
 
@@ -102,7 +103,8 @@ public:
   
   virtual bool isOutstandingRequest(size_t index, size_t blockIndex);
 
-  virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length);
+  virtual RequestSlot getOutstandingRequest
+  (size_t index, int32_t begin, int32_t length);
 
   virtual void removeOutstandingRequest(const RequestSlot& slot);
 

+ 3 - 3
src/DefaultBtMessageFactory.cc

@@ -317,7 +317,7 @@ DefaultBtMessageFactory::createRequestMessage
 
 BtMessageHandle
 DefaultBtMessageFactory::createCancelMessage
-(size_t index, uint32_t begin, size_t length)
+(size_t index, int32_t begin, int32_t length)
 {
   BtCancelMessageHandle msg(new BtCancelMessage(index, begin, length));
   SharedHandle<BtMessageValidator> validator
@@ -332,7 +332,7 @@ DefaultBtMessageFactory::createCancelMessage
 
 BtMessageHandle
 DefaultBtMessageFactory::createPieceMessage
-(size_t index, uint32_t begin, size_t length)
+(size_t index, int32_t begin, int32_t length)
 {
   BtPieceMessageHandle msg(new BtPieceMessage(index, begin, length));
   BtMessageValidatorHandle validator
@@ -428,7 +428,7 @@ DefaultBtMessageFactory::createHaveNoneMessage()
 
 BtMessageHandle
 DefaultBtMessageFactory::createRejectMessage
-(size_t index, uint32_t begin, size_t length)
+(size_t index, int32_t begin, int32_t length)
 {
   BtRejectMessageHandle msg(new BtRejectMessage(index, begin, length));
   SharedHandle<BtMessageValidator> validator

+ 3 - 3
src/DefaultBtMessageFactory.h

@@ -102,10 +102,10 @@ public:
   createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex);
 
   virtual SharedHandle<BtMessage>
-  createCancelMessage(size_t index, uint32_t begin, size_t length);
+  createCancelMessage(size_t index, int32_t begin, int32_t length);
 
   virtual SharedHandle<BtMessage>
-  createPieceMessage(size_t index, uint32_t begin, size_t length);
+  createPieceMessage(size_t index, int32_t begin, int32_t length);
 
   virtual SharedHandle<BtMessage> createHaveMessage(size_t index);
 
@@ -126,7 +126,7 @@ public:
   virtual SharedHandle<BtMessage> createHaveNoneMessage();
 
   virtual SharedHandle<BtMessage>
-  createRejectMessage(size_t index, uint32_t begin, size_t length);
+  createRejectMessage(size_t index, int32_t begin, int32_t length);
 
   virtual SharedHandle<BtMessage> createAllowedFastMessage(size_t index);
 

+ 3 - 4
src/RangeBtMessage.cc

@@ -41,7 +41,7 @@ namespace aria2 {
 
 RangeBtMessage::RangeBtMessage(uint8_t id,
                                const std::string& name,
-                               size_t index, uint32_t begin, size_t length)
+                               size_t index, int32_t begin, int32_t length)
   :SimpleBtMessage(id, name),
    index_(index),
    begin_(begin),
@@ -72,11 +72,10 @@ size_t RangeBtMessage::getMessageLength()
 
 std::string RangeBtMessage::toString() const
 {
-  return fmt("%s index=%lu, begin=%u, length=%lu",
+  return fmt("%s index=%lu, begin=%d, length=%d",
              getName().c_str(),
              static_cast<unsigned long>(index_),
-             begin_,
-             static_cast<unsigned long>(length_));
+             begin_, length_);
 }
 
 } // namespace aria2

+ 7 - 7
src/RangeBtMessage.h

@@ -43,8 +43,8 @@ namespace aria2 {
 class RangeBtMessage : public SimpleBtMessage {
 private:
   size_t index_;
-  uint32_t begin_;
-  size_t length_;
+  int32_t begin_;
+  int32_t length_;
 
   static const size_t MESSAGE_LENGTH = 17;
 protected:
@@ -62,19 +62,19 @@ protected:
   }
 public:
   RangeBtMessage(uint8_t id, const std::string& name,
-                 size_t index, uint32_t begin, size_t length);
+                 size_t index, int32_t begin, int32_t length);
 
   size_t getIndex() const { return index_; }
 
   void setIndex(size_t index) { index_ = index; }
 
-  uint32_t getBegin() const { return begin_; }
+  int32_t getBegin() const { return begin_; }
 
-  void setBegin(uint32_t begin) { begin_ = begin; }
+  void setBegin(int32_t begin) { begin_ = begin; }
 
-  size_t getLength() const { return length_; }
+  int32_t getLength() const { return length_; }
 
-  void setLength(size_t length) { length_ = length; }
+  void setLength(int32_t length) { length_ = length; }
 
   virtual unsigned char* createMessage();
 

+ 1 - 1
src/RangeBtMessageValidator.cc

@@ -39,7 +39,7 @@
 namespace aria2 {
 
 RangeBtMessageValidator::RangeBtMessageValidator
-(const RangeBtMessage* message, size_t numPiece, size_t pieceLength)
+(const RangeBtMessage* message, size_t numPiece, int32_t pieceLength)
   : message_(message),
     numPiece_(numPiece),
     pieceLength_(pieceLength)

+ 2 - 2
src/RangeBtMessageValidator.h

@@ -45,11 +45,11 @@ class RangeBtMessageValidator : public BtMessageValidator {
 private:
   const RangeBtMessage* message_;
   size_t numPiece_;
-  size_t pieceLength_;
+  int32_t pieceLength_;
 public:
   RangeBtMessageValidator(const RangeBtMessage* message,
                           size_t numPiece,
-                          size_t pieceLength);
+                          int32_t pieceLength);
 
   ~RangeBtMessageValidator();
 

+ 7 - 7
src/RequestSlot.h

@@ -46,8 +46,8 @@ class RequestSlot {
 private:
   Timer dispatchedTime_;
   size_t index_;
-  uint32_t begin_;
-  size_t length_;
+  int32_t begin_;
+  int32_t length_;
   size_t blockIndex_;
 
   // This is the piece whose index is index of this RequestSlot has.
@@ -69,7 +69,7 @@ private:
   }
 public:
   
-  RequestSlot(size_t index, uint32_t begin, size_t length, size_t blockIndex,
+  RequestSlot(size_t index, int32_t begin, int32_t length, size_t blockIndex,
               const SharedHandle<Piece>& piece = SharedHandle<Piece>()):
     dispatchedTime_(global::wallclock()),
     index_(index), begin_(begin), length_(length), blockIndex_(blockIndex),
@@ -124,11 +124,11 @@ public:
   size_t getIndex() const { return index_; }
   void setIndex(size_t index) { index_ = index; }
 
-  uint32_t getBegin() const { return begin_; }
-  void setBegin(uint32_t begin) { begin_ = begin; }
+  int32_t getBegin() const { return begin_; }
+  void setBegin(int32_t begin) { begin_ = begin; }
 
-  size_t getLength() const { return length_; }
-  void setLength(size_t length) { length_ = length; }
+  int32_t getLength() const { return length_; }
+  void setLength(int32_t length) { length_ = length; }
 
   size_t getBlockIndex() const { return blockIndex_; }
   void setBlockIndex(size_t blockIndex) { blockIndex_ = blockIndex; }

+ 9 - 17
src/bittorrent_helper.cc

@@ -729,42 +729,34 @@ void checkIndex(size_t index, size_t pieces)
   }
 }
 
-void checkBegin(uint32_t begin, size_t pieceLength)
+void checkBegin(int32_t begin, int32_t pieceLength)
 {
   if(!(begin < pieceLength)) {
-    throw DL_ABORT_EX(fmt("Invalid begin: %u", begin));
+    throw DL_ABORT_EX(fmt("Invalid begin: %d", begin));
   }  
 }
 
-void checkLength(size_t length)
+void checkLength(int32_t length)
 {
   if(length > MAX_BLOCK_LENGTH) {
     throw DL_ABORT_EX
-      (fmt("Length too long: %lu > %uKB",
-           static_cast<unsigned long>(length),
-           MAX_BLOCK_LENGTH/1024));
+      (fmt("Length too long: %d > %dKB", length, MAX_BLOCK_LENGTH/1024));
   }
   if(length == 0) {
-    throw DL_ABORT_EX
-      (fmt("Invalid length: %lu",
-           static_cast<unsigned long>(length)));
+    throw DL_ABORT_EX(fmt("Invalid length: %d", length));
   }
 }
 
-void checkRange(uint32_t begin, size_t length, size_t pieceLength)
+void checkRange(int32_t begin, int32_t length, int32_t pieceLength)
 {
   if(!(0 < length)) {
     throw DL_ABORT_EX
-      (fmt("Invalid range: begin=%u, length=%lu",
-           begin,
-           static_cast<unsigned long>(length)));
+      (fmt("Invalid range: begin=%d, length=%d", begin, length));
   }
-  uint32_t end = begin+length;
+  int32_t end = begin+length;
   if(!(end <= pieceLength)) {
     throw DL_ABORT_EX
-      (fmt("Invalid range: begin=%u, length=%lu",
-           begin,
-           static_cast<unsigned long>(length)));
+      (fmt("Invalid range: begin=%d, length=%d", begin, length));
   }
 }
 

+ 3 - 3
src/bittorrent_helper.h

@@ -178,9 +178,9 @@ void setShortIntParam(unsigned char* dest, uint16_t param);
 uint8_t getId(const unsigned char* msg);
   
 void checkIndex(size_t index, size_t pieces);
-void checkBegin(uint32_t begin, size_t pieceLength);
-void checkLength(size_t length);
-void checkRange(uint32_t begin, size_t length, size_t pieceLength);
+void checkBegin(int32_t begin, int32_t pieceLength);
+void checkLength(int32_t length);
+void checkRange(int32_t begin, int32_t length, int32_t pieceLength);
 void checkBitfield
 (const unsigned char* bitfield, size_t bitfieldLength, size_t pieces);
 

+ 7 - 7
src/message.h

@@ -63,27 +63,27 @@
 #define MSG_DNS_CACHE_HIT "CUID#%lld - DNS cache hit: %s -> %s"
 #define MSG_CONNECTING_TO_PEER "CUID#%lld - Connecting to the peer %s"
 #define MSG_PIECE_RECEIVED                                              \
-  "CUID#%lld - Piece received. index=%lu, begin=%u, length=%u, offset=%lld," \
+  "CUID#%lld - Piece received. index=%lu, begin=%d, length=%d, offset=%lld," \
   " blockIndex=%lu"
 #define MSG_PIECE_BITFIELD "CUID#%lld - Piece bitfield %s"
 #define MSG_REJECT_PIECE_CHOKED                                         \
   "CUID#%lld - Reject piece message in queue because the peer has been" \
-  " choked. index=%lu, begin=%u, length=%u"
+  " choked. index=%lu, begin=%d, length=%d"
 #define MSG_REJECT_PIECE_CANCEL                                         \
   "CUID#%lld - Reject piece message in queue because cancel message received." \
-  " index=%lu, begin=%u, length=%u"
+  " index=%lu, begin=%d, length=%d"
 #define MSG_FILE_VALIDATION_FAILURE                             \
   "CUID#%lld - Exception caught while validating file integrity."
 #define MSG_PEER_INTERESTED "CUID#%lld - Interested in the peer"
 #define MSG_PEER_NOT_INTERESTED "CUID#%lld - Not interested in the peer"
 #define MSG_DELETING_REQUEST_SLOT "CUID#%lld - Deleting request slot" \
-  " index=%lu, begin=%u, blockIndex=%lu"
+  " index=%lu, begin=%d, blockIndex=%lu"
 #define MSG_DELETING_REQUEST_SLOT_CHOKED "CUID#%lld - Deleting request slot" \
-  " index=%lu, begin=%u, blockIndex=%lu because localhost got choked."
+  " index=%lu, begin=%d, blockIndex=%lu because localhost got choked."
 #define MSG_DELETING_REQUEST_SLOT_TIMEOUT "CUID#%lld - Deleting request slot" \
-  " index=%lu, begin=%u, blockIndex=%lu because of time out"
+  " index=%lu, begin=%d, blockIndex=%lu because of time out"
 #define MSG_DELETING_REQUEST_SLOT_ACQUIRED "CUID#%lld - Deleting request slot" \
-  " index=%lu, begin=%u, blockIndex=%lu because the block has been acquired."
+  " index=%lu, begin=%d, blockIndex=%lu because the block has been acquired."
 #define MSG_FAST_EXTENSION_ENABLED "CUID#%lld - Fast extension enabled."
 #define MSG_EXTENDED_MESSAGING_ENABLED "CUID#%lld - Extended Messaging enabled."
 #define MSG_FILE_ALLOCATION_FAILURE                             \

+ 6 - 5
test/BtCancelMessageTest.cc

@@ -33,14 +33,15 @@ public:
   class MockBtMessageDispatcher2 : public MockBtMessageDispatcher {
   public:
     size_t index;
-    uint32_t begin;
-    size_t length;
+    int32_t begin;
+    int32_t length;
   public:
     MockBtMessageDispatcher2():index(0),
                                begin(0),
                                length(0) {}
 
-    virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) {
+    virtual void doCancelSendingPieceAction
+    (size_t index, int32_t begin, int32_t length) {
       this->index = index;
       this->begin = begin;
       this->length = length;
@@ -60,8 +61,8 @@ void BtCancelMessageTest::testCreate() {
   SharedHandle<BtCancelMessage> pm = BtCancelMessage::create(&msg[4], 13);
   CPPUNIT_ASSERT_EQUAL((uint8_t)8, pm->getId());
   CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
-  CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin());
-  CPPUNIT_ASSERT_EQUAL((size_t)1024, pm->getLength());
+  CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
+  CPPUNIT_ASSERT_EQUAL(1024, pm->getLength());
 
   // case: payload size is wrong
   try {

+ 4 - 4
test/BtPieceMessageTest.cc

@@ -65,8 +65,8 @@ public:
   public:
     virtual SharedHandle<BtMessage>
     createRejectMessage(size_t index,
-                        uint32_t begin,
-                        size_t length) {
+                        int32_t begin,
+                        int32_t length) {
       SharedHandle<MockBtMessage2> msg(new MockBtMessage2(index, begin, length));
       return msg;
     }
@@ -113,8 +113,8 @@ void BtPieceMessageTest::testCreate() {
   SharedHandle<BtPieceMessage> pm = BtPieceMessage::create(&msg[4], 11);
   CPPUNIT_ASSERT_EQUAL((uint8_t)7, pm->getId());
   CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
-  CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin());
-  CPPUNIT_ASSERT_EQUAL((size_t)2, pm->getBlockLength());
+  CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
+  CPPUNIT_ASSERT_EQUAL(2, pm->getBlockLength());
 
   // case: payload size is wrong
   try {

+ 4 - 4
test/BtRejectMessageTest.cc

@@ -41,8 +41,8 @@ public:
       this->slot = slot;
     }
 
-    virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin,
-                                              size_t length) {
+    virtual RequestSlot getOutstandingRequest
+    (size_t index, int32_t begin, int32_t length) {
       if(slot.getIndex() == index && slot.getBegin() == begin &&
          slot.getLength() == length) {
         return slot;
@@ -93,8 +93,8 @@ void BtRejectMessageTest::testCreate() {
   SharedHandle<BtRejectMessage> pm = BtRejectMessage::create(&msg[4], 13);
   CPPUNIT_ASSERT_EQUAL((uint8_t)16, pm->getId());
   CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
-  CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin());
-  CPPUNIT_ASSERT_EQUAL((size_t)1024, pm->getLength());
+  CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
+  CPPUNIT_ASSERT_EQUAL(1024, pm->getLength());
 
   // case: payload size is wrong
   try {

+ 4 - 4
test/BtRequestMessageTest.cc

@@ -79,14 +79,14 @@ public:
   class MockBtMessageFactory2 : public MockBtMessageFactory {
   public:
     virtual SharedHandle<BtMessage>
-    createPieceMessage(size_t index, uint32_t begin, size_t length) {
+    createPieceMessage(size_t index, int32_t begin, int32_t length) {
       SharedHandle<MockBtMessage2> btMsg
         (new MockBtMessage2("piece", index, begin, length));
       return btMsg;
     }
 
     virtual SharedHandle<BtMessage>
-    createRejectMessage(size_t index, uint32_t begin, size_t length) {
+    createRejectMessage(size_t index, int32_t begin, int32_t length) {
       SharedHandle<MockBtMessage2> btMsg
         (new MockBtMessage2("reject", index, begin, length));
       return btMsg;
@@ -135,8 +135,8 @@ void BtRequestMessageTest::testCreate() {
   SharedHandle<BtRequestMessage> pm = BtRequestMessage::create(&msg[4], 13);
   CPPUNIT_ASSERT_EQUAL((uint8_t)6, pm->getId());
   CPPUNIT_ASSERT_EQUAL((size_t)12345, pm->getIndex());
-  CPPUNIT_ASSERT_EQUAL((uint32_t)256, pm->getBegin());
-  CPPUNIT_ASSERT_EQUAL((size_t)1024, pm->getLength());
+  CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
+  CPPUNIT_ASSERT_EQUAL(1024, pm->getLength());
 
   // case: payload size is wrong
   try {

+ 1 - 1
test/DefaultBtMessageDispatcherTest.cc

@@ -127,7 +127,7 @@ public:
   class MockBtMessageFactory2 : public MockBtMessageFactory {
   public:
     virtual SharedHandle<BtMessage>
-    createCancelMessage(size_t index, uint32_t begin, size_t length) {
+    createCancelMessage(size_t index, int32_t begin, int32_t length) {
       SharedHandle<MockBtMessage2> btMsg(new MockBtMessage2());
       btMsg->type = "cancel";
       return btMsg;

+ 4 - 2
test/MockBtMessageDispatcher.h

@@ -28,7 +28,8 @@ public:
 
   virtual void sendMessages() {}
 
-  virtual void doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length) {}
+  virtual void doCancelSendingPieceAction
+  (size_t index, int32_t begin, int32_t length) {}
 
   virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece) {}
 
@@ -56,7 +57,8 @@ public:
     return false;
   }
 
-  virtual RequestSlot getOutstandingRequest(size_t index, uint32_t begin, size_t length) {
+  virtual RequestSlot getOutstandingRequest
+  (size_t index, int32_t begin, int32_t length) {
     return RequestSlot::nullSlot;
   }
 

+ 3 - 3
test/MockBtMessageFactory.h

@@ -35,12 +35,12 @@ public:
   }
 
   virtual SharedHandle<BtMessage>
-  createCancelMessage(size_t index, uint32_t begin, size_t length) {
+  createCancelMessage(size_t index, int32_t begin, int32_t length) {
     return SharedHandle<BtMessage>();
   }
 
   virtual SharedHandle<BtMessage>
-  createPieceMessage(size_t index, uint32_t begin, size_t length) {
+  createPieceMessage(size_t index, int32_t begin, int32_t length) {
     return SharedHandle<BtMessage>();
   }
 
@@ -81,7 +81,7 @@ public:
   }
 
   virtual SharedHandle<BtMessage>
-  createRejectMessage(size_t index, uint32_t begin, size_t length) {
+  createRejectMessage(size_t index, int32_t begin, int32_t length) {
     return SharedHandle<BtMessage>();
   }