ICE学习笔记 -- RFC 5245

4)STUN Message Type
- request
- success response
- failure response
- indication
1、A向S发出Allocate Request,请求S在自己的IP地址上为A分配一个端口。
5. 开源实现 https://github.com/NATTools
ICELIB_INSTANCE *m_iceInst;
static ICELIB_Result OnConnectivityChecksComplete(void *pUserData, uint32_t userValue1, bool isControlling, bool iceFailed);
static ICELIB_Result OnOutgoingBindingRequest(void *pUserData, const struct sockaddr *destination,
const struct sockaddr *source, uint32_t transport, uint32_t userValue1, uint32_t userValue2,
uint32_t componentId, bool useRelay, const char *pUfragPair, const char *pPasswd,
uint32_t peerPriority, bool useCandidate, bool iceControlling, bool iceControlled,
uint64_t tieBreaker, StunMsgId transactionId, const char *szFingerPrint);
static ICELIB_Result OutgoingBindingResponse(void *pUserData, uint32_t userValue1,
uint32_t userValue2, uint32_t componentId, const struct sockaddr *source,
const struct sockaddr *destination, const struct sockaddr *MappedAddress,
uint16_t errorResponse, StunMsgId transactionId, bool useRelay, const char *pUfragPair,
const char *pPasswd);
/*
static ICELIB_Result OnSendKeepAlive(void *pUserData, uint32_t userValue1, uint32_t userValue2,
uint32_t mediaIdx);
*/
6. wilson同学的分享记录
ICE
1. 什么是NAT?(网络地址转换)
2. NAT带来的问题(连通性问题,并没有定义或推荐公网或私网IP地址影射的方法,及互相通迅的问题,完全由应用自己解决)
3. STUN解决的问题(解决两个NAT之后设备的连通)
4. 源地址、目标地址、源端口,目标端口,协议 5个元素
5. NAT暴力猜测方法,两边各猜64个连接,连通的概率就很大了
6. ALG,根据SDP里的信息,帮你分配端口,路由器要支持SDP,且SDP不能被加密
7. Connectivity check,可以做很多并行的尝试,间隔一定的delay,按优先级发包
8. STUN包做了扩展。PRIORITY, USE-CANDIDATE, ICE-CONTROLLED, and ICE-CONTROLLING
9. Nominate的过程:(Nomination 一直在做,priority每过100毫秒加100,达到1000,即可以conclude.)
收到包以后,好几个都通了,就需要选择一个。Aggressive/Regular nomination, Aggressive nomination已经淘汰,因为协议有bug。
Aggressive 本来是想更快的建立连接,后来大家发现Regular完全可以做到同样的快, Early media。
Regular Nominate过程,发的STUN包有两种包,USE-CANDIDATE=0(Nominate前), USE-CANDIDATE=1(Nominate后)
两个人,不能两个人都Nominate, 要选择一个主动,一个被动。SDP里面有个属性,叫ICE-CONTROLLING(主动), ICE-CONTROLLED(被动)。
被动的一方收到response,看到USE-CANDIDATE=1,就知道了选择好了,以后用这个transport来通讯。
角色的选择,第一个STUN包的里时候,里面有个tie-breaking,是一个64bit的随机数,谁的大谁就做CONTROLLING,另一个做CONTROLLED
10. LITE实现(当做为服务器时,有公网IP的情况下,申明我是LITE,就不需要connectivity check,由client来check)
firefox 对LITE支持的不太好,chrome还可以。
11. Restart/Reconnect
12. Keep live(定时,client发一个包,server回一个包,做有效性检查)
13. Conclude:(为什么Aggressive Nominate不需要了,是因为有Early media)
Early media就是说,有一个transport连通以后,就可以发送一些数据回去,所以只要你发,对方肯定能收的到.
因为这时候还没有Conclue,一旦conclue这后,非nominate的transport会被关闭。
Conclude,是为了保证RTP的transport是symmetric的,即发过去和发过来的transport是同一个。
14. ICE, RTP, DTLS是复用在同一个transport上的。
15. AddMediaStream,一个SDP里面有多个Media(Audio/Video),要建多条连接,一个MediaStream里面有两个component(RTP1 /RTCP 2).
一个session里面有多个MediaStream(Audio/Video/Sharing)。
我们ICE session里面的实现,三个是分开的,一个Media就用了一个Session,是觉得放在一个session里,可以做优化的不多。
Audio/Video/Sharing各有一个ICEConnector,各用一个transport。
16. 优先级 0123456 Nattool里fundation有bug(不同的IP用相同的fundation).
17. OnICEComplete会来两回,第一次是Early meida(最早的连通的一个transport), 第二次是Conclude. bUpdate=0 bUpdate=1。
ICE
//
//----- ICE configuration data
//
typedef struct {
unsigned int tickIntervalMS;
unsigned int keepAliveIntervalS;
unsigned int maxCheckListPairs;
bool aggressiveNomination;
bool iceLite;
ICELIB_logLevel logLevel;
} ICELIB_CONFIGURATION;
//
//----- ICE instance data
//
typedef struct tag_ICELIB_INSTANCE {
ICELIB_STATE iceState;
ICELIB_CONFIGURATION iceConfiguration;
ICELIB_CALLBACKS callbacks;
ICE_MEDIA localIceMedia;
ICE_MEDIA remoteIceMedia;
bool iceControlling;
bool iceControlled;
bool iceSupportVerified;
uint64_t tieBreaker;
ICELIB_STREAM_CONTROLLER streamControllers[ ICE_MAX_MEDIALINES];
unsigned int numberOfMediaStreams;
unsigned int roundRobinStreamControllerIndex;
uint32_t tickCount;
uint32_t keepAliveTickCount;
} ICELIB_INSTANCE;
/*!
* ICE single candidate
*
* From draft-ietf-mmusic-ice-18:
*
* foundation = 1*32 ice-char
* componentid = 1*5 digit (0..65535)
* priority = 1*10 digit (0..2147483647)
* connectionAddr = address including port
* relAddr = host addres when sending relayed candidates (Optional, used for debugging)
*/
typedef struct {
char foundation[ ICE_MAX_FOUNDATION_LENGTH];
uint32_t componentid;
uint32_t priority;
struct sockaddr_storage connectionAddr;
ICE_CANDIDATE_TYPE type;
struct sockaddr_storage relAddr;
uint32_t userValue1;
uint32_t userValue2;
uint32_t transport;
char fingerprint[ICE_MAX_FINGERPRINT];
} ICE_CANDIDATE;
typedef struct {
uint32_t componentId;
struct sockaddr_storage connectionAddr;
ICE_CANDIDATE_TYPE type;
} ICE_REMOTE_CANDIDATE;
typedef struct {
ICE_REMOTE_CANDIDATE remoteCandidate[ICE_MAX_COMPONENTS];
uint32_t numberOfComponents;
} ICE_REMOTE_CANDIDATES;
/*!
* ICE candidates for a single media stream
*/
typedef struct {
char ufrag [ ICE_MAX_UFRAG_LENGTH];
char passwd [ ICE_MAX_PASSWD_LENGTH];
ICE_CANDIDATE candidate[ ICE_MAX_CANDIDATES];
uint32_t numberOfCandidates;
ICE_TURN_STATE turnState;
uint32_t userValue1;
uint32_t userValue2;
struct sockaddr_storage defaultAddr;
ICE_CANDIDATE_TYPE defaultCandType;
} ICE_MEDIA_STREAM;
ICELIB_INSTANCE
ICELIB_Constructor
ICELIB_Destructor
ICELIB_Start
ICELIB_Stop
ICELIB_ReStart
ICELIB_Tick
ICELIB_setCallbackLog
ICELIB_addLocalMediaStream
ICELIB_setLocalMediaStream
ICELIB_getLocalMediaStream
ICELIB_addRemoteMediaStream
ICELIB_getRemoteMediaStream
ICELIB_setCallbackConnecitivityChecksComplete
ICELIB_setCallbackOutgoingBindingRequest
ICELIB_setCallbackOutgoingBindingResponse
ICELIB_setCallbackKeepAlive
ICELIB_doKeepAlive
ICELIB_addLocalCandidate
ICELIB_getActiveCandidate
ICELIB_getActiveRemoteCandidates
ICELIB_incomingBindingRequest
ICELIB_isIceComplete
ICELIB_isRunning
ICELIB_incomingBindingResponse
ICELIB_getRemoteComponentId
ICELIB_generateTransactionId
ICELIBTYPES_ICE_CANDIDATE_TYPE_toString
Frozen已经废弃不用了
ICELIB_setCallbackConnecitivityChecksComplete(m_iceInst, OnConnectivityChecksComplete, this);
ICELIB_setCallbackOutgoingBindingRequest(m_iceInst, OnOutgoingBindingRequest, this);
ICELIB_setCallbackOutgoingBindingResponse(m_iceInst, OutgoingBindingResponse, this);
static ICELIB_Result OnConnectivityChecksComplete(void *pUserData, uint32_t userValue1, bool isControlling, bool iceFailed);
//onicecomplete, aReason
static ICELIB_Result OnOutgoingBindingRequest(void *pUserData, const struct sockaddr *destination,
const struct sockaddr *source, uint32_t transport, uint32_t userValue1, uint32_t userValue2,
uint32_t componentId, bool useRelay, const char *pUfragPair, const char *pPasswd,
uint32_t peerPriority, bool useCandidate, bool iceControlling, bool iceControlled,
uint64_t tieBreaker, StunMsgId transactionId, const char *szFingerPrint);
//start connectivity checking, a Request --->> a check.
static ICELIB_Result OutgoingBindingResponse(void *pUserData, uint32_t userValue1,
uint32_t userValue2, uint32_t componentId, const struct sockaddr *source,
const struct sockaddr *destination, const struct sockaddr *MappedAddress,
uint16_t errorResponse, StunMsgId transactionId, bool useRelay, const char *pUfragPair,
const char *pPasswd);
//有一个response回来可以做early media
conclude at last, select a transport
/*
static ICELIB_Result OnSendKeepAlive(void *pUserData, uint32_t userValue1, uint32_t userValue2,
uint32_t mediaIdx);
*/
ICE学习笔记 -- RFC 5245的更多相关文章
- ICE学习笔记一----运行官方的java版demo程序
建议新手和我一样,从官网下载英文文档,开个有道词典,慢慢啃. 官方文档下载: http://download.csdn.net/detail/xiong_mao_1/6300631 程序代码就不说了, ...
- DTLS学习笔记 -- RFC 4347- 6347
想学习一下dtls,是因为想以后没有公司免费VPN可用的时候,我能买一个主机,自己建一个VPN. 1.介绍 Web, email大多用TLS协议来做安全的网络传输,它们必须跑在可靠的TCP传输通道里. ...
- stun/turn/ice学习笔记
stun基本只是用于client探测NAT之后靠近stun server的外网地址,本身不包含应用数据通信的功能,其底层STUN协议通信多是基于UDP的.多个端点之间相互通过信令通道拿到彼此的NAT外 ...
- SIP学习笔记 -- RFC 3261
1.SDP (rfc 4566) 1)用于交换参数 2)内容分三部分Session description, Time description and Media description ...
- XMPP学习笔记 -- RFC 6120
XMPP - Extensible Messaging and Presence Protocol 1. 中文版3920 http://wiki.jabbercn.org/RFC3920 2. 大部分 ...
- RTP/RTCP学习笔记 -- RFC 3550
The MTU of RTP package payload is (IP) - (UDP) - = 1472 #define DEFAULT_MAX_PACKET_SIZE 1200 video ...
- [转]ICE介绍 (RFC 5245)
[转]ICE介绍 (RFC 5245) http://blog.csdn.net/dxpqxb/article/details/22040017 1关于ICE的10个事实 1 ICE使用STUN和TU ...
- squid 学习笔记
Squid学习笔记 1.安装前的配置 编译安装之前需要校正的参数主要包括File Descriptor和Mbuf Clusters. 1.File Descriptor 查看文件描述符的限制数目: u ...
- <老友记>学习笔记
这是六个人的故事,从不服输而又有强烈控制欲的monica,未经世事的千金大小姐rachel,正直又专情的ross,幽默风趣的chandle,古怪迷人的phoebe,花心天真的joey——六个好友之间的 ...
随机推荐
- VUE2.0 【v-html】标签使用技巧
<div class="active-rules"> <div class="weui-weixin-content" id="ru ...
- 554 DT:SPM 163 smtp5,D9GowAD3RPYqSvxZjpMaAA--.4817S2 1509706293 坑爹的防垃圾邮件机制
代码如下 package ssmtest; import java.io.File;import java.io.UnsupportedEncodingException;import java.ut ...
- 初学ElasticSeacher
这周,刚接手了同事那边的工作,项目里需要用到ElasticSeacher.但是,之前从未接触过,因此,看了ES的文档,开始慢慢的知道了一些ES的知识. 一.ES简介: Elasticsearch是一个 ...
- BZOJ 3065 带插入区间第K小值
题目描述 Description 从前有n只跳蚤排成一行做早操,每只跳蚤都有自己的一个弹跳力a[i].跳蚤国王看着这些跳蚤国欣欣向荣的情景,感到非常高兴.这时跳蚤国王决定理性愉悦一下,查询区间k小值. ...
- Maven出现User setting file does not exist ...\.m2\setting.xml的问题解决(同时也解决用户.m2目录下无setting.xml文件)
如果Eclipse中出现User setting file does not exist ...\.m2\setting.xml这样的问题,解决方法如下: 1.拷贝%M2_HOME%/conf/set ...
- 【spring data jpa】使用spring data jpa时,关于service层一个方法中进行【删除】和【插入】两种操作在同一个事务内处理
场景: 现在有这么一个情况,就是在service中提供的一个方法是先将符合条件的数据全部删除,然后再将新的条件全部插入数据库中 这个场景需要保证service中执行两步 1.删除 2.插入 这两步自然 ...
- Hibernate 3 深度解析--苏春波
Hibernate 3 深度解析 Hibernate 作为 Java ORM 模式的优秀开源实现, 当下已经成为一种标准,为饱受 JDBC 折磨的 Java 开发者带来了“福音.快速的版本更新,想 ...
- 机器学习(十三)——机器学习中的矩阵方法(3)病态矩阵、协同过滤的ALS算法(1)
http://antkillerfarm.github.io/ 向量的范数(续) 范数可用符号∥x∥λ表示. 经常使用的有: ∥x∥1=|x1|+⋯+|xn| ∥x∥2=x21+⋯+x2n−−−−−− ...
- Mysql的四种key
我们看到Key那一栏,可能会有4种值,即 '','PRI','UNI','MUL'1. 如果Key是空的, 那么该列值的可以重复, 表示该列没有索引, 或者是一个非唯一的复合索引的非前导列2. 如果K ...
- construct-binary-tree-from-preorder-and-inorder-traversal——前序和中序求二叉树
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume tha ...