[IOT-1371] Use both addr and port to identify the endpoint of the
authorTodd Malsbary <todd.malsbary@intel.com>
Wed, 28 Sep 2016 21:35:18 +0000 (14:35 -0700)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 26 Oct 2016 07:34:57 +0000 (07:34 +0000)
block transfer data.

Change-Id: I11a378aa611adb6b1cbfe5eacd4e45f34f1a649f
Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12505
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/inc/cablockwisetransfer.h
resource/csdk/connectivity/src/cablockwisetransfer.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/test/cablocktransfertest.cpp

index 3a7f948..7aa81a0 100644 (file)
@@ -419,11 +419,12 @@ void CADestroyDataSet(CAData_t* data);
  * Create the blockId for CABlockData.
  * @param[in]   token   token of current message.
  * @param[in]   tokenLength   token length of current message.
+ * @param[in]   addr    address, must be MAX_ADDR_STR_SIZE_CA in length.
  * @param[in]   portNumber   port.
  * @return ID set of CABlockData.
  */
 CABlockDataID_t* CACreateBlockDatablockId(const CAToken_t token, uint8_t tokenLength,
-                                          uint16_t portNumber);
+                                          const char* addr, uint16_t portNumber);
 
 /**
  * Destroy the blockId set.
@@ -560,11 +561,12 @@ CAResult_t CARemoveAllBlockDataFromList();
  * Find the block data with seed info and remove it from block-wise transfer list.
  * @param[in]   token         token of the message.
  * @param[in]   tokenLength   token length of the message.
+ * @param[in]   addr          address, must be MAX_ADDR_STR_SIZE_CA in length.
  * @param[in]   portNumber    port.
  * @return ::CASTATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
 CAResult_t CARemoveBlockDataFromListWithSeed(const CAToken_t token, uint8_t tokenLength,
-                                             uint16_t portNumber);
+                                             const char* addr, uint16_t portNumber);
 
 #ifdef __cplusplus
 } /* extern "C" */
index 76f8ca4..d1b901d 100644 (file)
@@ -331,7 +331,7 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
         CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
                 receivedData->responseInfo->info.token,
                 receivedData->responseInfo->info.tokenLength,
-                endpoint->port);
+                endpoint->addr, endpoint->port);
         if (NULL == blockDataID || blockDataID->idLength < 1)
         {
             // if retransmission is timeout, callback msg will be send without token.
@@ -394,7 +394,7 @@ CAResult_t CAReceiveBlockWiseData(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
         CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
                 (CAToken_t)pdu->transport_hdr->udp.token,
                 pdu->transport_hdr->udp.token_length,
-                endpoint->port);
+                endpoint->addr, endpoint->port);
         if (NULL == blockDataID || blockDataID->idLength < 1)
         {
             OIC_LOG(ERROR, TAG, "blockId is null");
@@ -870,7 +870,7 @@ CAResult_t CASetNextBlockOption1(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
             (CAToken_t)pdu->transport_hdr->udp.token,
             pdu->transport_hdr->udp.token_length,
-            endpoint->port);
+            endpoint->addr, endpoint->port);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
         OIC_LOG(ERROR, TAG, "blockId is null");
@@ -1013,7 +1013,7 @@ CAResult_t CASetNextBlockOption2(coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
             (CAToken_t)pdu->transport_hdr->udp.token,
             pdu->transport_hdr->udp.token_length,
-            endpoint->port);
+            endpoint->addr, endpoint->port);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
         OIC_LOG(ERROR, TAG, "blockId is null");
@@ -1400,7 +1400,7 @@ CAResult_t CAAddBlockOption(coap_pdu_t **pdu, const CAInfo_t *info,
     CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
             (CAToken_t)(*pdu)->transport_hdr->udp.token,
             (*pdu)->transport_hdr->udp.token_length,
-            endpoint->port);
+            endpoint->addr, endpoint->port);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
         OIC_LOG(ERROR, TAG, "blockId is null");
