Commit d5389594 authored by johan's avatar johan

Update ZRTP API to use stream sessions and not MediaStream

Can't rely on MediaStream which may be killed while stream sessions is kept
+ code cleaning and comments
parent 3e0ee98f
......@@ -28,7 +28,7 @@ extern "C"{
#endif
/* defined in mediastream.h */
struct _MediaStream;
struct _MSMediaStreamSessions;
typedef struct MSZrtpParams {
const char *zid_file; // File where to store secrets and other information
......@@ -37,29 +37,53 @@ typedef struct MSZrtpParams {
typedef struct _MSZrtpContext MSZrtpContext ;
/**
* check if ZRTP is available
* @return TRUE if it is available, FALSE if not
*/
MS2_PUBLIC bool_t ms_zrtp_available(void);
/**
* @deprecated Use ms_zrtp_transport_modifier_new() instead. Using #srtp_transport_new will prevent usage of multiple
* encryptions and/or custom packets transmission.
*/
MS2_PUBLIC MSZrtpContext* ms_zrtp_context_new(struct _MediaStream *stream, RtpSession *s, MSZrtpParams *params);
* Create an initialise a ZRTP context
* @param[in] stream_sessions A link to the stream sessions structures, used to get rtp session to add transport modifier and needed to set SRTP sessions when keys are ready
* @param[in] params ZID cache filename and peer sip uri
* @return a pointer to the opaque context structure needed by MSZRTP
*/
MS2_PUBLIC MSZrtpContext* ms_zrtp_context_new(struct _MSMediaStreamSessions *stream_sessions, MSZrtpParams *params);
/**
* Create an initialise a ZRTP context on a channel when a ZRTP exchange was already performed on an other one
* @param[in] stream_sessions A link to the stream sessions structures, used to get rtp session to add transport modifier and needed to set SRTP sessions when keys are ready
* @param[in] activeContext The MSZRTP context of the already active session, used to pass to lib bzrtp its own context which shall remain unique.
* @param[in] params ZID cache filename and peer sip uri
* @return a pointer to the opaque context structure needed by MSZRTP
*/
MS2_PUBLIC MSZrtpContext* ms_zrtp_multistream_new(struct _MSMediaStreamSessions *stream_sessions, MSZrtpContext* activeContext, MSZrtpParams *params);
/**
* Free ressources used by ZRTP context
* it will also free the libbzrtp context if no more channel are active
* @param[in/out] context the opaque MSZRTP context
*/
MS2_PUBLIC void ms_zrtp_context_destroy(MSZrtpContext *ctx);
/**
* can be used to give more time for establishing zrtp session
* @param[in] ctx The MSZRTP context
* */
MS2_PUBLIC void ms_zrtp_reset_transmition_timer(MSZrtpContext* ctx, RtpSession *s);
MS2_PUBLIC MSZrtpContext* ms_zrtp_multistream_new(struct _MediaStream *stream, MSZrtpContext* activeContext, RtpSession *s, MSZrtpParams *params);
MS2_PUBLIC void ms_zrtp_reset_transmition_timer(MSZrtpContext* ctx);
/**
* Tell the MSZRTP context that SAS was controlled by user, it will trigger a ZID cache update
* @param[in] ctx MSZRTP context, used to retrieve cache and update it
*/
MS2_PUBLIC void ms_zrtp_sas_verified(MSZrtpContext* ctx);
MS2_PUBLIC void ms_zrtp_sas_reset_verified(MSZrtpContext* ctx);
MS2_PUBLIC int ms_zrtp_transport_modifier_new(MSZrtpContext* ctx, RtpTransportModifier **rtpt, RtpTransportModifier **rtcpt );
MS2_PUBLIC void ms_zrtp_transport_modifier_destroy(RtpTransportModifier *tp);
/**
* Tell the MSZRTP context that user have requested the SAS verified status to be reseted, it will trigger a ZID cache update
* @param[in] ctx MSZRTP context, used to retrieve cache and update it
*/
MS2_PUBLIC void ms_zrtp_sas_reset_verified(MSZrtpContext* ctx);
#ifdef __cplusplus
}
......
......@@ -1112,6 +1112,9 @@ AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *session
stream->ms.type = MSAudio;
stream->ms.sessions=*sessions;
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions));
}
if (sessions->dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(sessions->dtls_context, &(stream->ms.sessions));
}
......@@ -1352,9 +1355,9 @@ float audio_stream_get_average_lq_quality_rating(AudioStream *stream) {
void audio_stream_enable_zrtp(AudioStream *stream, MSZrtpParams *params){
if (stream->ms.sessions.zrtp_context==NULL)
stream->ms.sessions.zrtp_context=ms_zrtp_context_new((MediaStream *)stream, stream->ms.sessions.rtp_session, params);
stream->ms.sessions.zrtp_context=ms_zrtp_context_new( &(stream->ms.sessions), params);
else if (!stream->ms.sessions.is_secured)
ms_zrtp_reset_transmition_timer(stream->ms.sessions.zrtp_context,stream->ms.sessions.rtp_session);
ms_zrtp_reset_transmition_timer(stream->ms.sessions.zrtp_context);
}
bool_t audio_stream_zrtp_enabled(const AudioStream *stream) {
......
......@@ -103,6 +103,12 @@ MS2_PUBLIC void ms_srtp_shutdown(void);
* @param[in] stream_sessions Pointer to the new stream session structure
*/
MS2_PUBLIC void ms_dtls_srtp_set_stream_sessions(MSDtlsSrtpContext *dtls_context, MSMediaStreamSessions *stream_sessions);
/**
* Set the backlink in zrtp_context to stream sessions context. Used when reinvite force creation of a new stream with same session data
* @param[in/out] zrtp_context ZRTP context, contains a link to stream session context needed to access srtp context
* @param[in] stream_sessions Pointer to the new stream session structure
*/
MS2_PUBLIC void ms_zrtp_set_stream_sessions(MSZrtpContext *zrtp_context, MSMediaStreamSessions *stream_sessions);
#ifdef __cplusplus
}
#endif
......
......@@ -253,6 +253,9 @@ VideoStream *video_stream_new_with_sessions(const MSMediaStreamSessions *session
stream->ms.type = MSVideo;
stream->ms.sessions=*sessions;
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions));
}
if (sessions->dtls_context != NULL) {
ms_dtls_srtp_set_stream_sessions(sessions->dtls_context, &(stream->ms.sessions));
}
......@@ -1259,9 +1262,9 @@ void video_stream_send_only_stop(VideoStream *vs){
/* enable ZRTP on the video stream using information from the audio stream */
void video_stream_enable_zrtp(VideoStream *vstream, AudioStream *astream, MSZrtpParams *param){
if (astream->ms.sessions.zrtp_context != NULL && vstream->ms.sessions.zrtp_context == NULL) {
vstream->ms.sessions.zrtp_context=ms_zrtp_multistream_new((MediaStream *)vstream, astream->ms.sessions.zrtp_context, vstream->ms.sessions.rtp_session, param);
vstream->ms.sessions.zrtp_context=ms_zrtp_multistream_new(&(vstream->ms.sessions), astream->ms.sessions.zrtp_context, param);
} else if (vstream->ms.sessions.zrtp_context && !vstream->ms.sessions.is_secured)
ms_zrtp_reset_transmition_timer(vstream->ms.sessions.zrtp_context,vstream->ms.sessions.rtp_session);
ms_zrtp_reset_transmition_timer(vstream->ms.sessions.zrtp_context);
}
void video_stream_enable_dtls(VideoStream *stream, MSDtlsSrtpParams *params){
......
This diff is collapsed.
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