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

Modularize FTL modules/headers #605

Merged
merged 45 commits into from Jul 9, 2019
Merged

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented Jul 1, 2019

By submitting this pull request, I confirm the following (please check boxes, eg [X]) Failure to fill the template will close your PR:

Please submit all pull requests against the development branch. Failure to do so will delay or deny your request

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.

How familiar are you with the codebase?:

10


Since the advent of our Faster Than Light (pihole-FTL) engine, it somewhat organically grew and quickly became a complex daemon. However, instead of properly fractionating the code into clearly separated modules, we instead got two very large files FTL.h and routines.h which contained prototypes for everything.

This PR restructures our FTL engine by separating the declarations and functions into separated modules, each consisting of a .c and the corresponding .h files. These two files build modules, each corresponding to a clear piece of functionality. They can be largely maintained and developed separately from the other modules, and partially even reused in entirely different projects.

Summary of the changes in this pull request:

  1. Move definitions of global variables from FTL.h into the corresponding module headers where this is practical.
  2. Move all prototypes into the corresponding module headers. This allows us to remove the old and very large routines.h altogether.
  3. Move database related modules into a common subdirectory database/
  4. Split the old database.c file into two smaller files (database/common.c and database/query-table.c).
  5. Rename some files and functions for the sake of consistency.
  6. Move some files from their old module into a new one if they fit there better. An example is moving the function that calls stat() to obtain the physical size of the database from database.c into files.c where similar functions already exist.

DL6ER added 13 commits June 29, 2019 18:01
Signed-off-by: DL6ER <dl6er@dl6er.de>
…utines.h

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…ar as this is applicable (we do not do it for the thread pointers as this complicates linking dependencies).

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER added this to the v5.0 milestone Jul 1, 2019
DL6ER added 10 commits July 1, 2019 19:46
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…-the-fly.

Signed-off-by: DL6ER <dl6er@dl6er.de>
…fix clean target.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…ts into new subdirectory "build".

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…rectory src/api.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Makefile Outdated Show resolved Hide resolved
src/files.c Outdated Show resolved Hide resolved
src/config.h Show resolved Hide resolved
src/database/common.c Outdated Show resolved Hide resolved
src/database/network-table.c Outdated Show resolved Hide resolved
src/files.h Outdated Show resolved Hide resolved
src/timers.c Show resolved Hide resolved
.gitignore Show resolved Hide resolved
DL6ER added 7 commits July 5, 2019 12:08
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…nfig{.c/.h}

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER mentioned this pull request Jul 5, 2019
5 tasks
DL6ER added 4 commits July 6, 2019 17:03
Signed-off-by: DL6ER <dl6er@dl6er.de>
… prefer to handle the logging through the SQLite3 error callback as this ensures it cannot be missed.

Previously:
[2019-07-06 17:00:55.526 32339] SQLite3 message: statement aborts at 36: [CREATE UNIQUE INDEX network_hwaddr_idx ON network(hwaddr)] attempt to write a readonly database (8)
[2019-07-06 17:00:55.526 32339] dbquery(CREATE UNIQUE INDEX network_hwaddr_idx ON network(hwaddr)) - SQL error (8): attempt to write a readonly database
[2019-07-06 17:00:55.526 32339] check_database(8): Disabling database connection due to error
[2019-07-06 17:00:55.526 32339] unify_hwaddr(): "CREATE UNIQUE INDEX network_hwaddr_idx ON network(hwaddr)" failed!

Now:
[2019-07-06 17:00:55.526 32339] SQLite3 message: statement aborts at 36: [CREATE UNIQUE INDEX network_hwaddr_idx ON network(hwaddr)] attempt to write a readonly database (8)
[2019-07-06 17:00:55.526 32339] check_database(8): Disabling database connection due to error
[2019-07-06 17:00:55.526 32339] ERROR: unify_hwaddr() failed!

Signed-off-by: DL6ER <dl6er@dl6er.de>
… error.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
src/setupVars.h Show resolved Hide resolved
src/timers.h Show resolved Hide resolved
DL6ER added 5 commits July 7, 2019 09:45
…e we set database to false.

Signed-off-by: DL6ER <dl6er@dl6er.de>
…ld_queries_in_DB(). The function can in any way not be called when database == false as this is an exit criterion for the database thread.

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…commented.

Signed-off-by: DL6ER <dl6er@dl6er.de>
src/dnsmasq_interface.c Outdated Show resolved Hide resolved
AzureMarker and others added 2 commits July 7, 2019 15:04
@AzureMarker
Copy link
Contributor

Note that the codefactor issues are ignored, but the GitHub check is not updated.

@AzureMarker AzureMarker merged commit 5e85489 into development Jul 9, 2019
@AzureMarker AzureMarker deleted the new/modularize_headers branch July 9, 2019 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants