Commit aa734546 authored by Ghislain MARY's avatar Ghislain MARY

Implement TURN deallocation when an ICE session is destroyed.

parent 5c9ad0e1
......@@ -136,14 +136,11 @@ typedef struct _IceStunServerCheckTransaction {
} IceStunServerCheckTransaction;
typedef struct _IceStunServerCheck {
struct _IceCheckList *cl;
RtpTransport *rtptp;
MSTurnContext *turn_context;
int srcport;
MSList *transactions; /**< List of IceStunServerCheckTransaction structures. */
char *realm;
char *nonce;
char *username;
char *password;
char *ha1;
MSTimeSpec next_transmission_time;
bool_t responded;
} IceStunServerCheck;
......@@ -219,6 +216,8 @@ typedef struct _IceTransaction {
*/
typedef struct _IceCheckList {
IceSession *session; /**< Pointer to the ICE session */
MSTurnContext *rtp_turn_context; /**< TURN context for RTP socket */
MSTurnContext *rtcp_turn_context; /**< TURN context for RTCP socket */
RtpSession *rtp_session; /**< Pointer to the RTP session associated with this ICE check list */
char *remote_ufrag; /**< Remote username fragment for this check list (provided via SDP by the peer) */
char *remote_pwd; /**< Remote password for this check list (provided via SDP by the peer) */
......
......@@ -154,6 +154,24 @@ typedef struct {
bool_t has_requested_transport;
} MSStunMessage;
typedef enum {
MS_TURN_CONTEXT_STATE_IDLE,
MS_TURN_CONTEXT_STATE_CREATING_ALLOCATION,
MS_TURN_CONTEXT_STATE_ALLOCATION_CREATED,
MS_TURN_CONTEXT_STATE_CREATING_PERMISSIONS,
MS_TURN_CONTEXT_STATE_RUNNING
} MSTurnContextState;
typedef struct {
char *realm;
char *nonce;
char *username;
char *password;
char *ha1;
uint32_t lifetime;
MSTurnContextState state;
} MSTurnContext;
#ifdef __cplusplus
extern "C"
......@@ -230,12 +248,30 @@ MS2_PUBLIC bool_t ms_stun_message_dummy_message_integrity_enabled(const MSStunMe
MS2_PUBLIC void ms_stun_message_enable_dummy_message_integrity(MSStunMessage *msg, bool_t enable);
MS2_PUBLIC MSStunMessage * ms_turn_allocate_request_create(void);
MS2_PUBLIC MSStunMessage * ms_turn_refresh_request_create(uint32_t lifetime);
MS2_PUBLIC bool_t ms_stun_message_has_requested_transport(const MSStunMessage *msg);
MS2_PUBLIC uint8_t ms_stun_message_get_requested_transport(const MSStunMessage *msg);
MS2_PUBLIC bool_t ms_stun_message_has_lifetime(const MSStunMessage *msg);
MS2_PUBLIC uint32_t ms_stun_message_get_lifetime(const MSStunMessage *msg);
MS2_PUBLIC void ms_stun_message_set_lifetime(MSStunMessage *msg, uint32_t lifetime);
MS2_PUBLIC MSTurnContext * ms_turn_context_create(void);
MS2_PUBLIC void ms_turn_context_destroy(MSTurnContext *context);
MS2_PUBLIC MSTurnContextState ms_turn_context_get_state(const MSTurnContext *context);
MS2_PUBLIC void ms_turn_context_set_state(MSTurnContext *context, MSTurnContextState state);
MS2_PUBLIC const char * ms_turn_context_get_realm(const MSTurnContext *context);
MS2_PUBLIC void ms_turn_context_set_realm(MSTurnContext *context, const char *realm);
MS2_PUBLIC const char * ms_turn_context_get_nonce(const MSTurnContext *context);
MS2_PUBLIC void ms_turn_context_set_nonce(MSTurnContext *context, const char *nonce);
MS2_PUBLIC const char * ms_turn_context_get_username(const MSTurnContext *context);
MS2_PUBLIC void ms_turn_context_set_username(MSTurnContext *context, const char *username);
MS2_PUBLIC const char * ms_turn_context_get_password(const MSTurnContext *context);
MS2_PUBLIC void ms_turn_context_set_password(MSTurnContext *context, const char *password);
MS2_PUBLIC const char * ms_turn_context_get_ha1(const MSTurnContext *context);
MS2_PUBLIC void ms_turn_context_set_ha1(MSTurnContext *context, const char *ha1);
MS2_PUBLIC uint32_t ms_turn_context_get_lifetime(const MSTurnContext *context);
MS2_PUBLIC void ms_turn_context_set_lifetime(MSTurnContext *context, uint32_t lifetime);
#ifdef __cplusplus
}
#endif
......
This diff is collapsed.
......@@ -257,6 +257,12 @@ static void encode_requested_transport(StunMessageEncoder *encoder, uint8_t requ
encode16(encoder, 0);
}
static void encode_lifetime(StunMessageEncoder *encoder, uint32_t lifetime) {
encode16(encoder, MS_TURN_ATTR_LIFETIME);
encode16(encoder, 4);
encode32(encoder, lifetime);
}
typedef struct {
const char *buffer;
......@@ -832,6 +838,7 @@ size_t ms_stun_message_encode(const MSStunMessage *msg, char **buf) {
stun_addr = ms_stun_message_get_xor_relayed_address(msg);
if (stun_addr != NULL) encode_addr(&encoder, MS_TURN_ATTR_XOR_RELAYED_ADDRESS, stun_addr);
if (ms_stun_message_has_requested_transport(msg)) encode_requested_transport(&encoder, ms_stun_message_get_requested_transport(msg));
if (ms_stun_message_has_lifetime(msg)) encode_lifetime(&encoder, ms_stun_message_get_lifetime(msg));
if (ms_stun_message_has_priority(msg)) encode_priority(&encoder, ms_stun_message_get_priority(msg));
if (ms_stun_message_use_candidate_enabled(msg)) encode_use_candidate(&encoder);
......@@ -1080,6 +1087,12 @@ MSStunMessage * ms_turn_allocate_request_create(void) {
return msg;
}
MSStunMessage * ms_turn_refresh_request_create(uint32_t lifetime) {
MSStunMessage *msg = ms_stun_message_create(MS_STUN_TYPE_REQUEST, MS_TURN_METHOD_REFRESH);
ms_stun_message_set_lifetime(msg, lifetime);
return msg;
}
bool_t ms_stun_message_has_requested_transport(const MSStunMessage *msg) {
return msg->has_requested_transport;
}
......@@ -1100,3 +1113,70 @@ void ms_stun_message_set_lifetime(MSStunMessage *msg, uint32_t lifetime) {
msg->lifetime = lifetime;
msg->has_lifetime = TRUE;
}
MSTurnContext * ms_turn_context_create(void) {
MSTurnContext *context = ms_new0(MSTurnContext, 1);
context->state = MS_TURN_CONTEXT_STATE_IDLE;
return context;
}
void ms_turn_context_destroy(MSTurnContext *context) {
ms_free(context);
}
MSTurnContextState ms_turn_context_get_state(const MSTurnContext *context) {
return context->state;
}
void ms_turn_context_set_state(MSTurnContext *context, MSTurnContextState state) {
context->state = state;
}
const char * ms_turn_context_get_realm(const MSTurnContext *context) {
return context->realm;
}
void ms_turn_context_set_realm(MSTurnContext *context, const char *realm) {
STUN_STR_SETTER(context->realm, realm);
}
const char * ms_turn_context_get_nonce(const MSTurnContext *context) {
return context->nonce;
}
void ms_turn_context_set_nonce(MSTurnContext *context, const char *nonce) {
STUN_STR_SETTER(context->nonce, nonce);
}
const char * ms_turn_context_get_username(const MSTurnContext *context) {
return context->username;
}
void ms_turn_context_set_username(MSTurnContext *context, const char *username) {
STUN_STR_SETTER(context->username, username);
}
const char * ms_turn_context_get_password(const MSTurnContext *context) {
return context->password;
}
void ms_turn_context_set_password(MSTurnContext *context, const char *password) {
STUN_STR_SETTER(context->password, password);
}
const char * ms_turn_context_get_ha1(const MSTurnContext *context) {
return context->ha1;
}
void ms_turn_context_set_ha1(MSTurnContext *context, const char *ha1) {
STUN_STR_SETTER(context->ha1, ha1);
}
uint32_t ms_turn_context_get_lifetime(const MSTurnContext *context) {
return context->lifetime;
}
void ms_turn_context_set_lifetime(MSTurnContext *context, uint32_t lifetime) {
context->lifetime = lifetime;
}
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