/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
*
* This file is part of mediastreamer2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef ice_h
#define ice_h
#include
#include
#include
/**
* @file ice.h
* @brief mediastreamer2 ice.h include file
*
* This file provides the API to handle the ICE protocol defined in the RFC 5245.
*/
/**
* The maximum number of check lists in an ICE session.
*/
#define ICE_SESSION_MAX_CHECK_LISTS 8
/**
* ICE agent role.
*
* See the terminology in paragraph 3 of the RFC 5245 for more details.
*/
typedef enum {
IR_Controlling,
IR_Controlled
} IceRole;
/**
* ICE candidate type.
*
* See the terminology in paragraph 3 of the RFC 5245 for more details.
*/
typedef enum {
ICT_CandidateInvalid = -1,
ICT_HostCandidate,
ICT_ServerReflexiveCandidate,
ICT_PeerReflexiveCandidate,
ICT_RelayedCandidate,
ICT_CandidateTypeMax
} IceCandidateType;
/**
* ICE candidate pair state.
*
* See paragraph 5.7.4 ("Computing states") of RFC 5245 for more details.
*/
typedef enum {
ICP_Waiting,
ICP_InProgress,
ICP_Succeeded,
ICP_Failed,
ICP_Frozen
} IceCandidatePairState;
/**
* ICE check list state.
*
* See paragraph 5.7.4 ("Computing states") of RFC 5245 for more details.
*/
typedef enum {
ICL_Running,
ICL_Completed,
ICL_Failed
} IceCheckListState;
/**
* ICE session state.
*/
typedef enum {
IS_Stopped,
IS_Running,
IS_Completed,
IS_Failed
} IceSessionState;
struct _IceCheckList;
/**
* Structure representing an ICE session.
*/
typedef struct _IceSession {
struct _IceCheckList * streams[ICE_SESSION_MAX_CHECK_LISTS]; /**< Table of IceChecklist structure pointers. Each element represents a media stream */
MSStunAuthRequestedCb stun_auth_requested_cb; /**< Callback called when authentication is requested */
void *stun_auth_requested_userdata; /**< Userdata to pass to the STUN authentication requested callback */
char *local_ufrag; /**< Local username fragment for the session (assigned during the session creation) */
char *local_pwd; /**< Local password for the session (assigned during the session creation) */
char *remote_ufrag; /**< Remote username fragment for the session (provided via SDP by the peer) */
char *remote_pwd; /**< Remote password for the session (provided via SDP by the peer) */
IceRole role; /**< Role played by the agent for this session */
IceSessionState state; /**< State of the session */
uint64_t tie_breaker; /**< Random number used to resolve role conflicts (see paragraph 5.2 of the RFC 5245) */
int32_t ta; /**< Duration of timer for sending connectivity checks in ms */
int event_value; /** Value of the event to send */
MSTimeSpec event_time; /**< Time when an event must be sent */
struct sockaddr_storage ss; /**< STUN server address to use for the candidates gathering process */
socklen_t ss_len; /**< Length of the STUN server address to use for the candidates gathering process */
MSTimeSpec gathering_start_ts;
MSTimeSpec gathering_end_ts;
MSTimeSpec connectivity_checks_start_ts;
IceCandidateType default_types[ICT_CandidateTypeMax];
bool_t check_message_integrity; /*set to false for backward compatibility only*/
bool_t send_event; /**< Boolean value telling whether an event must be sent or not */
uint8_t max_connectivity_checks; /**< Configuration parameter to limit the number of connectivity checks performed by the agent (default is 100) */
uint8_t keepalive_timeout; /**< Configuration parameter to define the timeout between each keepalive packets (default is 15s) */
bool_t forced_relay; /**< Force use of relay by modifying the local and reflexive candidates */
bool_t turn_enabled; /**< TURN protocol enabled */
bool_t short_turn_refresh; /**< Short TURN refresh for tests */
} IceSession;
typedef struct _IceStunServerRequestTransaction {
UInt96 transactionID;
MSTimeSpec request_time;
MSTimeSpec response_time;
} IceStunServerRequestTransaction;
typedef struct _IceStunServerRequest {
struct _IceCheckList *cl;
RtpTransport *rtptp;
MSTurnContext *turn_context;
struct addrinfo *source_ai;
MSList *transactions; /**< List of IceStunServerRequestTransaction structures. */
MSTimeSpec next_transmission_time;
MSStunAddress peer_address;
uint16_t channel_number;
uint16_t stun_method;
uint8_t requested_address_family;
bool_t gathering;
bool_t responded;
bool_t to_remove;
} IceStunServerRequest;
typedef struct _IceStunRequestRoundTripTime {
int nb_responses;
int sum;
} IceStunRequestRoundTripTime;
/**
* Structure representing an ICE transport address.
*/
typedef struct _IceTransportAddress {
char ip[64];
int port;
int family;
// TODO: Handling of transport type: TCP, UDP...
} IceTransportAddress;
/**
* Structure representing an ICE candidate.
*/
typedef struct _IceCandidate {
char foundation[32]; /**< Foundation of the candidate (see paragraph 3 of the RFC 5245 for more details */
IceTransportAddress taddr; /**< Transport address of the candidate */
IceCandidateType type; /**< Type of the candidate */
uint32_t priority; /**< Priority of the candidate */
uint16_t componentID; /**< component ID between 1 and 256: usually 1 for RTP component and 2 for RTCP component */
struct _IceCandidate *base; /**< Pointer to the candidate that is the base of the current one */
bool_t is_default; /**< Boolean value telling whether this candidate is a default candidate or not */
} IceCandidate;
/**
* Structure representing an ICE candidate pair.
*/
typedef struct _IceCandidatePair {
IceRole role; /**< Role of the agent when the connectivity check has been sent for the candidate pair */
IceCandidate *local; /**< Pointer to the local candidate of the pair */
IceCandidate *remote; /**< Pointer to the remote candidate of the pair */
IceCandidatePairState state; /**< State of the candidate pair */
uint64_t priority; /**< Priority of the candidate pair */
MSTimeSpec transmission_time; /**< Time when the connectivity check for the candidate pair has been sent */
int32_t rto; /**< Duration of the retransmit timer for the connectivity check sent for the candidate pair in ms */
uint8_t retransmissions; /**< Number of retransmissions for the connectivity check sent for the candidate pair */
bool_t is_default; /**< Boolean value telling whether this candidate pair is a default candidate pair or not */
bool_t use_candidate; /**< Boolean value telling if the USE-CANDIDATE attribute must be set for the connectivity checks send for the candidate pair */
bool_t is_nominated; /**< Boolean value telling whether this candidate pair is nominated or not */
bool_t nomination_pending; /** Boolean value telling whether this candidate pair was nominated by the remote (in controlled mode), but we could not yet complete the check*/
bool_t has_canceled_transaction; /**< Boolean value telling that the pair has a cancelled transaction, see RFC5245 7.2.1.4. Triggered Checks */
bool_t nomination_failing; /**