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

Use libsoup3 over curl #196

Merged
merged 4 commits into from Oct 16, 2022
Merged

Use libsoup3 over curl #196

merged 4 commits into from Oct 16, 2022

Conversation

LaserEyess
Copy link
Member

@LaserEyess LaserEyess commented Aug 28, 2022

This should be working, minus the TODOs below:

  • Fix RSS stuff (just add a new SoupSession for now, I guess) Nope
  • Make sure callbacks can handle JsonObject being NULL
  • hook up error reporting back to TrgMainWindow
  • Re-add json debugging output
  • SoupLogger maybe for debugging headers/connections?
  • SSL Validation logic
  • Make sure proxies work (they should work transparently?) later

closes #147 (I think)

@LaserEyess
Copy link
Member Author

??? Message is already in session queue

so, somehow this error is being raised. My best guess is because session_id_callback is wrong somehow. There are other issues with this, but I think some of them stem from this.

@LaserEyess LaserEyess linked an issue Aug 28, 2022 that may be closed by this pull request
@LaserEyess LaserEyess force-pushed the libsoup branch 2 times, most recently from 30d547b to d809bea Compare August 28, 2022 14:38
@LaserEyess LaserEyess force-pushed the libsoup branch 10 times, most recently from bf83496 to 80bc17a Compare September 25, 2022 21:05
@LaserEyess LaserEyess changed the title WIP: Use libsoup3 over curl Use libsoup3 over curl Sep 25, 2022
@LaserEyess
Copy link
Member Author

LaserEyess commented Sep 26, 2022

This is feature complete (minus RSS which I don't want to do) and ready for review.

Forgot about SSL lol

@LaserEyess LaserEyess force-pushed the libsoup branch 3 times, most recently from acb7faf to 17c9d00 Compare October 2, 2022 12:48
src/trg-client.c Outdated Show resolved Hide resolved
src/trg-client.c Outdated Show resolved Hide resolved
src/trg-client.c Outdated Show resolved Hide resolved
src/trg-client.c Outdated Show resolved Hide resolved
@TingPing
Copy link
Member

TingPing commented Oct 2, 2022

I don't have a ton to say, honestly this looks excellent. I think you've done really well with all the error handling.

@LaserEyess
Copy link
Member Author

I appreciate the review, I'm glad my first attempt at using libsoup didn't end in disaster. Unfortunately, unconditionally calling the callback like this code now does is wrong. I think I'm missing how updateSerial and connid (which I removed...) work to ensure that data is consistent when switching sessions. I assumed it wouldn't matter, but that's clearly wrong.

I need to re-add that logic in a more intelligent way and then do more testing with ASAN since I seem to be getting a lot of UAF bugs.

meson.build Show resolved Hide resolved
@LaserEyess LaserEyess force-pushed the libsoup branch 2 times, most recently from f574c7e to a0c058a Compare October 8, 2022 13:17
@LaserEyess
Copy link
Member Author

Saving this for my own reference later:

When using json_parser_load_from_stream_async(), it runs in a separate thread to get "async" capabilities. libsoup, in theory, should support reading a GInputStream from soup_session_send_finish() , but it does not. See this libsoup issue. So, instead of doing those two callbacks in succession, we have to do soup_session_send_and_read_async() and then take the resulting GBytes and turn them into something that json_parser_load_from_data() can read.

There is the potential to switch back to json_parser_load_from_stream_async() but we'll see how this one works for now.

LaserEyess and others added 4 commits October 9, 2022 10:43
Previously it used a special #define to indicate that something had gone
wrong, which didn't really seem practical. So, instead return a boolean
for success/failure and explicitly pass an error message on what the
failure was.
libsoup is a gobject based API with async that integrates well into the
glib mainloop. The current curl threadpool implementation has a high
amount of latency and is somewhat complex, so this simplifies a lot of
code as well as adding a gobject based library for further extension.

The changes can be summarized as the following

1. remove the threadpool, and curl handling
2. Vastly simplify trg_request and make it private, as well as removing
   the ability to do anything but handle JSON RPC
3. Put a SoupSession into TrgClient and allow that to handle all
   connections to the daemon
4. Arrange a series of callbacks for async RPC as well as JSON loading
   of results (see comment in src/trg-client.c)
5. Set up new error handling for bad requests
6. Clean up the rest of the code base to work with the above changes.

Since this commit is very complex, even though it isn't 1:1 feature
complete with the old curl implementation, other things will be added as
separate commits for easier reviewing.

This commit additionally bumps glib to 2.70 for GUri usage

Co-Authored-By: Patrick Griffis <pgriffis@igalia.com>
This function existed previously but was unused, now it is more useful
and flexible. Some slight code de-duplication is possible
This uses the SoupLogger functionality to add logging support to RPC
calls if $TRG_CLIENT_DEBUG is set. This effect is also documented inside
of the man page.
@LaserEyess LaserEyess force-pushed the libsoup branch 2 times, most recently from 719b95a to 8c6d499 Compare October 12, 2022 13:05
priv->username = trg_prefs_get_string(prefs, TRG_PREFS_KEY_USERNAME, TRG_PREFS_CONNECTION);
priv->url = g_uri_parse(uri_str, G_URI_FLAGS_NONE, &uri_err);
if (uri_err) {
g_mutex_unlock(&priv->configMutex);
Copy link
Member

@TingPing TingPing Oct 16, 2022

Choose a reason for hiding this comment

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

You might be interested in the GMutexLocker API. Nothing wrong here but I find it nicer to use.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it should be possible to remove all the locking since we can restrict TrgPrefs to a single thread. That's for a later time though.

Copy link
Member

@TingPing TingPing left a comment

Choose a reason for hiding this comment

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

Looks great.

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.

Adding torrents is awfully slow
2 participants