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

0.7.0 Legos #17

Merged
merged 45 commits into from
Sep 12, 2024
Merged

0.7.0 Legos #17

merged 45 commits into from
Sep 12, 2024

Conversation

0xAlcibiades
Copy link
Member

@0xAlcibiades 0xAlcibiades commented Sep 10, 2024

🚀 0.7.0 Legos - Hyper 1.0 Migration and Server Modularization

This PR implements a major overhaul of hyper-server, migrating to hyper 1.0 and introducing a more modular, composable architecture. These changes aim to improve flexibility, performance, and maintainability while aligning with the latest hyper ecosystem.

Overall principle:

tokio::net::TcpListener -> rustls::TlsAcceptor -> hyper_util::server::conn::auto -> hyper::service::Service -> tower::Service (optionally) -> tower::steer (by request header, optionally) -> then onwards towards tower::* && tonic::* && axum::* && tungstenite::* && etc::towerlike::*

Leveraging streaming APIs throughout, exposing native builder APIs for complete control at each layer.

🔄 Hyper 1.0 Migration

  • Updated to hyper 1.0, addressing breaking changes as outlined in the hyper upgrade guide
  • Replaced hyper::Body usage with appropriate alternatives (e.g., impl Body, BoxBody)
  • Migrated from hyper::Server to hyper-util::server::conn::auto::Builder
  • Updated Service and service_fn implementations to use hyper::service

✅ Completed Modularization (This PR)

  1. 🧱 Scaffold (WAR-653): Established the new modular architecture
  2. 🌐 TcpListener (WAR-654): Implemented a flexible TCP listening mechanism
  3. 🔒 rustls Acceptor (WAR-655): Integrated TLS support using rustls
  4. 🔧 Generic hyper service (WAR-656): Integrates well with the new hyper services structure
  5. 🏗️ Generic tower service (WAR-657): Integrates well with the tower services and layers ecosystem
    (and thereby tonic and axum)
  6. 🧪 Full test coverage (WAR-658): Expanded test suite for new components
  7. 🧸 toy-server (WAR-662): Developed a sample server showcasing the new architecture which was on 0x alicibades/toy server #16

🚧 Pending Tasks (Future PRs)

  • 🎨 Ergonomic refinement
  • 🔝 Integration of top-level server
  • 📊 Examples & Benchmarks
  • 📚 Documentation & Readme updates

🔍 Key Changes

  • Improved modularity allowing for easier customization of server components
  • Enhanced composability at different layers (TCP, TLS, HTTP)
  • Updated examples to demonstrate usage with the new architecture
  • Maintained compatibility with the latest axum and tonic ecosystems via tower integration

👀 Review Focus

  • Migration approach and adherence to hyper 1.0 best practices
  • Architectural decisions in the new modular structure
  • Backwards compatibility considerations
  • Test coverage and quality

💡 This PR marks a significant evolution of hyper-server, aligning it with hyper 1.0 and introducing a more flexible architecture. Your insights are crucial as we refine this new foundation!

@0xAlcibiades 0xAlcibiades marked this pull request as draft September 10, 2024 21:30
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 85.14286% with 104 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/error.rs 0.00% 35 Missing ⚠️
src/tcp.rs 79.06% 27 Missing ⚠️
src/tls.rs 90.25% 27 Missing ⚠️
src/http.rs 93.92% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

src/tcp.rs Outdated
Copy link

Choose a reason for hiding this comment

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

  • Interesting fairly low-level management of the TCP stream, i guess in terms of handling errors and interception.
  • The tokio::stream_iter!() also looks like a useful tool, particularly in tests
  • too bad yield only works within async, would love to see the generator proposal make it to prod rust. (i.e. python-like yield generators, present in many other languages); imagine some borrow-checker issues to work around given the arbitrarily complex finite state machine it might generate. Probably would need pins and possibly unsafe under the covers.

@0xAlcibiades 0xAlcibiades changed the title WIP: server rework 0.7.0 Legos Sep 11, 2024
@0xAlcibiades 0xAlcibiades marked this pull request as ready for review September 11, 2024 02:05
@0xAlcibiades 0xAlcibiades changed the base branch from master to v0.7.0-dev September 11, 2024 02:12
Copy link

@tr8dr tr8dr left a comment

Choose a reason for hiding this comment

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

very nice!

I learned quite a bit last week and then yet some more stuff (other patterns in tokio for example).

@megsdevs
Copy link
Contributor

Very nice! I like how you don't wrap anything unnecessarily which reduces complexity, so we can use the native blocks during setup, tokio listener, hyper stream, tower service builder and rustls config.
Definitely would be nice to have the option to build server in a one liner though, with intuitive builder configuration :)

@megsdevs
Copy link
Contributor

megsdevs commented Sep 11, 2024

nit: remove or update the old changelog

@megsdevs
Copy link
Contributor

  • consider having rustls under a feature, might consider adding equivalent openssl if we release, but also nice to keep smol

README.md Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/fuse.rs Show resolved Hide resolved
Copy link

@trbritt trbritt left a comment

Choose a reason for hiding this comment

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

I've not dug deep on the networking rabbit hole of rust, yet the design seems minimal yet powerful; clean abstractions, and clean usages. Only gripe is that there are some files that don't have a single comment or doc string, would be useful for futureproofing this against later confusion (from yourself, but also for us later who will ues this lol)

Cargo.toml Show resolved Hide resolved
src/error.rs Show resolved Hide resolved
src/tls.rs Show resolved Hide resolved
@0xAlcibiades 0xAlcibiades changed the base branch from v0.7.0-dev to master September 12, 2024 08:31
@0xAlcibiades 0xAlcibiades merged commit 4706e3f into master Sep 12, 2024
1 check passed
@0xAlcibiades 0xAlcibiades deleted the 0xalcibiades/war-653-scaffold branch September 12, 2024 08:36
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.

5 participants