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

Refactor: reorganize modules #246

Merged
merged 12 commits into from
Mar 17, 2023
Merged

Conversation

josecelano
Copy link
Member

@josecelano josecelano commented Mar 17, 2023

I'm going to start working on the built-in crate documentation. A crucial point to understanding a code base is the folder/mod structure. If you want a good structure for the documentation, the docs have to mirror the code, and we cannot have good documentation without having a good folder structure.

I have also removed duplicated code for the application initialization. The code was duplicated for testing.

Move apps into a "servers" module.
@josecelano josecelano force-pushed the reorganize-modules branch 2 times, most recently from 1b3ef25 to 69a09d7 Compare March 17, 2023 11:39
`protocol` nod contains logic not only for BitTorrent protocol.
There was a lot of duplicate code for app initialization between prod
and testing code.
@josecelano josecelano marked this pull request as ready for review March 17, 2023 14:00
@josecelano
Copy link
Member Author

josecelano commented Mar 17, 2023

The final folder structure:

$ tree -L 5 src/
src/
├── app.rs
├── bootstrap
│   ├── app.rs
│   ├── jobs
│   │   ├── http_tracker.rs
│   │   ├── mod.rs
│   │   ├── torrent_cleanup.rs
│   │   ├── tracker_apis.rs
│   │   └── udp_tracker.rs
│   ├── logging.rs
│   └── mod.rs
├── lib.rs
├── main.rs
├── servers
│   ├── apis
│   │   ├── mod.rs
│   │   ├── routes.rs
│   │   ├── server.rs
│   │   └── v1
│   │       ├── context
│   │       │   ├── auth_key
│   │       │   ├── mod.rs
│   │       │   ├── stats
│   │       │   ├── torrent
│   │       │   └── whitelist
│   │       ├── middlewares
│   │       │   ├── auth.rs
│   │       │   └── mod.rs
│   │       ├── mod.rs
│   │       ├── responses.rs
│   │       └── routes.rs
│   ├── http
│   │   ├── mod.rs
│   │   ├── percent_encoding.rs
│   │   ├── server.rs
│   │   └── v1
│   │       ├── extractors
│   │       │   ├── announce_request.rs
│   │       │   ├── authentication_key.rs
│   │       │   ├── client_ip_sources.rs
│   │       │   ├── mod.rs
│   │       │   └── scrape_request.rs
│   │       ├── handlers
│   │       │   ├── announce.rs
│   │       │   ├── common
│   │       │   ├── mod.rs
│   │       │   └── scrape.rs
│   │       ├── launcher.rs
│   │       ├── mod.rs
│   │       ├── query.rs
│   │       ├── requests
│   │       │   ├── announce.rs
│   │       │   ├── mod.rs
│   │       │   └── scrape.rs
│   │       ├── responses
│   │       │   ├── announce.rs
│   │       │   ├── error.rs
│   │       │   ├── mod.rs
│   │       │   └── scrape.rs
│   │       ├── routes.rs
│   │       └── services
│   │           ├── announce.rs
│   │           ├── mod.rs
│   │           ├── peer_ip_resolver.rs
│   │           └── scrape.rs
│   ├── mod.rs
│   ├── signals.rs
│   └── udp
│       ├── connection_cookie.rs
│       ├── error.rs
│       ├── handlers.rs
│       ├── mod.rs
│       ├── peer_builder.rs
│       ├── request.rs
│       └── server.rs
├── shared
│   ├── bit_torrent
│   │   ├── common.rs
│   │   ├── info_hash.rs
│   │   └── mod.rs
│   ├── clock
│   │   ├── mod.rs
│   │   ├── static_time.rs
│   │   ├── time_extent.rs
│   │   └── utils.rs
│   ├── crypto
│   │   ├── ephemeral_instance_keys.rs
│   │   ├── keys.rs
│   │   └── mod.rs
│   └── mod.rs
└── tracker
    ├── auth.rs
    ├── databases
    │   ├── driver.rs
    │   ├── error.rs
    │   ├── mod.rs
    │   ├── mysql.rs
    │   └── sqlite.rs
    ├── error.rs
    ├── mod.rs
    ├── peer.rs
    ├── services
    │   ├── mod.rs
    │   ├── statistics
    │   │   ├── mod.rs
    │   │   └── setup.rs
    │   └── torrent.rs
    ├── statistics.rs
    └── torrent.rs

28 directories, 81 files

The previous folder structure:

$ tree -L 4 src/
src/
├── apis
│   ├── mod.rs
│   ├── routes.rs
│   ├── server.rs
│   └── v1
│       ├── context
│       │   ├── auth_key
│       │   ├── mod.rs
│       │   ├── stats
│       │   ├── torrent
│       │   └── whitelist
│       ├── middlewares
│       │   ├── auth.rs
│       │   └── mod.rs
│       ├── mod.rs
│       ├── responses.rs
│       └── routes.rs
├── databases
│   ├── driver.rs
│   ├── error.rs
│   ├── mod.rs
│   ├── mysql.rs
│   └── sqlite.rs
├── http
│   ├── mod.rs
│   ├── percent_encoding.rs
│   ├── server.rs
│   └── v1
│       ├── extractors
│       │   ├── announce_request.rs
│       │   ├── authentication_key.rs
│       │   ├── client_ip_sources.rs
│       │   ├── mod.rs
│       │   └── scrape_request.rs
│       ├── handlers
│       │   ├── announce.rs
│       │   ├── common
│       │   ├── mod.rs
│       │   └── scrape.rs
│       ├── launcher.rs
│       ├── mod.rs
│       ├── query.rs
│       ├── requests
│       │   ├── announce.rs
│       │   ├── mod.rs
│       │   └── scrape.rs
│       ├── responses
│       │   ├── announce.rs
│       │   ├── error.rs
│       │   ├── mod.rs
│       │   └── scrape.rs
│       ├── routes.rs
│       └── services
│           ├── announce.rs
│           ├── mod.rs
│           ├── peer_ip_resolver.rs
│           └── scrape.rs
├── jobs
│   ├── http_tracker.rs
│   ├── mod.rs
│   ├── torrent_cleanup.rs
│   ├── tracker_apis.rs
│   └── udp_tracker.rs
├── lib.rs
├── logging.rs
├── main.rs
├── protocol
│   ├── clock
│   │   ├── mod.rs
│   │   └── time_extent.rs
│   ├── common.rs
│   ├── crypto.rs
│   ├── info_hash.rs
│   ├── mod.rs
│   └── utils.rs
├── setup.rs
├── signals.rs
├── stats.rs
├── tracker
│   ├── auth.rs
│   ├── error.rs
│   ├── mod.rs
│   ├── peer.rs
│   ├── services
│   │   ├── common.rs
│   │   ├── mod.rs
│   │   ├── statistics.rs
│   │   └── torrent.rs
│   ├── statistics.rs
│   └── torrent.rs
└── udp
    ├── connection_cookie.rs
    ├── error.rs
    ├── handlers.rs
    ├── mod.rs
    ├── peer_builder.rs
    ├── request.rs
    └── server.rs

23 directories, 75 files

I think we still have to improve many things, for example, the tracker mod. I would add folders like:

  • app/services
  • domain
  • infrastructure/database

but we can do it when we start extracting the packages or if the complexity increases.

@josecelano josecelano merged commit 2049f84 into torrust:develop Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant