/* * Copyright 2004 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.
*/
size_t AddrCmp::operator()(const SocketAddress& a) const {
size_t h = 0; if (use_ip)
h ^= HashIP(a.ipaddr()); if (use_port)
h ^= a.port() | (a.port() << 16); return h;
}
bool AddrCmp::operator()(const SocketAddress& a1, const SocketAddress& a2) const { if (use_ip && (a1.ipaddr() < a2.ipaddr())) returntrue; if (use_ip && (a2.ipaddr() < a1.ipaddr())) returnfalse; if (use_port && (a1.port() < a2.port())) returntrue; if (use_port && (a2.port() < a1.port())) returnfalse; returnfalse;
}
// Proxy socket that will capture the external destination address intended for // a TCP connection to the NAT server. class NATProxyServerSocket : public AsyncProxyServerSocket { public:
NATProxyServerSocket(Socket* socket)
: AsyncProxyServerSocket(socket, kNATEncodedIPv6AddressSize) {
BufferInput(true);
}
void NATServer::OnInternalUDPPacket(AsyncPacketSocket* socket, const rtc::ReceivedPacket& packet) {
RTC_DCHECK(internal_socket_thread_.IsCurrent()); // Read the intended destination from the wire.
SocketAddress dest_addr;
size_t length = UnpackAddressFromNAT(packet.payload(), &dest_addr);
// Find the translation for these addresses (allocating one if necessary).
SocketAddressPair route(packet.source_address(), dest_addr);
InternalMap::iterator iter = int_map_->find(route); if (iter == int_map_->end()) {
Translate(route);
iter = int_map_->find(route);
}
RTC_DCHECK(iter != int_map_->end());
// Allow the destination to send packets back to the source.
iter->second->AllowlistInsert(dest_addr);
// Send the packet to its intended destination.
rtc::PacketOptions options; constchar* buf = reinterpret_cast<constchar*>(packet.payload().data());
size_t size = packet.payload().size();
iter->second->socket->SendTo(buf + length, size - length, dest_addr, options);
}
// Find the translation for this addresses.
ExternalMap::iterator iter = ext_map_->find(local_addr);
RTC_DCHECK(iter != ext_map_->end());
// Allow the NAT to reject this packet. if (ShouldFilterOut(iter->second, packet.source_address())) {
RTC_LOG(LS_INFO) << "Packet from "
<< packet.source_address().ToSensitiveString()
<< " was filtered out by the NAT."; return;
}
// Forward this packet to the internal address. // First prepend the address in a quasi-STUN format.
std::unique_ptr<char[]> real_buf( newchar[packet.payload().size() + kNATEncodedIPv6AddressSize]);
size_t addrlength = PackAddressForNAT(
real_buf.get(), packet.payload().size() + kNATEncodedIPv6AddressSize,
packet.source_address()); // Copy the data part after the address.
rtc::PacketOptions options;
memcpy(real_buf.get() + addrlength, packet.payload().data(),
packet.payload().size());
udp_server_socket_->SendTo(real_buf.get(),
packet.payload().size() + addrlength,
iter->second->route.source(), options);
}
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.