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

sipsess: refactor and simplify SDP negotiation state #1016

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

maximilianfridrich
Copy link
Contributor

The SDP negotiation state is now tracked in a single enum which is used as a state machine to keep track of the current state of the SDP negotiation. This makes reasoning about the SDP negotiation much easier and less error prone.

Some details about SDP offer/answer are now enforced more strictly, e.g. the first reliable non-failure response to an INVITE MUST contain an SDP offer, if the INVITE contained no offer.

Read about SDP negotiation in the excellent informational RFC 6337.

@@ -74,3 +83,4 @@ void sipsess_close_all(struct sipsess_sock *sock);
struct sip_dialog *sipsess_dialog(const struct sipsess *sess);
void sipsess_abort(struct sipsess *sess);
bool sipsess_ack_pending(const struct sipsess *sess);
enum sdp_neg_state sipsess_sdp_neg_state(const struct sipsess *sess);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the state have to be exposed to the application?

Copy link
Contributor Author

@maximilianfridrich maximilianfridrich Nov 26, 2023

Choose a reason for hiding this comment

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

I believe so. E.g. the application can check if the state is SDP_NEG_PREVIEW_ANSWER (unreliable SDP answer was sent in 1XX response) and in this case it MUST send the exact same SDP in the 200 OK. Ideally, re would not allow non RFC conformant usage, but we're not there yet. That would take more refactoring that could be done in a subsequent step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following BareSIP PR makes use of the state:

@maximilianfridrich maximilianfridrich marked this pull request as ready for review November 27, 2023 12:57
src/sipsess/connect.c Outdated Show resolved Hide resolved
@maximilianfridrich maximilianfridrich force-pushed the sdp_neg_refactoring branch 4 times, most recently from 5e945aa to daae405 Compare November 28, 2023 09:40
src/sipsess/reply.c Outdated Show resolved Hide resolved
@cspiel1
Copy link
Collaborator

cspiel1 commented Nov 29, 2023

Looks good now.

SDP_NEG_REMOTE_OFFER = (1 << 1), /** SDP offer received */
SDP_NEG_PREVIEW_ANSWER = (1 << 2), /** SDP preview answer sent */
SDP_NEG_DONE = (1 << 3) /** SDP negotiation done */
};
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a "state" or "flags" ?

If it is flags then the stored value can contain a bitmask of many values ORed together.

If it is a state, the value can only contain one value and the states values 1<<N is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I thought it could be useful in some cases to OR the values (like flags), but I didn't end up using it anywhere. I have removed the explicit enum values.

@maximilianfridrich maximilianfridrich force-pushed the sdp_neg_refactoring branch 2 times, most recently from 5dff203 to f03d626 Compare December 11, 2023 07:03
The SDP negotiation state is now tracked in a single enum which is used
as a state machine to keep track of the current state of the SDP
negotiation.
@sreimers sreimers merged commit 89700a8 into baresip:main Jan 2, 2024
35 checks passed
@maximilianfridrich maximilianfridrich deleted the sdp_neg_refactoring branch February 12, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants