Fixed bug during CacheID generation in resource encapsulation.
authorAbhishek Pandey <abhi.siso@samsung.com>
Thu, 21 Jul 2016 10:00:11 +0000 (15:30 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Fri, 22 Jul 2016 04:43:59 +0000 (04:43 +0000)
On calling startCaching API [RCSRemoteResourceObject.h] for different resources
one after another it is generating the same CacheID.

If we call the API at 1 second delay it is working fine; but it's better to use
a more accurate random generator. OCGetRandom() function provided by CSDK
seems to be more accurate here as it seeds each byte separately.

In this patch we have replaced rand() call with OCGetRandom().
This solves the problem in our test environment and generates unique random
numbers each time which can be used as Cache IDs.

Change-Id: I52858d6b6d149ec23df39920d8a767dd08d67d69
Signed-off-by: Abhishek Pandey <abhi.siso@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9549
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Junghyun Oh <junghyun.oh@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
service/resource-encapsulation/src/resourceCache/src/DataCache.cpp

index 51b3536..e774d68 100644 (file)
@@ -31,6 +31,8 @@
 #include "RCSResourceAttributes.h"
 #include "ExpiryTimer.h"
 
+#include "ocrandom.h"
+
 namespace OIC
 {
     namespace Service
@@ -314,17 +316,15 @@ namespace OIC
         CacheID DataCache::generateCacheID()
         {
             CacheID retID = 0;
-            srand(time(NULL));
-
             while (1)
             {
                 if (findSubscriber(retID).first == 0 && retID != 0)
                 {
                     break;
                 }
-                retID = rand();
-            }
 
+                retID = OCGetRandom();
+            }
             return retID;
         }