ICE之STUN协议---Binding Request
参考文档
按照时间顺序:
- stun(rfc 3489) : https://tools.ietf.org/html/rfc3489
- stun(rfc 5389,从rfc 3489演变来的) : https://tools.ietf.org/html/rfc5389
- ice : https://tools.ietf.org/html/rfc5245
stun协议
使用
https://tools.ietf.org/html/rfc5389#section-14
- stun不是NAT穿透问题的解决方案。
- stun只能作为大解决方案的一个工具。
stun message structure
https://tools.ietf.org/html/rfc5389#section-6
binding request
-
message type 分析
-
14bits表示message type
-
2bits表示class,C0和C1,也就是说一共四个class类型
- 0b00 : request
- 0b01 : indication
- 0b10 : success response
- 0b11 : error response
-
12bits表示method,M0-M11
-
下面这个是在rfc3489的描述
https://tools.ietf.org/html/rfc3489#section-11.1
说明:- 0b000000000001 :表示Binding方法
- 0b000000000010 :表示Shared Secret方法
-
-
cookie 必须是 0x2112a442
-
messgae length
- 单位是字节
- 不包含20字节头
-
transaction id
- 随机值
- 0至
attributes
- 跟在header之后
- 可以没有
- TLV(Type-Length-Value)格式
Type
- 在rfc 5226里定义的类型
https://tools.ietf.org/html/rfc5389#section-18.2
常用的:-
required
- 0x0001 : mapped-address
- 0x0006 : username
- 0x0008 : message-integrity
- 0x0020 : xor-mapped-address
-
optional
- 0x8028 : fingerprint
-
- 在rfc 5245中,进行了一些扩展
https://tools.ietf.org/html/rfc5245#section-19- required
- 0x0024 : priority
- 0x0025 : use-candidate
- optional
- 0x8029 : ice-controlled
- 0x802a : ice-controlling
- required
Length
-
只表示value的长度
-
但是如果长度不是整4个字节,要补0
比如这就是补的三个0 -
具体案例分析
-
username
-
ice-controlling
- Tie breaker 是一个64bits的随机值,是当两端的角色相同时,在服务端做决策的,决定哪一端改变角色。
- Tie breaker 是一个64bits的随机值,是当两端的角色相同时,在服务端做决策的,决定哪一端改变角色。
-
use-candidate
-
priority
-
message-integrity
-
fingerprint