/* * Copyright 2013 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
inlinebool IsStunMessage(uint16_t msg_type) { // The first two bits of a channel data message are 0b01. return (msg_type & 0xC000) ? false : true;
}
// AsyncStunTCPSocket // Binds and connects `socket` and creates AsyncTCPSocket for // it. Takes ownership of `socket`. Returns NULL if bind() or // connect() fail (`socket` is destroyed in that case).
AsyncStunTCPSocket* AsyncStunTCPSocket::Create(
rtc::Socket* socket, const rtc::SocketAddress& bind_address, const rtc::SocketAddress& remote_address) { returnnew AsyncStunTCPSocket(
AsyncTCPSocketBase::ConnectSocket(socket, bind_address, remote_address));
}
size_t processed_bytes = 0; while (true) {
size_t bytes_left = data.size() - processed_bytes; // We need at least 4 bytes to read the STUN or ChannelData packet length. if (bytes_left < kPacketLenOffset + kPacketLenSize) return processed_bytes;
size_t AsyncStunTCPSocket::GetExpectedLength(constvoid* data,
size_t len, int* pad_bytes) {
*pad_bytes = 0;
PacketLength pkt_len =
rtc::GetBE16(static_cast<constchar*>(data) + kPacketLenOffset);
size_t expected_pkt_len;
uint16_t msg_type = rtc::GetBE16(data); if (IsStunMessage(msg_type)) { // STUN message.
expected_pkt_len = kStunHeaderSize + pkt_len;
} else { // TURN ChannelData message.
expected_pkt_len = kTurnChannelDataHdrSize + pkt_len; // From RFC 5766 section 11.5 // Over TCP and TLS-over-TCP, the ChannelData message MUST be padded to // a multiple of four bytes in order to ensure the alignment of // subsequent messages. The padding is not reflected in the length // field of the ChannelData message, so the actual size of a ChannelData // message (including padding) is (4 + Length) rounded up to the nearest // multiple of 4. Over UDP, the padding is not required but MAY be // included. if (expected_pkt_len % 4)
*pad_bytes = 4 - (expected_pkt_len % 4);
} return expected_pkt_len;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.