图片.png
    图片.png

    1. WebRtcTransport::WebRtcTransport(const std::string& id, RTC::Transport::Listener* listener, json& data)
    2. : RTC::Transport::Transport(id, listener, data)
    3. {
    4. ********************************
    5. for (auto& listenIp : listenIps)
    6. {
    7. if (enableUdp)
    8. {
    9. ********************************
    10. // This may throw.
    11. auto* udpSocket = new RTC::UdpSocket(this, listenIp.ip);
    12. this->udpSockets[udpSocket] = listenIp.announcedIp;
    13. if (listenIp.announcedIp.empty())
    14. this->iceCandidates.emplace_back(udpSocket, icePriority);
    15. else
    16. this->iceCandidates.emplace_back(udpSocket, icePriority, listenIp.announcedIp);
    17. }
    18. if (enableTcp)
    19. {
    20. ********************************
    21. // This may throw.
    22. auto* tcpServer = new RTC::TcpServer(this, this, listenIp.ip);
    23. this->tcpServers[tcpServer] = listenIp.announcedIp;
    24. if (listenIp.announcedIp.empty())
    25. this->iceCandidates.emplace_back(tcpServer, icePriority);
    26. else
    27. this->iceCandidates.emplace_back(tcpServer, icePriority, listenIp.announcedIp);
    28. }
    29. // Decrement initial ICE local preference for next IP.
    30. iceLocalPreferenceDecrement += 100;
    31. }
    32. *******************************
    33. }

    inline void WebRtcTransport::OnDtlsDataReceived( const RTC::TransportTuple tuple, const uint8_t data, size_t len)
    {
    {
    *
    this->dtlsTransport->ProcessDtlsData(data, len);
    **
    }

    1. void DtlsTransport::Run(Role localRole)
    2. {
    3. MS_TRACE();
    4. MS_ASSERT(
    5. localRole == Role::CLIENT || localRole == Role::SERVER,
    6. "local DTLS role must be 'client' or 'server'");
    7. Role previousLocalRole = this->localRole;
    8. if (localRole == previousLocalRole)
    9. {
    10. MS_ERROR("same local DTLS role provided, doing nothing");
    11. return;
    12. }
    13. // If the previous local DTLS role was 'client' or 'server' do reset.
    14. if (previousLocalRole == Role::CLIENT || previousLocalRole == Role::SERVER)
    15. {
    16. MS_DEBUG_TAG(dtls, "resetting DTLS due to local role change");
    17. Reset();
    18. }
    19. // Update local role.
    20. this->localRole = localRole;
    21. // Set state and notify the listener.
    22. this->state = DtlsState::CONNECTING;
    23. this->listener->OnDtlsTransportConnecting(this);
    24. switch (this->localRole)
    25. {
    26. case Role::CLIENT:
    27. {
    28. MS_DEBUG_TAG(dtls, "running [role:client]");
    29. SSL_set_connect_state(this->ssl);
    30. SSL_do_handshake(this->ssl);
    31. SendPendingOutgoingDtlsData();
    32. SetTimeout();
    33. break;
    34. }
    35. case Role::SERVER:
    36. {
    37. MS_DEBUG_TAG(dtls, "running [role:server]");
    38. SSL_set_accept_state(this->ssl);
    39. SSL_do_handshake(this->ssl);
    40. break;
    41. }
    42. default:
    43. {
    44. MS_ABORT("invalid local DTLS role");
    45. }
    46. }
    47. }