Skip to content
Snippets Groups Projects
Commit 25cdcd8b authored by Edric Milaret's avatar Edric Milaret
Browse files

sip: fix pkt receive

- Sending profile highlighted a flaw in the processing of packet
  * The receive packet function from pjsip can't handle a packet
    larger than PJSIP_MAX_PKT_LEN (4000) but we were not enforcing
    that correctly
  * The received callback was appending packet to the last one instead
    of appending it to the received packet vector

Change-Id: I603cf19cb2951708edd5cca44d71b77bb83114d6
Tuleap: #538
parent 41e304a4
No related branches found
No related tags found
No related merge requests found
......@@ -319,19 +319,19 @@ SipsIceTransport::handleEvents()
auto& pck = *it;
pj_pool_reset(rdata_.tp_info.pool);
pj_gettimeofday(&rdata_.pkt_info.timestamp);
rdata_.pkt_info.len = pck.size();
std::copy_n(pck.data(), pck.size(), rdata_.pkt_info.packet);
rdata_.pkt_info.len = std::min(pck.size(), (size_t) PJSIP_MAX_PKT_LEN);
std::copy_n(pck.data(), rdata_.pkt_info.len, rdata_.pkt_info.packet);
auto eaten = pjsip_tpmgr_receive_packet(trData_.base.tpmgr, &rdata_);
// Uncomplet parsing? (may be a partial sip packet received)
if (eaten != rdata_.pkt_info.len) {
if (eaten != (pj_ssize_t)pck.size()) {
auto npck_it = std::next(it);
if (npck_it != rx.end()) {
// drop current packet, merge reminder with next one
auto& npck = *npck_it;
npck.insert(npck.begin(), pck.begin()+eaten, pck.end());
} else {
// erase eaten part, keep reminder
// erase eaten part, keep remainder
pck.erase(pck.begin(), pck.begin()+eaten);
{
std::lock_guard<std::mutex> l(rxMtx_);
......@@ -369,12 +369,7 @@ void
SipsIceTransport::onRxData(std::vector<uint8_t>&& buf)
{
std::lock_guard<std::mutex> l(rxMtx_);
if (rxPending_.empty())
rxPending_.emplace_back(std::move(buf));
else {
auto& last = rxPending_.back();
last.insert(std::end(last), std::begin(buf), std::end(buf));
}
}
/* Update local & remote certificates info. This function should be
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment