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

[search] Wait for replies from client before sending more data #6640

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

WinterSolstice8
Copy link
Member

I affirm:

  • I understand that if I do not agree to the following points by completing the checkboxes my PR will be ignored.
  • I understand I should leave resolving conversations to the LandSandBoat team so that reviewers won't miss what was said.
  • I have read and understood the Contributing Guide and the Code of Conduct.
  • I have tested my code and the things my code has changed since the last commit in the PR and will test after any later commits.

What does this pull request do?

Apparently we are supposed to expect a reply and to wait for it. Otherwise bad things happen. (see #6633)

Steps to test these changes

search linkshell, party, /sea all, search comment, AH item list, AH sale list, AH detailed sale list on 2+ clients at a time with no errors on windows and linux

Apparently we are supposed to expect a reply and to wait for it. Otherwise bad things happen.

searchPackets.pop_front();

encrypt(length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not relevant for this PR, but as future points: Should we:

  • make searchPacket more abstract as OwnedSpan or similar
  • make searchPacket more of it's own thing, where it can encrypt itself and we then just stuff it into the buffer, etc.
  • Rename it to SearchPacket
  • We now have data_ and searchPackets - is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

We now have data_ and searchPackets - is this necessary?
I suppose no, if we boost the internal buffer size of searchPackets to 4096 we could encrypt them ahead of time.

do_read();

deadline_.expires_after(std::chrono::milliseconds(2000));
deadline_.expires_after(std::chrono::milliseconds(10000)); // AH searches can take quite a while
Copy link
Contributor

Choose a reason for hiding this comment

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

While I'm looking at this - what is this actually the deadline for? C2S packet, db access, S2C packet?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was originally intended as a way to close a hung socket, but now it serves a few more purposes

If the query simply takes too long in general it will die, though that was not intended. There are several points where we could be waiting forever on a socket and we don't want to due to malicious actors.

I suppose we may want to repurpose it into the total lifespan of a single request, with a shorter timeout for the original open.

Open -> few hundred MS waiting on arrival of first data packet -> close if it never comes
Open -> few hundred MS waiting on arrival of first data packet -> get request-> send reply -> we are now waiting again for a reply that could never come. Repeat send reply -> get request a few times and this could be waiting a long time with someone with a malicious attack.

@@ -40,4 +40,38 @@ struct search_req
uint8 commentType;
};

class searchPacket
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future, we might want to look at making this more abstract, or more specialised.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, it's probably useful elsewhere

@@ -110,4 +110,6 @@ class search_handler
auto _HandleSearchRequest() -> search_req;

blowfish_t blowfish;

std::deque<searchPacket> searchPackets;
Copy link
Contributor

Choose a reason for hiding this comment

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

Under what circumstances will we end up with more than a couple of packets in here?

Copy link
Member Author

Choose a reason for hiding this comment

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

AH list item packets are 20~ bytes and there are several hundred items in most equipment categories. So probably a good chunk of the time.

Copy link
Member Author

Choose a reason for hiding this comment

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

uint8 PacketsCount = (uint8)((ItemList.size() / 20) + (ItemList.size() % 20 != 0) + (ItemList.empty()));

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, maybe it is 20 items per chunk. Still a good amount.

@zach2good zach2good merged commit 74ab602 into LandSandBoat:base Jan 3, 2025
14 checks passed
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