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>
--- /dev/null
+# *****************************************************************
+#
+# 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');
+
+
+
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/
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])
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')])
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'))
#include "oic_malloc.h"
#include "oic_string.h"
#include "global.h"
+#include "timer.h"
#include <netdb.h>
#ifdef __WITH_X509__
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
*/
#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");
#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;
}