Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug when crafting HS response after received waveahand version 4 #354

Merged
merged 4 commits into from
Jun 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,22 @@ bool CUDT::createSrtHandshake(ref_t<CPacket> r_pkt, ref_t<CHandShake> r_hs,
CPacket& pkt = *r_pkt;
CHandShake& hs = *r_hs;

HLOGC(mglog.Debug, log << "createSrtHandshake: have buffer size=" << pkt.getLength() << " kmdata_wordsize=" << kmdata_wordsize);
// This function might be called before the opposite version was recognized.
// Check if the version is exactly 4 because this means that the peer has already
// sent something - asynchronously, and usually in rendezvous - and we already know
// that the peer is version 4. In this case, agent must behave as HSv4, til the end.
if (m_ConnRes.m_iVersion == HS_VERSION_UDT4)
{
hs.m_iVersion = HS_VERSION_UDT4;
if (hs.m_extension)
{
// Should be impossible
LOGC(mglog.Fatal, log << "createSrtHandshake: IPE: EXTENSION SET WHEN peer reports version 4 - fixing...");
hs.m_extension = false;
}
}

HLOGC(mglog.Debug, log << "createSrtHandshake: have buffer size=" << pkt.getLength() << " kmdata_wordsize=" << kmdata_wordsize << " version=" << hs.m_iVersion);

// values > URQ_CONCLUSION include also error types
// if (hs.m_iVersion == HS_VERSION_UDT4 || hs.m_iReqType > URQ_CONCLUSION) <--- This condition was checked b4 and it's only valid for caller-listener mode
Expand All @@ -1553,6 +1568,10 @@ bool CUDT::createSrtHandshake(ref_t<CPacket> r_pkt, ref_t<CHandShake> r_hs,
// here, it's already too late (it should've been advertised before getting the first
// handshake message with KMREQ).
}
else
{
hs.m_iType = UDT_DGRAM;
}

size_t hs_size = pkt.getLength();
hs.store_to(pkt.m_pcData, Ref(hs_size));
Expand Down Expand Up @@ -2939,6 +2958,11 @@ bool CUDT::processAsyncConnectRequest(EConnectStatus cst, const CPacket& respons
return false;
}
}
else if (cst == CONN_REJECT)
{
LOGC(mglog.Error, log << "processAsyncConnectRequest: REJECT reported from HS processing, not processing further.");
return false;
}
else
{
// (this procedure will be also run for HSv4 rendezvous)
Expand Down Expand Up @@ -7831,6 +7855,15 @@ int CUDT::processConnectRequest(const sockaddr* addr, CPacket& packet)
CHandShake hs;
hs.load_from(packet.m_pcData, packet.getLength());

// XXX MOST LIKELY this hs should be now copied into m_ConnRes field, which holds
// the handshake structure sent from the peer (no matter the role or mode).
// This should simplify the createSrtHandshake() function which can this time
// simply write the crafted handshake structure into m_ConnReq, which needs no
// participation of the local handshake and passing it as a parameter through
// newConnection() -> acceptAndRespond() -> createSrtHandshake(). This is also
// required as a source of the peer's information used in processing in other
// structures.

int32_t cookie_val = bake(addr);

HLOGC(mglog.Debug, log << "processConnectRequest: new cookie: " << hex << cookie_val);
Expand Down