Commit 362ae097 authored by johan's avatar johan

Add the reset retransmission timer function to the API

- and fix retransmission timer increment to maximum value
parent ab83c1a8
......@@ -209,6 +209,18 @@ __attribute__ ((visibility ("default"))) void bzrtp_SASVerified(bzrtpContext_t *
*/
__attribute__ ((visibility ("default"))) void bzrtp_resetSASVerified(bzrtpContext_t *zrtpContext);
/**
* @brief Reset the retransmission timer of a given channel.
* Packets will be sent again if appropriate:
* - when in responder role, zrtp engine only answer to packets sent by the initiator.
* - if we are still in discovery phase, Hello or Commit packets will be resent.
*
* @param[in/out] zrtpContext The ZRTP context we're dealing with
* @param[in] selfSSRC The SSRC identifying the channel to reset
*
* return 0 on success, error code otherwise
*/
__attribute__ ((visibility ("default"))) int bzrtp_resetRetransmissionTimer(bzrtpContext_t *zrtpContext, uint32_t selfSSRC);
#define BZRTP_CUSTOMCACHE_USEKDF 1
#define BZRTP_CUSTOMCACHE_PLAINDATA 0
......
......@@ -70,7 +70,7 @@ typedef struct bzrtpTimer_struct {
uint8_t status; /**< Status is BZRTP_TIMER_ON or BZRTP_TIMER_OFF */
uint64_t firingTime; /**< in ms. The timer will fire if currentTime >= firingTime */
uint8_t firingCount; /**< Timer is used to resend packets, count the number of times a packet has been resent */
uint8_t timerStep; /**< in ms. Step between next timer fire: used to reset firingTime for next timer fire */
int timerStep; /**< in ms. Step between next timer fire: used to reset firingTime for next timer fire */
} bzrtpTimer_t;
/* the rs1 and rs2 are 256 bits long - see rfc section 4.6.1 */
......
......@@ -336,7 +336,9 @@ int bzrtp_iterate(bzrtpContext_t *zrtpContext, uint32_t selfSSRC, uint64_t timeR
timerEvent.zrtpChannelContext = zrtpChannelContext;
/* send it to the state machine*/
return zrtpChannelContext->stateMachine(timerEvent);
if (zrtpChannelContext->stateMachine != NULL) {
return zrtpChannelContext->stateMachine(timerEvent);
}
}
}
......@@ -531,6 +533,41 @@ int bzrtp_addCustomDataInCache(bzrtpContext_t *zrtpContext, uint8_t peerZID[12],
}
}
/*
* @brief Reset the retransmission timer of a given channel.
* Packets will be sent again if appropriate:
* - when in responder role, zrtp engine only answer to packets sent by the initiator.
* - if we are still in discovery phase, Hello or Commit packets will be resent.
*
* @param[in/out] zrtpContext The ZRTP context we're dealing with
* @param[in] selfSSRC The SSRC identifying the channel to reset
*
* return 0 on success, error code otherwise
*/
int bzrtp_resetRetransmissionTimer(bzrtpContext_t *zrtpContext, uint32_t selfSSRC) {
/* get channel context */
bzrtpChannelContext_t *zrtpChannelContext = getChannelContext(zrtpContext, selfSSRC);
if (zrtpChannelContext == NULL) {
return BZRTP_ERROR_INVALIDCONTEXT;
}
/* reset timer only when not in secure mode yet and for initiator(engine start as initiator so if we call this function in discovery phase, it will reset the timer */
if ((zrtpContext->isSecure == 0) && (zrtpChannelContext->role == INITIATOR)) {
zrtpChannelContext->timer.status = BZRTP_TIMER_ON;
zrtpChannelContext->timer.firingTime = 0; /* be sure it will trigger at next call to bzrtp_iterate*/
zrtpChannelContext->timer.firingCount = -1; /* -1 to count the initial packet and then retransmit the regular number of packets */
/* reset timerStep to the base value */
if ((zrtpChannelContext->timer.timerStep % NON_HELLO_BASE_RETRANSMISSION_STEP) == 0) {
zrtpChannelContext->timer.timerStep = NON_HELLO_BASE_RETRANSMISSION_STEP;
} else {
zrtpChannelContext->timer.timerStep = HELLO_BASE_RETRANSMISSION_STEP;
}
}
return 0;
}
/* Local functions implementation */
/**
......@@ -580,6 +617,7 @@ int bzrtp_initChannelContext(bzrtpContext_t *zrtpContext, bzrtpChannelContext_t
/* timer is off */
zrtpChannelContext->timer.status = BZRTP_TIMER_OFF;
zrtpChannelContext->timer.timerStep = HELLO_BASE_RETRANSMISSION_STEP; /* we must initialise the timeStep just in case the resettimer function is called between init and start */
zrtpChannelContext->selfSSRC = selfSSRC;
......
......@@ -145,8 +145,8 @@ int state_discovery_init(bzrtpEvent_t event) {
if (event.eventType == BZRTP_EVENT_TIMER) {
/* adjust timer for next time : check we didn't reach the max retransmissions adjust the step(double it until reaching the cap) */
if (zrtpChannelContext->timer.firingCount<HELLO_MAX_RETRANSMISSION_NUMBER + 1) {
if (2*zrtpChannelContext->timer.timerStep<HELLO_CAP_RETRANSMISSION_STEP) {
if (zrtpChannelContext->timer.firingCount<=HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<=HELLO_CAP_RETRANSMISSION_STEP) {
zrtpChannelContext->timer.timerStep *= 2;
}
zrtpChannelContext->timer.firingTime = zrtpContext->timeReference + zrtpChannelContext->timer.timerStep;
......@@ -354,8 +354,8 @@ int state_discovery_waitingForHelloAck(bzrtpEvent_t event) {
if (event.eventType == BZRTP_EVENT_TIMER) {
/* adjust timer for next time : check we didn't reach the max retransmissions adjust the step(double it until reaching the cap) */
if (zrtpChannelContext->timer.firingCount<HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<HELLO_CAP_RETRANSMISSION_STEP) {
if (zrtpChannelContext->timer.firingCount<=HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<=HELLO_CAP_RETRANSMISSION_STEP) {
zrtpChannelContext->timer.timerStep *= 2;
}
zrtpChannelContext->timer.firingTime = zrtpContext->timeReference + zrtpChannelContext->timer.timerStep;
......@@ -622,8 +622,8 @@ int state_keyAgreement_sendingCommit(bzrtpEvent_t event) {
if (event.eventType == BZRTP_EVENT_TIMER) {
/* adjust timer for next time : check we didn't reach the max retransmissions adjust the step(double it until reaching the cap) */
if (zrtpChannelContext->timer.firingCount<NON_HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<NON_HELLO_CAP_RETRANSMISSION_STEP) {
if (zrtpChannelContext->timer.firingCount<=NON_HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<=NON_HELLO_CAP_RETRANSMISSION_STEP) {
zrtpChannelContext->timer.timerStep *= 2;
}
zrtpChannelContext->timer.firingTime = zrtpContext->timeReference + zrtpChannelContext->timer.timerStep;
......@@ -926,8 +926,8 @@ int state_keyAgreement_initiatorSendingDHPart2(bzrtpEvent_t event) {
if (event.eventType == BZRTP_EVENT_TIMER) {
/* adjust timer for next time : check we didn't reach the max retransmissions adjust the step(double it until reaching the cap) */
if (zrtpChannelContext->timer.firingCount<NON_HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<NON_HELLO_CAP_RETRANSMISSION_STEP) {
if (zrtpChannelContext->timer.firingCount<=NON_HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<=NON_HELLO_CAP_RETRANSMISSION_STEP) {
zrtpChannelContext->timer.timerStep *= 2;
}
zrtpChannelContext->timer.firingTime = zrtpContext->timeReference + zrtpChannelContext->timer.timerStep;
......@@ -1313,8 +1313,8 @@ int state_confirmation_initiatorSendingConfirm2(bzrtpEvent_t event) {
if (event.eventType == BZRTP_EVENT_TIMER) {
/* adjust timer for next time : check we didn't reach the max retransmissions adjust the step(double it until reaching the cap) */
if (zrtpChannelContext->timer.firingCount<NON_HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<NON_HELLO_CAP_RETRANSMISSION_STEP) {
if (zrtpChannelContext->timer.firingCount<=NON_HELLO_MAX_RETRANSMISSION_NUMBER) {
if (2*zrtpChannelContext->timer.timerStep<=NON_HELLO_CAP_RETRANSMISSION_STEP) {
zrtpChannelContext->timer.timerStep *= 2;
}
zrtpChannelContext->timer.firingTime = zrtpContext->timeReference + zrtpChannelContext->timer.timerStep;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment