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

Free-form text rejection message sent back to the caller #1170

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

ethouris
Copy link
Collaborator

@ethouris ethouris commented Mar 5, 2020

The STREAMID extension field together with associated SRTO_STREAMID option is reused for the purpose of returning the error message.

USAGE:

The listener callback handler is allowed to set the streamid string either through SRTO_STREAMID option or UDT::setstreamid extension function on the connecting socket passed to the handler. This very message will be then able to be extracted from the connector socket through the same option (or UDT::getstreamid).

Note that on the caller side the user should get the STREAMID value. If this is not empty, it should contain a string message that the server has passed to the caller.

The srt-test-live application contains the example hook that simply rejects every connection with customizable error code and message. The caller side should display it.

Addresses partially #1292

@ethouris ethouris added Type: Enhancement Indicates new feature requests [apps] Area: Test applications related improvements [core] Area: Changes in SRT library core Impact: High labels Mar 5, 2020
@ethouris ethouris requested a review from maxsharabayko March 5, 2020 18:04
@ethouris ethouris self-assigned this Mar 5, 2020
// it's already done during handshake serialization.

// Now check the obligatory HS flags. HSX is required, KMX and CONFIG optional.
int ext_flags = SrtHSRequest::SRT_HSTYPE_HSFLAGS::unwrap(hs.m_iType);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just inverted order, while the size check is for not just the plain handshake, but + the HSREQ extension. Basic size doesn't have to be checked - it was done already when deserializing the handshake. But then the flag should be checked first because with the flag it should grant that it also contains appropriate extensions.


if (contents.size() >= size_limit)
{
contents = "#!::="; // size error
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just came to my mind: probably this isn't possible here, as the size limit should be checked when setting streamid.

@ethouris ethouris marked this pull request as ready for review March 12, 2020 14:49
@ethouris ethouris added this to the v1.5.0 milestone Mar 12, 2020
@@ -227,23 +227,34 @@ enum UDTRequestType

// Errors reported by the peer, also used as useless error codes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors reported by the peer, also used as useless error codes

"Useless" or "useful"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment comes from times when these codes were useless indeed. This can be now commented better.

srtcore/core.h Outdated
@@ -1530,7 +1532,10 @@ class CUDT

int processData(CUnit* unit);
void processClose();
SRT_REJECT_REASON processConnectRequest(const sockaddr_any& addr, CPacket& packet);

/// Returns: URQ code, possibly containing reject reason
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doxygen style requires:

/// @returns URQ code, possibly containing reject reason

srtcore/core.cpp Outdated
Comment on lines 10594 to 10596
int error = SRT_REJ_UNKNOWN;
string streaminfo_msg;
int result = s_UDTUnited.newConnection(m_SocketID, addr, packet, (hs), (error), (streaminfo_msg));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you get the contents of STREAM_ID. To put it into the response handshake?
How was it done before, if it was?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't. That's a new thing here. Previously the failure response handshake contained no extensions. This is copying it back in order to pass it in case when the user has set some contents here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is something that we decided not to do at the moment.
There is no precedure for this defined yet.

Comment on lines 249 to 255
inline int RejectReasonForURQ(UDTRequestType req)
{
if (req < URQ_FAILURE_TYPES || req - URQ_FAILURE_TYPES >= SRT_REJ__SIZE)
if (req < URQ_FAILURE_TYPES)
return SRT_REJ_UNKNOWN;
return SRT_REJECT_REASON(req - URQ_FAILURE_TYPES);

if (req < URQ_SERVER_FAILURE_TYPES && req - URQ_FAILURE_TYPES >= SRT_REJ_E_SIZE)
return SRT_REJ_UNKNOWN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the second if can be simplified to just:

if (req - URQ_FAILURE_TYPES >= SRT_REJ_E_SIZE)
    return SRT_REJ_UNKNOWN;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, wrong. This will change the behavior when req > URQ_SERVER_FAILURE_TYPES. This condition is in order to embrace the range between SRT_REJ_E_SIZE and SRT_REJC_SERVER (for the value of req - URQ_FAILURE_TYPES).

Copy link
Collaborator

@stevomatthews stevomatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor edits to doc.

srtcore/core.cpp Outdated
Comment on lines 11151 to 11160
int CUDT::rejectReason(SRTSOCKET u, int value)
{
CUDTSocket* s = s_UDTUnited.locateSocket(u);
if (!s || !s->m_pUDT)
return APIError(MJ_NOTSUP, MN_SIDINVAL);

if (value < SRT_REJC_SERVER)
return APIError(MJ_NOTSUP, MN_INVAL);

s->m_pUDT->m_RejectReason = value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SRT_REJC_SERVER = 1000 (see srt.h)

srt_setrejectreason(..) should return error if the value >=2000 is passed.
The values below are SRT internal.

if (value < SRT_REJC_SERVER) does not protect from this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I am probably confused by SRT API and SRT protocol error ranges. 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a confusion, so let me explain:

The rejection code is passed through the URQ field in the handshake. For this number the ranges are valid codes, below 1000. Since 1000 on there start values of rejection codes, system ones this time, and those are these collected in SRT_REJECT_REASON. The code is then 1000 + the reject reason. Therefore for this field the server and user codes will be shifted by 2000 and 3000 respectively.

Translation from URQ into the rejection code is URQ - 1000, however:

  • Codes from the system region (0 to 999) result in the system error code, unless the value is outside the system rejection values, in which case it renders to UNKNOWN
  • Otherwise pass the code as is, just doing URQ - 1000.

@maxsharabayko
Copy link
Collaborator

Do I understand this correctly?

SRT Protocol Error ranges (transmitted in the "Handshake Type" field)

  • [1000 - 2000] - SRT rejection codes (like bad passphrase)
  • [2000 - 3000] - Well-Defined listener provided error codes (likely HTTP Status codes)
  • [3000 - 4000] - User-Defined Listener provided error codes (custom application specific)

SRT API Error ranges

  • [1000 - 2000] - Well-Defined listener provided error codes (likely HTTP Status codes)
  • [2000 - 3000] - User-Defined Listener provided error codes (custom application specific)

@ethouris
Copy link
Collaborator Author

Yes, that's correct, I'd just add lacking parrts:

For the handshake field, values between -3 and 1 are valid request types. Errors in general start with 1000.

For the rejection code [0 - 1000] are reserved for system and values up to 15 are currently in use.

@ethouris ethouris marked this pull request as draft May 15, 2020 10:45
@ethouris ethouris changed the title Enhanced and customizable reject reason Free-form text rejection message sent back to the caller May 19, 2020
@maxsharabayko maxsharabayko modified the milestones: v1.5.0, v1.5.1 Jun 23, 2020
@mbakholdina mbakholdina modified the milestones: v1.5.1, Backlog May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[apps] Area: Test applications related improvements [core] Area: Changes in SRT library core Priority: High Type: Enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants