为何WebRTC TURN客户端不仅使用Channel Data传输数据?
WebRTC TURN客户端:Create Permission与Channel Bind的疑问
在WebRTC TURN客户端中,*创建权限(create permission)与通道绑定请求(channel bind request)*的现有流程如下:
1. 在TurnEntry构造函数中创建权限
TurnEntry::TurnEntry(TurnPort* port, Connection* conn, int channel_id) : port_(port), channel_id_(channel_id), ext_addr_(conn->remote_candidate().address()), state_(STATE_UNBOUND), connections_({conn}) { // 为`ext_addr_`创建权限。 SendCreatePermissionRequest(0); }
2. 后续发送通道绑定请求
对应核心方法SendChannelBindRequest的调用逻辑如下:
int TurnEntry::Send(const void* data, size_t size, bool payload, const rtc::PacketOptions& options) { rtc::ByteBufferWriter buf; if (state_ != STATE_BOUND || !port_->TurnCustomizerAllowChannelData(data, size, payload)) { // 如果通道尚未绑定,我们必须使用Send Indication。 // turn_customizer_也可能让我们使用Send Indication。 TurnMessage msg(TURN_SEND_INDICATION); msg.AddAttribute(std::make_unique<StunXorAddressAttribute>( STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_)); msg.AddAttribute( std::make_unique<StunByteStringAttribute>(STUN_ATTR_DATA, data, size)); port_->TurnCustomizerMaybeModifyOutgoingStunMessage(&msg); const bool success = msg.Write(&buf); RTC_DCHECK(success); // 如果我们正在发送真实数据,请求一个后续可使用的通道绑定。 if (state_ == STATE_UNBOUND && payload) { SendChannelBindRequest(0); state_ = STATE_BINDING; } } else { // 如果通道已绑定,我们可以将数据作为Channel Message发送。 buf.WriteUInt16(channel_id_); buf.WriteUInt16(static_cast<uint16_t>(size)); buf.WriteBytes(reinterpret_cast<const char*>(data), size); } rtc::PacketOptions modified_options(options); modified_options.info_signaled_after_sent.turn_overhead_bytes = buf.Length() - size; return port_->Send(buf.Data(), buf.Length(), modified_options); }
根据RFC 8656,Channel Data的开销仅为4字节,而Indication的开销为36字节。
为何不直接仅使用Channel Data进行传输?是否可以在TurnEntry构造函数中用SendChannelBindRequest替代SendCreatePermissionRequest?
内容的提问来源于stack exchange,提问作者Justme0
相关产品推荐
相关产品推荐

