Skip to content

Use resume gateway url for session resuming#82

Merged
lcsmuller merged 1 commit intodevfrom
feat/resume_gateway_url
Sep 1, 2022
Merged

Use resume gateway url for session resuming#82
lcsmuller merged 1 commit intodevfrom
feat/resume_gateway_url

Conversation

@lcsmuller
Copy link
Collaborator

Discord will be using a different URL for resuming purposes, this commit
implements that

What?

Use Discord resume gateway url for session resuming

Why?

In the future it is expected this URL to be used for resuming session purposes

How?

The URL is parsed and kept internally, and the client should attempt to reconnect to that URL if it wants to resume to the previous session.

Testing?

The client has been shutdown without sending a WebSockets CLOSE opcode to Discord, and then managed to resume to the ongoing session.

@lcsmuller lcsmuller added the missing feature Missing Discord API feature label Aug 30, 2022
@lcsmuller lcsmuller requested review from a user, Anotra and HackerSmacker August 30, 2022 01:53
@lcsmuller lcsmuller self-assigned this Aug 30, 2022
@Anotra
Copy link
Contributor

Anotra commented Aug 30, 2022

Attempting to resume always results in "Invalid session, can't resume."

Discord will be using a different URL for resuming purposes, this commit
implements that
@lcsmuller lcsmuller force-pushed the feat/resume_gateway_url branch from 84d24ea to 7c10c0e Compare August 31, 2022 00:29
@lcsmuller
Copy link
Collaborator Author

lcsmuller commented Aug 31, 2022

Attempting to resume always results in "Invalid session, can't resume."

@Anotra Should be fixed now, can you give it a try?

@ghost
Copy link

ghost commented Sep 1, 2022

Took a look at it, I think is pretty good. Wanted to verify that the snprintf on line 224 of discord-gateway.c would always add a NULL byte, so did some testing on my own and it seems like it is.

The thing I want to make note of is that on line 705, we index something and subtract 1 from the URL length. If the URL length is 0, that will index backwards. I have doubts that the URL will be zero, but I thought I would mention it. Since I do not see this happening, it looks good to me.

@ghost
Copy link

ghost commented Sep 1, 2022

Also, In my own code, I often do out of bounds error checks with macros for every attempt to index any array (among other things). I see you have an ASSERT_NOT_OOB. I might want to suggest in the future checks for if the URL length -1 is out of bounds, as well. Like I said previously, I do not see it happening ever, but just a thought.

Copy link
Collaborator

@HackerSmacker HackerSmacker left a comment

Choose a reason for hiding this comment

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

Alright, I'm good here! Looks good to me.

@@ -688,8 +701,8 @@ _discord_gateway_session_from_json(struct discord_gateway_session *session,
int url_len = (int)f->v.len;

url_len = snprintf(session->base_url, sizeof(session->base_url),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, this part here looks good, since it's gonna get OOB-checked after the fact.

sizeof(gw->session->resume_url),
"%.*s%s" DISCORD_GATEWAY_URL_SUFFIX, url_len,
url, ('/' == url[url_len - 1]) ? "" : "/");
ASSERT_NOT_OOB(url_len, sizeof(gw->session->resume_url));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here as below -- good idea to have some checking in there.

@lcsmuller lcsmuller merged commit 646dad0 into dev Sep 1, 2022
@lcsmuller lcsmuller deleted the feat/resume_gateway_url branch September 1, 2022 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing feature Missing Discord API feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants