DTLS handshake retransmission
authorAndrii Shtompel <a.shtompel@samsung.com>
Thu, 17 Dec 2015 08:51:37 +0000 (10:51 +0200)
committerSachin Agrawal <sachin.agrawal@intel.com>
Thu, 24 Dec 2015 18:47:07 +0000 (18:47 +0000)
DTLS retransmission initiated after dtls context successfully created.
After that it starts each 2 seconds (using Timer) and call dtls_check_retransmission()
It stops when global dtls session was destroyed

Change-Id: Idc2216a4773feea44a306fcee78b8c779b595abe
Signed-off-by: Andrii Shtompel <a.shtompel@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4647
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
Reviewed-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-by: sangsu choi <sangsu.choi@samsung.com>
Reviewed-by: Ivan Pazderskyy <i.pazderskyy@samsung.com>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
extlibs/timer/SConscript [new file with mode: 0644]
resource/csdk/connectivity/build/tizen/gbsbuild.sh
resource/csdk/connectivity/samples/linux/SConscript
resource/csdk/connectivity/src/SConscript
resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c

diff --git a/extlibs/timer/SConscript b/extlibs/timer/SConscript
new file mode 100644 (file)
index 0000000..edcc7ef
--- /dev/null
@@ -0,0 +1,28 @@
+# *****************************************************************
+#
+#  Copyright 2015 Samsung Electronics All Rights Reserved.
+#
+#
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+# *****************************************************************/
+
+Import('env')
+env.AppendUnique(TIMER_SRC = 'timer.c')
+
+libtimer = env.StaticLibrary('libtimer', env.get('TIMER_SRC'), OBJPREFIX='libtimer_')
+env.InstallTarget(libtimer, 'libtimer');
+
+
+
index 6ab0e87..5c61d0e 100755 (executable)
@@ -56,6 +56,7 @@ mkdir -p $sourcedir/tmp/con/sample/external/inc
 cp -R $cur_dir/external/inc/* $sourcedir/tmp/con/sample/external/inc/
 mkdir -p $sourcedir/tmp/con/extlibs/
 cp -R ./extlibs/tinydtls/ $sourcedir/tmp/con/extlibs/
+cp -R ./extlibs/timer/ $sourcedir/tmp/con/extlibs/
 mkdir -p $sourcedir/tmp/con/c_common
 cp -R ./resource/c_common/* $sourcedir/tmp/con/c_common/
 
index 71c7388..68f4f16 100644 (file)
@@ -53,7 +53,7 @@ if ca_os not in ['darwin']:
 if secured == '1':
        current_dir=env.get('SRC_DIR')
        sample_env.AppendUnique(CPPPATH = [root_dir + 'external/inc/'])
-       sample_env.AppendUnique(LIBS = ['tinydtls'])
+       sample_env.AppendUnique(LIBS = ['timer','tinydtls'])
        casample =sample_env.Program('casample', [sample_src])
 else:
        casample =sample_env.Program('casample', [sample_src])
index ec68e29..9b21749 100755 (executable)
@@ -45,6 +45,12 @@ if env.get('SECURED') == '1':
                env.SConscript(os.path.join(root_dir, 'extlibs/tinydtls/SConscript'))
        else:
                env.SConscript('#extlibs/tinydtls/SConscript')
+       if ca_os == 'tizen' and os.path.exists(root_dir + '/extlibs/timer'):
+               env.SConscript(os.path.join(root_dir, 'extlibs/timer/SConscript'))
+               env.AppendUnique(CPPPATH = [os.path.join(root_dir, 'extlibs/timer')])
+       else:
+               env.SConscript('#extlibs/timer/SConscript')
+               env.AppendUnique(CPPPATH = ['#extlibs/timer'])
 
 env.AppendUnique(CA_SRC = [os.path.join(ca_path,
                                         'adapter_util/caadapterutils.c')])
@@ -136,6 +142,7 @@ if ca_os in ['android', 'tizen']:
        env.AppendUnique(LIBS = ['coap'])
        if env.get('SECURED') == '1':
                env.AppendUnique(LIBS = ['tinydtls'])
+               env.AppendUnique(LIBS = ['timer'])
        if ca_os != 'android':
                env.AppendUnique(LIBS = ['rt'])
        calib = env.SharedLibrary('connectivity_abstraction', env.get('CA_SRC'))
index 36d7b75..970c150 100644 (file)
@@ -24,6 +24,7 @@
 #include "oic_malloc.h"
 #include "oic_string.h"
 #include "global.h"
+#include "timer.h"
 #include <netdb.h>
 
 #ifdef __WITH_X509__
@@ -65,6 +66,12 @@ static ca_mutex g_dtlsContextMutex = NULL;
 static CAGetDTLSPskCredentialsHandler g_getCredentialsCallback = NULL;
 
 /**
+ * @var MAX_RETRANSMISSION_TIME
+ * @brief Maximum timeout value (in seconds) to start DTLS retransmission.
+ */
+#define MAX_RETRANSMISSION_TIME 1
+
+/**
  * @var g_dtlsHandshakeCallback
  * @brief callback to deliver the DTLS handshake result
  */
@@ -992,6 +999,48 @@ exit:
 
 #endif
 
+static void CAStartRetransmit()
+{
+    static int timerId = -1;
+    clock_time_t nextSchedule = MAX_RETRANSMISSION_TIME;
+
+    OIC_LOG(DEBUG, NET_DTLS_TAG, "CAStartRetransmit IN");
+
+    if (timerId != -1)
+    {
+        //clear previous timer
+        unregisterTimer(timerId);
+
+        ca_mutex_lock(g_dtlsContextMutex);
+
+        //stop retransmission if context is invalid
+        if(NULL == g_caDtlsContext)
+        {
+            OIC_LOG(ERROR, NET_DTLS_TAG, "Context is NULL. Stop retransmission");
+            ca_mutex_unlock(g_dtlsContextMutex);
+            return;
+        }
+
+        OIC_LOG(DEBUG, NET_DTLS_TAG, "Check retransmission");
+        dtls_check_retransmit(g_caDtlsContext->dtlsContext, &nextSchedule);
+        ca_mutex_unlock(g_dtlsContextMutex);
+
+        //re-transmission timeout should not be greater then max one
+        //this will cover case when several clients start dtls sessions
+        nextSchedule /= CLOCKS_PER_SEC;
+        if (nextSchedule > MAX_RETRANSMISSION_TIME)
+        {
+            nextSchedule = MAX_RETRANSMISSION_TIME;
+        }
+    }
+
+    //start new timer
+    OIC_LOG(DEBUG, NET_DTLS_TAG, "Start new timer");
+    registerTimer(nextSchedule, &timerId, CAStartRetransmit);
+
+    OIC_LOG(DEBUG, NET_DTLS_TAG, "CAStartRetransmit OUT");
+}
+
 CAResult_t CAAdapterNetDtlsInit()
 {
     OIC_LOG(DEBUG, NET_DTLS_TAG, "IN");
@@ -1066,6 +1115,9 @@ CAResult_t CAAdapterNetDtlsInit()
 #endif //__WITH_X509__*
     dtls_set_handler(g_caDtlsContext->dtlsContext, &(g_caDtlsContext->callbacks));
     ca_mutex_unlock(g_dtlsContextMutex);
+
+    CAStartRetransmit();
+
     OIC_LOG(DEBUG, NET_DTLS_TAG, "OUT");
     return CA_STATUS_OK;
 }