@@ -10748,8 +10748,8 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)
10748
10748
HLOGC(cnlog.Debug, log << "processConnectRequest: ... NOT. Rejecting because broken.");
10749
10749
return m_RejectReason;
10750
10750
}
10751
-
size_t exp_len =
10752
-
CHandShake::m_iContentSize; // When CHandShake::m_iContentSize is used in log, the file fails to link!
10751
+
// When CHandShake::m_iContentSize is used in log, the file fails to link!
10752
+
size_t exp_len = CHandShake::m_iContentSize;
10753
10753
10754
10754
// NOTE!!! Old version of SRT code checks if the size of the HS packet
10755
10755
// is EQUAL to the above CHandShake::m_iContentSize.
@@ -10927,6 +10927,11 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)
10927
10927
}
10928
10928
else
10929
10929
{
10930
+
// IMPORTANT!!!
10931
+
// If the newConnection() detects there is already a socket connection associated with the remote peer,
10932
+
// it returns the socket via `acpu`, and the `result` returned is 0.
10933
+
// Else if a new connection is successfully created, the conclusion handshake response
10934
+
// is sent by the function itself (it calls the acceptAndRespond(..)), the `acpu` remains null, the `result` is 1.
10930
10935
int error = SRT_REJ_UNKNOWN;
10931
10936
CUDT* acpu = NULL;
10932
10937
int result = uglobal().newConnection(m_SocketID, addr, packet, (hs), (error), (acpu));
@@ -10944,41 +10949,11 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)
10944
10949
LOGF(cnlog.Warn, "processConnectRequest: rsp(REJECT): %d - %s", hs.m_iReqType, srt_rejectreason_str(error));
10945
10950
}
10946
10951
10947
-
// CONFUSION WARNING!
10948
-
//
10949
-
// The newConnection() will call acceptAndRespond() if the processing
10950
-
// was successful - IN WHICH CASE THIS PROCEDURE SHOULD DO NOTHING.
10951
-
// Ok, almost nothing - see update_events below.
10952
-
//
10953
-
// If newConnection() failed, acceptAndRespond() will not be called.
10954
-
// Ok, more precisely, the thing that acceptAndRespond() is expected to do
10955
-
// will not be done (this includes sending any response to the peer).
10956
-
//
10957
-
// Now read CAREFULLY. The newConnection() will return:
10958
-
//
10959
-
// - -1: The connection processing failed due to errors like:
10960
-
// - memory alloation error
10961
-
// - listen backlog exceeded
10962
-
// - any error propagated from CUDT::open and CUDT::acceptAndRespond
10963
-
// - 0: The connection already exists
10964
-
// - 1: Connection accepted.
10965
-
//
10966
-
// So, update_events is called only if the connection is established.
10967
-
// Both 0 (repeated) and -1 (error) require that a response be sent.
10968
-
// The CPacket object that has arrived as a connection request is here
10969
-
// reused for the connection rejection response (see URQ_ERROR_REJECT set
10970
-
// as m_iReqType).
10971
-
10972
-
// The 'acpu' should be set to a new socket, if found;
10973
-
// this means simultaneously that result == 0, but it's safest to
10974
-
// check this condition only. This means that 'newConnection' found
10975
-
// that the connection attempt has already been accepted, just the
10976
-
// caller side somehow didn't get the answer. The rule is that every
10977
-
// connection request HS must be completed with a symmetric HS response,
10978
-
// so craft one here.
10979
-
10980
-
// Note that this function runs in the listener socket context, while 'acpu'
10981
-
// is the CUDT entity for the accepted socket.
10952
+
// The `acpu` not NULL means connection exists, the `result` should be 0. It is not checked here though.
10953
+
// The `newConnection(..)` only sends reponse for newly created connection.
10954
+
// The connection already exists (no new connection has been created, no response sent).
10955
+
// Send the conclusion response manually here in case the peer has missed the first one.
10956
+
// The value `result` here should be 0.
10982
10957
if (acpu)
10983
10958
{
10984
10959
// This is an existing connection, so the handshake is only needed
@@ -11029,16 +11004,31 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)
11029
11004
}
11030
11005
}
11031
11006
11032
-
// send back a response if connection failed or connection already existed
11033
-
// (or the above procedure failed)
11034
-
if (result == -1)
11007
+
if (result == 1)
11035
11008
{
11009
+
// BUG! There is no need to update write-readiness on the listener socket once new connection is accepted.
11010
+
// Only read-readiness has to be updated, but it is done so in the newConnection(..) function.
11011
+
// See PR #1831 and issue #1667.
11012
+
HLOGC(cnlog.Debug, log << "processConnectRequest: @" << m_SocketID
11013
+
<< " accepted connection, updating epoll to write-ready");
11014
+
11015
+
// New connection has been accepted or an existing one has been found. Update epoll write-readiness.
11016
+
// a new connection has been created, enable epoll for write
11017
+
// Note: not using SRT_EPOLL_CONNECT symbol because this is a procedure
11018
+
// executed for the accepted socket.
11019
+
uglobal().m_EPoll.update_events(m_SocketID, m_sPollID, SRT_EPOLL_OUT, true);
11020
+
}
11021
+
else if (result == -1)
11022
+
{
11023
+
// The new connection failed
11024
+
// or the connection already existed, but manually sending the HS response above has failed.
11025
+
// HSv4: Send the SHUTDOWN message to the peer (see PR #2010) in order to disallow the peer to connect.
11026
+
// The HSv4 clients do not interpret the error handshake response correctly.
11027
+
// HSv5: Send a handshake with an error code (hs.m_iReqType set earlier) to the peer.
11036
11028
if (hs.m_iVersion < HS_VERSION_SRT1)
11037
11029
{
11038
11030
HLOGC(cnlog.Debug, log << CONID() << "processConnectRequest: HSv4 caller, sending SHUTDOWN after rejection with "
11039
11031
<< RequestTypeStr(hs.m_iReqType));
11040
-
// The HSv4 clients do not interpret the error handshake response correctly.
11041
-
// In order to really disallow them to connect there's needed the shutdown response.
11042
11032
CPacket rsp;
11043
11033
setPacketTS((rsp), steady_clock::now());
11044
11034
rsp.pack(UMSG_SHUTDOWN);
@@ -11053,24 +11043,12 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)
11053
11043
size_t size = CHandShake::m_iContentSize;
11054
11044
hs.store_to((packet.m_pcData), (size));
11055
11045
packet.setLength(size);
11056
-
packet.m_iID = id;
11046
+
packet.m_iID = id;
11057
11047
setPacketTS(packet, steady_clock::now());
11058
11048
HLOGC(cnlog.Debug, log << "processConnectRequest: SENDING HS (a): " << hs.show());
11059
11049
m_pSndQueue->sendto(addr, packet);
11060
11050
}
11061
11051
}
11062
-
// new connection response should be sent in acceptAndRespond()
11063
-
// turn the socket writable if this is the first time when this was found out.
11064
-
else
11065
-
{
11066
-
// a new connection has been created, enable epoll for write
11067
-
HLOGC(cnlog.Debug, log << "processConnectRequest: @" << m_SocketID
11068
-
<< " connected, setting epoll to connect:");
11069
-
11070
-
// Note: not using SRT_EPOLL_CONNECT symbol because this is a procedure
11071
-
// executed for the accepted socket.
11072
-
uglobal().m_EPoll.update_events(m_SocketID, m_sPollID, SRT_EPOLL_OUT, true);
11073
-
}
11074
11052
}
11075
11053
LOGC(cnlog.Note, log << "listen ret: " << hs.m_iReqType << " - " << RequestTypeStr(hs.m_iReqType));
11076
11054
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4