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;
}
// Proxy socket that will capture the external destination address intended for // a TCP connection to the NAT server. class NATProxyServerSocket : public AsyncProxyServerSocket {
public: explicit NATProxyServerSocket(Socket* socket)
: AsyncProxyServerSocket(socket, kNATEncodedIPv6AddressSize) {
BufferInput(true);
}
void NATServer::OnInternalUDPPacket(AsyncPacketSocket* socket, const ReceivedIpPacket& 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.
AsyncSocketPacketOptions 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 (iter->second->ShouldFilterOut(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.
Buffer real_buf = Buffer::CreateWithCapacity(packet.payload().size() +
kNATEncodedIPv6AddressSize);
PackAddressForNAT(packet.source_address(), real_buf); // Copy the data part after the address.
AsyncSocketPacketOptions options;
real_buf.AppendData(packet.payload());
udp_server_socket_->SendTo(real_buf.data(), real_buf.size(),
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.