@@ -2357,7 +2357,7 @@ CAResult_t CACheckBlockDataValidation(const CAData_t *sendData, CABlockData_t **
         CABlockDataID_t* blockDataID = CACreateBlockDatablockId(
                 (CAToken_t)sendData->responseInfo->info.token,
                 sendData->responseInfo->info.tokenLength,
-                sendData->remoteEndpoint->port);
+                sendData->remoteEndpoint->addr, sendData->remoteEndpoint->port);
         if (NULL == blockDataID || blockDataID->idLength < 1)
         {
             OIC_LOG(ERROR, TAG, "blockId is null");
@@ -2510,6 +2510,7 @@ CABlockData_t *CACreateNewBlockData(const CAData_t *sendData)
     }
 
     CABlockDataID_t* blockDataID = CACreateBlockDatablockId(token, tokenLength,
+                                                            data->sentData->remoteEndpoint->addr,
                                                             data->sentData->remoteEndpoint->port);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
@@ -2612,8 +2613,9 @@ void CADestroyDataSet(CAData_t* data)
 }
 
 CABlockDataID_t* CACreateBlockDatablockId(const CAToken_t token, uint8_t tokenLength,
-                                          uint16_t portNumber)
+                                          const char* addr, uint16_t portNumber)
 {
+    size_t addrLength = strlen(addr);
     char port[PORT_LENGTH] = { 0, };
     port[0] = (char) ((portNumber >> 8) & 0xFF);
     port[1] = (char) (portNumber & 0xFF);
@@ -2624,7 +2626,7 @@ CABlockDataID_t* CACreateBlockDatablockId(const CAToken_t token, uint8_t tokenLe
         OIC_LOG(ERROR, TAG, "memory alloc has failed");
         return NULL;
     }
-    blockDataID->idLength = tokenLength + sizeof(port);
+    blockDataID->idLength = tokenLength + sizeof(port) + addrLength;
     blockDataID->id = (uint8_t *) OICMalloc(blockDataID->idLength);
     if (!blockDataID->id)
     {
@@ -2639,6 +2641,7 @@ CABlockDataID_t* CACreateBlockDatablockId(const CAToken_t token, uint8_t tokenLe
     }
 
     memcpy(blockDataID->id + tokenLength, port, sizeof(port));
+    memcpy(blockDataID->id + tokenLength + sizeof(port), addr, addrLength);
 
     OIC_LOG(DEBUG, TAG, "BlockID is ");
     OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *)blockDataID->id, blockDataID->idLength);
@@ -2684,9 +2687,9 @@ void CALogBlockInfo(coap_block_t *block)
 }
 
 CAResult_t CARemoveBlockDataFromListWithSeed(const CAToken_t token, uint8_t tokenLength,
-                                             uint16_t portNumber)
+                                             const char* addr, uint16_t portNumber)
 {
-    CABlockDataID_t* blockDataID = CACreateBlockDatablockId(token, tokenLength, portNumber);
+    CABlockDataID_t* blockDataID = CACreateBlockDatablockId(token, tokenLength, addr, portNumber);
     if (NULL == blockDataID || blockDataID->idLength < 1)
     {
         OIC_LOG(ERROR, TAG, "blockId is null");
index 8d86b1d..c330d59 100644 (file)
@@ -307,7 +307,7 @@ static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uin
     if (CAIsSupportedBlockwiseTransfer(endpoint->adapter))
     {
         res = CARemoveBlockDataFromListWithSeed(resInfo->info.token, resInfo->info.tokenLength,
-                                                endpoint->port);
+                                                endpoint->addr, endpoint->port);
         if (CA_STATUS_OK != res)
         {
             OIC_LOG(ERROR, TAG, "CARemoveBlockDataFromListWithSeed failed");
index 040c7e0..6540348 100644 (file)
@@ -132,7 +132,9 @@ TEST_F(CABlockTransferTests, CARemoveBlockDataFromListWithSeed)
     if (currData)
     {
         EXPECT_EQ(CA_STATUS_OK, CARemoveBlockDataFromListWithSeed(tempToken,
-                                                                  CA_MAX_TOKEN_LEN, 5683));
+                                                                  CA_MAX_TOKEN_LEN,
+                                                                  tempRep->addr,
+                                                                  tempRep->port));
     }
 
     CADestroyDataSet(cadata);