Commit 227c8d1c authored by Adrien Béraud's avatar Adrien Béraud

Revert "sip: negotiate both UDP and TCP for the control channel"

This reverts commit e83a1006.

Reason for revert: some major issues remain

Change-Id: I6c59880ef9aacb1a0646c4879186b3f269b8541e
parent 8b3399e8
...@@ -35,6 +35,7 @@ bash -c "%PATCH_CMD% %UNIXPATH%pjproject/fix_ioqueue_ipv6_sendto.patch" ...@@ -35,6 +35,7 @@ bash -c "%PATCH_CMD% %UNIXPATH%pjproject/fix_ioqueue_ipv6_sendto.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/add_dtls_transport.patch" bash -c "%PATCH_CMD% %UNIXPATH%pjproject/add_dtls_transport.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/rfc6544.patch" bash -c "%PATCH_CMD% %UNIXPATH%pjproject/rfc6544.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/ice_config.patch" bash -c "%PATCH_CMD% %UNIXPATH%pjproject/ice_config.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/win32_ice_tcp_temp_fix.patch"
%APPLY_CMD% %SRC%\pjproject\win32_vs_gnutls.patch %APPLY_CMD% %SRC%\pjproject\win32_vs_gnutls.patch
%APPLY_CMD% %SRC%\pjproject\win_config.patch %APPLY_CMD% %SRC%\pjproject\win_config.patch
......
This diff is collapsed.
From 5f288fe0067f995b91ea87ba4ed19fd65b75ff31 Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Tue, 11 Jun 2019 16:47:06 -0400
Subject: [PATCH] fix for windows GetAdaptersAddresses
---
pjnath/src/pjnath/ice_strans.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 6172172..33ac521 100644
--- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c
@@ -1645,9 +1645,7 @@ pj_ice_strans_sendto2(pj_ice_strans *ice_st, unsigned comp_id, const void *data,
dest_addr_len = dst_addr_len;
}
- pj_stun_sock_info stun_sock_info;
- pj_stun_sock_get_info(comp->stun[tp_idx].sock, &stun_sock_info);
- pj_bool_t add_header = stun_sock_info.conn_type != PJ_STUN_TP_UDP;
+ pj_bool_t add_header = comp->ice_st->cfg.stun_tp->conn_type == PJ_STUN_TP_TCP;
if (add_header) {
//TCP
/*
@@ -1864,9 +1862,7 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
if (comp->stun[tp_idx].sock) {
pj_ssize_t sent_size;
- pj_stun_sock_info stun_sock_info;
- pj_stun_sock_get_info(comp->stun[tp_idx].sock, &stun_sock_info);
- pj_bool_t add_header = stun_sock_info.conn_type != PJ_STUN_TP_UDP;
+ pj_bool_t add_header = comp->ice_st->cfg.stun_tp->conn_type == PJ_STUN_TP_TCP;
if (add_header) {
//TCP
/*
--
2.7.4
...@@ -67,13 +67,12 @@ public: ...@@ -67,13 +67,12 @@ public:
static constexpr uint16_t IPV4_HEADER_SIZE = 20; // Size in bytes of IPv4 packet header static constexpr uint16_t IPV4_HEADER_SIZE = 20; // Size in bytes of IPv4 packet header
static constexpr uint16_t UDP_HEADER_SIZE = 8; // Size in bytes of UDP header static constexpr uint16_t UDP_HEADER_SIZE = 8; // Size in bytes of UDP header
IceSocketTransport(std::shared_ptr<IceTransport>& ice, int comp_id, bool reliable = false) IceSocketTransport(std::shared_ptr<IceTransport>& ice, int comp_id)
: compId_ {comp_id} : compId_ {comp_id}
, ice_ {ice} , ice_ {ice} {}
, reliable_ {reliable} {}
bool isReliable() const override { bool isReliable() const override {
return reliable_; return false; // we consider that a ICE transport is never reliable (UDP support only)
} }
bool isInitiator() const override; bool isInitiator() const override;
...@@ -95,7 +94,6 @@ public: ...@@ -95,7 +94,6 @@ public:
private: private:
const int compId_; const int compId_;
std::shared_ptr<IceTransport> ice_; std::shared_ptr<IceTransport> ice_;
bool reliable_;
}; };
}; };
This diff is collapsed.
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <msgpack.hpp>
#include <vector> #include <vector>
namespace jami { namespace jami {
...@@ -74,14 +73,6 @@ struct IceTransportOptions { ...@@ -74,14 +73,6 @@ struct IceTransportOptions {
bool aggressive {false}; // If we use the aggressive nomination strategy bool aggressive {false}; // If we use the aggressive nomination strategy
}; };
struct SDP {
std::string ufrag;
std::string pwd;
std::vector<std::string> candidates;
MSGPACK_DEFINE(ufrag, pwd, candidates)
};
class IceTransport { class IceTransport {
public: public:
using Attribute = struct { using Attribute = struct {
...@@ -94,6 +85,7 @@ public: ...@@ -94,6 +85,7 @@ public:
*/ */
IceTransport(const char* name, int component_count, bool master, IceTransport(const char* name, int component_count, bool master,
const IceTransportOptions& options = {}); const IceTransportOptions& options = {});
/** /**
* Get current state * Get current state
*/ */
...@@ -108,7 +100,7 @@ public: ...@@ -108,7 +100,7 @@ public:
*/ */
bool start(const Attribute& rem_attrs, bool start(const Attribute& rem_attrs,
const std::vector<IceCandidate>& rem_candidates); const std::vector<IceCandidate>& rem_candidates);
bool start(const SDP& sdp); bool start(const std::vector<uint8_t>& attrs_candidates);
/** /**
* Stop a started or completed transport. * Stop a started or completed transport.
...@@ -133,12 +125,6 @@ public: ...@@ -133,12 +125,6 @@ public:
*/ */
bool isRunning() const; bool isRunning() const;
/**
* Return true if a start operations fails or if stop() has been called
* [mutex protected]
*/
bool isStopped() const;
/** /**
* Returns true if ICE transport is in failure state * Returns true if ICE transport is in failure state
* [mutex protected] * [mutex protected]
...@@ -170,7 +156,7 @@ public: ...@@ -170,7 +156,7 @@ public:
/** /**
* Returns serialized ICE attributes and candidates. * Returns serialized ICE attributes and candidates.
*/ */
std::vector<uint8_t> packIceMsg(uint8_t version = 1) const; std::vector<uint8_t> packIceMsg() const;
bool getCandidateFromSDP(const std::string& line, IceCandidate& cand); bool getCandidateFromSDP(const std::string& line, IceCandidate& cand);
...@@ -202,15 +188,6 @@ public: ...@@ -202,15 +188,6 @@ public:
bool setSlaveSession(); bool setSlaveSession();
bool setInitiatorSession(); bool setInitiatorSession();
/**
* Get SDP messages list
* @param msg The payload to parse
* @return the list of SDP messages
*/
static std::vector<SDP> parseSDPList(const std::vector<uint8_t>& msg);
bool isTCPEnabled();
private: private:
class Impl; class Impl;
std::unique_ptr<Impl> pimpl_; std::unique_ptr<Impl> pimpl_;
......
This diff is collapsed.
...@@ -615,7 +615,6 @@ class JamiAccount : public SIPAccountBase { ...@@ -615,7 +615,6 @@ class JamiAccount : public SIPAccountBase {
void saveKnownDevices() const; void saveKnownDevices() const;
void replyToIncomingIceMsg(const std::shared_ptr<SIPCall>&, void replyToIncomingIceMsg(const std::shared_ptr<SIPCall>&,
const std::shared_ptr<IceTransport>&,
const std::shared_ptr<IceTransport>&, const std::shared_ptr<IceTransport>&,
const dht::IceCandidates&, const dht::IceCandidates&,
const std::shared_ptr<dht::crypto::Certificate>& from_cert, const std::shared_ptr<dht::crypto::Certificate>& from_cert,
......
...@@ -236,7 +236,7 @@ SipsIceTransport::SipsIceTransport(pjsip_endpoint* endpt, ...@@ -236,7 +236,7 @@ SipsIceTransport::SipsIceTransport(pjsip_endpoint* endpt,
std::memset(&localCertInfo_, 0, sizeof(pj_ssl_cert_info)); std::memset(&localCertInfo_, 0, sizeof(pj_ssl_cert_info));
std::memset(&remoteCertInfo_, 0, sizeof(pj_ssl_cert_info)); std::memset(&remoteCertInfo_, 0, sizeof(pj_ssl_cert_info));
iceSocket_ = std::make_unique<IceSocketTransport>(ice_, comp_id, PJSIP_TRANSPORT_IS_RELIABLE(&trData_.base)); iceSocket_ = std::make_unique<IceSocketTransport>(ice_, comp_id);
TlsSession::TlsSessionCallbacks cbs = { TlsSession::TlsSessionCallbacks cbs = {
/*.onStateChange = */[this](TlsSessionState state){ onTlsStateChange(state); }, /*.onStateChange = */[this](TlsSessionState state){ onTlsStateChange(state); },
...@@ -249,22 +249,11 @@ SipsIceTransport::SipsIceTransport(pjsip_endpoint* endpt, ...@@ -249,22 +249,11 @@ SipsIceTransport::SipsIceTransport(pjsip_endpoint* endpt,
if (pjsip_transport_register(base.tpmgr, &base) != PJ_SUCCESS) if (pjsip_transport_register(base.tpmgr, &base) != PJ_SUCCESS)
throw std::runtime_error("Can't register PJSIP transport."); throw std::runtime_error("Can't register PJSIP transport.");
if (PJSIP_TRANSPORT_IS_RELIABLE(&trData_.base)) {
eventLoop_ = std::thread([this] {
try {
eventLoop();
} catch (const std::exception& e) {
JAMI_ERR() << "SipIceTransport: eventLoop() failure: " << e.what();
}
});
}
} }
SipsIceTransport::~SipsIceTransport() SipsIceTransport::~SipsIceTransport()
{ {
JAMI_DBG("~SipIceTransport@%p {tr=%p}", this, &trData_.base); JAMI_DBG("~SipIceTransport@%p {tr=%p}", this, &trData_.base);
stopLoop_ = true;
// Flush send queue with ENOTCONN error // Flush send queue with ENOTCONN error
for (auto tdata : txQueue_) { for (auto tdata : txQueue_) {
...@@ -277,8 +266,6 @@ SipsIceTransport::~SipsIceTransport() ...@@ -277,8 +266,6 @@ SipsIceTransport::~SipsIceTransport()
auto base = getTransportBase(); auto base = getTransportBase();
// Stop low-level transport first // Stop low-level transport first
tls_->shutdown();
if (eventLoop_.joinable()) eventLoop_.join();
tls_.reset(); tls_.reset();
// If delete not trigged by pjsip_transport_destroy (happen if objet not given to pjsip) // If delete not trigged by pjsip_transport_destroy (happen if objet not given to pjsip)
...@@ -513,10 +500,7 @@ SipsIceTransport::getInfo(pj_ssl_sock_info* info, bool established) ...@@ -513,10 +500,7 @@ SipsIceTransport::getInfo(pj_ssl_sock_info* info, bool established)
std::memset(info, 0, sizeof(*info)); std::memset(info, 0, sizeof(*info));
info->established = established; info->established = established;
if (PJSIP_TRANSPORT_IS_RELIABLE(&trData_.base)) info->proto = PJ_SSL_SOCK_PROTO_DTLS1;
info->proto = PJSIP_SSL_DEFAULT_PROTO;
else
info->proto = PJ_SSL_SOCK_PROTO_DTLS1;
pj_sockaddr_cp(&info->local_addr, local_.pjPtr()); pj_sockaddr_cp(&info->local_addr, local_.pjPtr());
...@@ -724,23 +708,4 @@ SipsIceTransport::getTlsSessionMtu() ...@@ -724,23 +708,4 @@ SipsIceTransport::getTlsSessionMtu()
return tls_->maxPayload(); return tls_->maxPayload();
} }
void
SipsIceTransport::eventLoop()
{
while(!stopLoop_) {
std::error_code err;
if (tls_ && tls_->waitForData(100, err)) {
std::vector<uint8_t> pkt;
pkt.resize(PJSIP_MAX_PKT_LEN);
auto read = tls_->read(pkt.data(), PJSIP_MAX_PKT_LEN, err);
if (read > 0) {
pkt.resize(read);
std::lock_guard<std::mutex> l(rxMtx_);
rxPending_.emplace_back(std::move(pkt));
scheduler_.run([this]{ handleEvents(); });
}
}
}
}
}} // namespace jami::tls }} // namespace jami::tls
...@@ -138,10 +138,6 @@ private: ...@@ -138,10 +138,6 @@ private:
void onRxData(std::vector<uint8_t>&&); void onRxData(std::vector<uint8_t>&&);
void onCertificatesUpdate(const gnutls_datum_t*, const gnutls_datum_t*, unsigned int); void onCertificatesUpdate(const gnutls_datum_t*, const gnutls_datum_t*, unsigned int);
int verifyCertificate(gnutls_session_t); int verifyCertificate(gnutls_session_t);
std::thread eventLoop_;
void eventLoop();
std::atomic_bool stopLoop_ {false};
}; };
}} // namespace jami::tls }} // namespace jami::tls
...@@ -334,7 +334,7 @@ IceSocketEndpoint::waitForData(unsigned ms_timeout, std::error_code& ec) const ...@@ -334,7 +334,7 @@ IceSocketEndpoint::waitForData(unsigned ms_timeout, std::error_code& ec) const
{ {
if (ice_) { if (ice_) {
if (!ice_->isRunning()) return -1; if (!ice_->isRunning()) return -1;
return iceIsSender ? ice_->isDataAvailable(compId_) : ice_->waitForData(compId_, ms_timeout, ec); return iceIsSender ? ice_->isDataAvailable(1) : ice_->waitForData(1, ms_timeout, ec);
} }
return -1; return -1;
} }
...@@ -345,7 +345,7 @@ IceSocketEndpoint::read(ValueType* buf, std::size_t len, std::error_code& ec) ...@@ -345,7 +345,7 @@ IceSocketEndpoint::read(ValueType* buf, std::size_t len, std::error_code& ec)
if (ice_) { if (ice_) {
if (!ice_->isRunning()) return 0; if (!ice_->isRunning()) return 0;
try { try {
auto res = ice_->recvfrom(compId_, reinterpret_cast<char *>(buf), len); auto res = ice_->recvfrom(1, reinterpret_cast<char *>(buf), len);
if (res < 0) if (res < 0)
ec.assign(errno, std::generic_category()); ec.assign(errno, std::generic_category());
else else
...@@ -365,7 +365,7 @@ IceSocketEndpoint::write(const ValueType* buf, std::size_t len, std::error_code& ...@@ -365,7 +365,7 @@ IceSocketEndpoint::write(const ValueType* buf, std::size_t len, std::error_code&
if (ice_) { if (ice_) {
if (!ice_->isRunning()) return 0; if (!ice_->isRunning()) return 0;
auto res = 0; auto res = 0;
res = ice_->send(compId_, reinterpret_cast<const unsigned char *>(buf), len); res = ice_->send(0, reinterpret_cast<const unsigned char *>(buf), len);
if (res < 0) { if (res < 0) {
ec.assign(errno, std::generic_category()); ec.assign(errno, std::generic_category());
} else { } else {
......
...@@ -157,7 +157,7 @@ public: ...@@ -157,7 +157,7 @@ public:
void setOnRecv(RecvCb&& cb) override { void setOnRecv(RecvCb&& cb) override {
if (ice_) { if (ice_) {
ice_->setOnRecv(compId_, cb); ice_->setOnRecv(0, cb);
} }
} }
...@@ -165,7 +165,6 @@ private: ...@@ -165,7 +165,6 @@ private:
std::shared_ptr<IceTransport> ice_ {nullptr}; std::shared_ptr<IceTransport> ice_ {nullptr};
std::atomic_bool iceStopped{false}; std::atomic_bool iceStopped{false};
std::atomic_bool iceIsSender{false}; std::atomic_bool iceIsSender{false};
uint8_t compId_ {0};
}; };
//============================================================================== //==============================================================================
......
...@@ -234,7 +234,6 @@ public: ...@@ -234,7 +234,6 @@ public:
std::unique_ptr<TlsAnonymousClientCredendials> cacred_; // ctor init. std::unique_ptr<TlsAnonymousClientCredendials> cacred_; // ctor init.
std::unique_ptr<TlsAnonymousServerCredendials> sacred_; // ctor init. std::unique_ptr<TlsAnonymousServerCredendials> sacred_; // ctor init.
std::unique_ptr<TlsCertificateCredendials> xcred_; // ctor init. std::unique_ptr<TlsCertificateCredendials> xcred_; // ctor init.
std::mutex sessionMutex_;
gnutls_session_t session_ {nullptr}; gnutls_session_t session_ {nullptr};
gnutls_datum_t cookie_key_ {nullptr, 0}; gnutls_datum_t cookie_key_ {nullptr, 0};
gnutls_dtls_prestate_st prestate_ {}; gnutls_dtls_prestate_st prestate_ {};
...@@ -725,16 +724,13 @@ TlsSession::TlsSessionImpl::cleanup() ...@@ -725,16 +724,13 @@ TlsSession::TlsSessionImpl::cleanup()
state_ = TlsSessionState::SHUTDOWN; // be sure to block any user operations state_ = TlsSessionState::SHUTDOWN; // be sure to block any user operations
stateCondition_.notify_all(); stateCondition_.notify_all();
{ if (session_) {
std::lock_guard<std::mutex> lk(sessionMutex_); if (transport_.isReliable())
if (session_) { gnutls_bye(session_, GNUTLS_SHUT_RDWR);
if (transport_.isReliable()) else
gnutls_bye(session_, GNUTLS_SHUT_RDWR); gnutls_bye(session_, GNUTLS_SHUT_WR); // not wait for a peer answer
else gnutls_deinit(session_);
gnutls_bye(session_, GNUTLS_SHUT_WR); // not wait for a peer answer session_ = nullptr;
gnutls_deinit(session_);
session_ = nullptr;
}
} }
if (cookie_key_.data) if (cookie_key_.data)
...@@ -1222,7 +1218,7 @@ TlsSession::TlsSession(SocketType& transport, const TlsParams& params, ...@@ -1222,7 +1218,7 @@ TlsSession::TlsSession(SocketType& transport, const TlsParams& params,
TlsSession::~TlsSession() TlsSession::~TlsSession()
{ {
if (pimpl_) shutdown(); shutdown();
} }
bool bool
...@@ -1241,8 +1237,8 @@ int ...@@ -1241,8 +1237,8 @@ int
TlsSession::maxPayload() const TlsSession::maxPayload() const
{ {
if (pimpl_->state_ == TlsSessionState::SHUTDOWN) if (pimpl_->state_ == TlsSessionState::SHUTDOWN)
throw std::runtime_error("Getting maxPayload from non-valid TLS session"); throw std::runtime_error("Getting MTU from non-valid TLS session");
return pimpl_->transport_.maxPayload(); return gnutls_dtls_get_data_mtu(pimpl_->session_);
} }
const char* const char*
...@@ -1299,22 +1295,15 @@ TlsSession::read(ValueType* data, std::size_t size, std::error_code& ec) ...@@ -1299,22 +1295,15 @@ TlsSession::read(ValueType* data, std::size_t size, std::error_code& ec)
} }
while (true) { while (true) {
ssize_t ret; auto ret = gnutls_record_recv(pimpl_->session_, data, size);
{
std::lock_guard<std::mutex> lk(pimpl_->sessionMutex_);
if (!pimpl_->session_) return 0;
ret = gnutls_record_recv(pimpl_->session_, data, size);
}
if (ret > 0) { if (ret > 0) {
ec.clear(); ec.clear();
return ret; return ret;
} }
if (ret == 0) { if (ret == 0) {
if (pimpl_) { JAMI_DBG("[TLS] eof");
JAMI_ERR("[TLS] eof"); shutdown();
shutdown();
}
error = std::errc::broken_pipe; error = std::errc::broken_pipe;
break; break;
} else if (ret == GNUTLS_E_REHANDSHAKE) { } else if (ret == GNUTLS_E_REHANDSHAKE) {
...@@ -1323,10 +1312,8 @@ TlsSession::read(ValueType* data, std::size_t size, std::error_code& ec) ...@@ -1323,10 +1312,8 @@ TlsSession::read(ValueType* data, std::size_t size, std::error_code& ec)
pimpl_->rxCv_.notify_one(); // unblock waiting FSM pimpl_->rxCv_.notify_one(); // unblock waiting FSM
pimpl_->stateCondition_.notify_all(); pimpl_->stateCondition_.notify_all();
} else if (gnutls_error_is_fatal(ret)) { } else if (gnutls_error_is_fatal(ret)) {
if (pimpl_ && pimpl_->state_ != TlsSessionState::SHUTDOWN) { JAMI_ERR("[TLS] fatal error in recv: %s", gnutls_strerror(ret));
JAMI_ERR("[TLS] fatal error in recv: %s", gnutls_strerror(ret)); shutdown();
shutdown();
}
error = std::errc::io_error; error = std::errc::io_error;
break; break;
} }
......
...@@ -440,9 +440,6 @@ SipTransportBroker::getTlsIceTransport(const std::shared_ptr<jami::IceTransport> ...@@ -440,9 +440,6 @@ SipTransportBroker::getTlsIceTransport(const std::shared_ptr<jami::IceTransport>
{ {
auto ipv6 = ice->getLocalAddress(comp_id).isIpv6(); auto ipv6 = ice->getLocalAddress(comp_id).isIpv6();
auto type = ipv6 ? PJSIP_TRANSPORT_DTLS6 : PJSIP_TRANSPORT_DTLS; auto type = ipv6 ? PJSIP_TRANSPORT_DTLS6 : PJSIP_TRANSPORT_DTLS;
if (ice->isTCPEnabled()) {
type = ipv6 ? PJSIP_TRANSPORT_TLS6 : PJSIP_TRANSPORT_TLS;
}
auto sip_ice_tr = std::unique_ptr<tls::SipsIceTransport>( auto sip_ice_tr = std::unique_ptr<tls::SipsIceTransport>(
new tls::SipsIceTransport(endpt_, type, params, ice, comp_id)); new tls::SipsIceTransport(endpt_, type, params, ice, comp_id));
auto tr = sip_ice_tr->getTransportBase(); auto tr = sip_ice_tr->getTransportBase();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment