@@ -2629,6 +2629,9 @@ bool srt::CUDT::interpretSrtHandshake(const CHandShake& hs,
26292629 {
26302630 // Cryptographic modes mismatch. Not acceptable at all.
26312631 m_RejectReason = SRT_REJ_CRYPTO;
2632+ LOGC (cnlog.Error ,
2633+ log << CONID ()
2634+ << " interpretSrtHandshake: KMREQ result: Bad crypto mode - rejecting" );
26322635 return false ;
26332636 }
26342637#endif
@@ -3682,11 +3685,23 @@ void srt::CUDT::startConnect(const sockaddr_any& serv_addr, int32_t forced_isn)
36823685 cst = processRendezvous (&response, serv_addr, RST_OK, (reqpkt));
36833686 if (cst == CONN_CONTINUE)
36843687 continue ;
3685- break ;
3688+
3689+ // Just in case it wasn't set, set this as a fallback
3690+ if (m_RejectReason == SRT_REJ_UNKNOWN)
3691+ m_RejectReason = SRT_REJ_ROGUE;
3692+
3693+ // rejection or erroneous code.
3694+ reqpkt.setLength (m_iMaxSRTPayloadSize);
3695+ reqpkt.setControl (UMSG_HANDSHAKE);
3696+ sendRendezvousRejection (serv_addr, (reqpkt));
36863697 }
36873698
36883699 if (cst == CONN_REJECT)
3700+ {
3701+ HLOGC (cnlog.Debug ,
3702+ log << CONID () << " startConnect: REJECTED by processConnectResponse - sending SHUTDOWN" );
36893703 sendCtrl (UMSG_SHUTDOWN);
3704+ }
36903705
36913706 if (cst != CONN_CONTINUE && cst != CONN_CONFUSED)
36923707 break ; // --> OUTSIDE-LOOP
@@ -3873,6 +3888,11 @@ bool srt::CUDT::processAsyncConnectRequest(EReadStatus rst,
38733888 LOGC (cnlog.Warn ,
38743889 log << CONID ()
38753890 << " processAsyncConnectRequest: REJECT reported from processRendezvous, not processing further." );
3891+
3892+ if (m_RejectReason == SRT_REJ_UNKNOWN)
3893+ m_RejectReason = SRT_REJ_ROGUE;
3894+
3895+ sendRendezvousRejection (serv_addr, (request));
38763896 status = false ;
38773897 }
38783898 }
@@ -3925,6 +3945,24 @@ bool srt::CUDT::processAsyncConnectRequest(EReadStatus rst,
39253945 return status;
39263946}
39273947
3948+ void srt::CUDT::sendRendezvousRejection (const sockaddr_any& serv_addr, CPacket& r_rsppkt)
3949+ {
3950+ // We can reuse m_ConnReq because we are about to abandon the connection process.
3951+ m_ConnReq.m_iReqType = URQFailure (m_RejectReason);
3952+
3953+ // Assumed that r_rsppkt refers to a packet object that was already prepared
3954+ // to be used for storing the handshake there.
3955+ size_t size = r_rsppkt.getLength ();
3956+ m_ConnReq.store_to ((r_rsppkt.m_pcData ), (size));
3957+ r_rsppkt.setLength (size);
3958+
3959+ HLOGC (cnlog.Debug , log << CONID () << " sendRendezvousRejection: using code=" << m_ConnReq.m_iReqType
3960+ << " for reject reason code " << m_RejectReason << " (" << srt_rejectreason_str (m_RejectReason) << " )" );
3961+
3962+ setPacketTS (r_rsppkt, steady_clock::now ());
3963+ m_pSndQueue->sendto (serv_addr, r_rsppkt, m_SourceAddr);
3964+ }
3965+
39283966void srt::CUDT::cookieContest ()
39293967{
39303968 if (m_SrtHsSide != HSD_DRAW)
@@ -4427,7 +4465,25 @@ EConnectStatus srt::CUDT::processConnectResponse(const CPacket& response, CUDTEx
44274465 << " processConnectResponse: CONFUSED: expected UMSG_HANDSHAKE as connection not yet established, "
44284466 " got: "
44294467 << MessageTypeStr (response.getType (), response.getExtendedType ()));
4468+
4469+ if (response.getType () == UMSG_SHUTDOWN)
4470+ {
4471+ LOGC (cnlog.Error ,
4472+ log << CONID () << " processConnectResponse: UMSG_SHUTDOWN received, rejecting connection." );
4473+ return CONN_REJECT;
4474+ }
44304475 }
4476+
4477+ if (m_config.bRendezvous )
4478+ {
4479+ // In rendezvous mode we expect that both sides are known
4480+ // to the service operator (unlike a listener, which may
4481+ // operate connections from unknown sources). This means that
4482+ // the connection process should be terminated anyway, on
4483+ // whichever side it would happen.
4484+ return CONN_REJECT;
4485+ }
4486+
44314487 return CONN_CONFUSED;
44324488 }
44334489
0 commit comments