diff --git a/src/db/database.h b/src/db/database.h index a9a40a0..d13c299 100644 --- a/src/db/database.h +++ b/src/db/database.h @@ -24,8 +24,20 @@ typedef struct dbConnection dbConnection; -int db_open (dbConnection **, char *cStr); -int db_close (dbConnection *); +/** + * Opens a database connection. + * @param pdb Pointer to database instance. + * @param cStr Connection string for the active driver. + * @return 0 on success; otherwise non-zero. + */ +int db_open (dbConnection **pdb, char *cStr); + +/** + * Closes the database connection. + * @param db Database instance. + * @return 0 on success; otherwise non-zero. + */ +int db_close (dbConnection *db); typedef struct { uint8_t *peer_id; @@ -37,22 +49,50 @@ typedef struct { uint16_t port; } db_peerEntry; -// adds a peer to the torrent's list. -int db_add_peer (dbConnection *, uint8_t [20], db_peerEntry*); - -/* - * lst: pointer to an array whose maximum size is passed to sZ. - * sZ returns the amount of peers returned. +/** + * Adds/Updates the list of peers. + * @param db The database's instance. + * @param hash The info_hash of the torrent. + * @param pE Peer's information. + * @return 0 on success; otherwise non-zero. */ -int db_load_peers (dbConnection *, uint8_t [20], db_peerEntry *lst, int *sZ); - -int db_get_stats (dbConnection *, uint8_t [20], int32_t *seeders, int32_t *leechers, int32_t *completed); +int db_add_peer (dbConnection *db, uint8_t hash[20], db_peerEntry *pE); /** - * Calculates Stats, Removes expired data. + * Loads peers for the requested torrent. + * @param db Database instance. + * @param hash The info_hash of the requested torrent. + * @param lst A allocated array to store results in. + * @param sZ in: The maximum amount of entries to load. out: Amount of loaded entries. + * @return 0 on success; otherwise non-zero. */ -int db_cleanup (dbConnection *); +int db_load_peers (dbConnection *db, uint8_t hash[20], db_peerEntry *lst, int *sZ); -int db_remove_peer (dbConnection *, uint8_t hash [20], db_peerEntry *); +/** + * Gets stats for the requested torrent. + * @param db The Database connection + * @param hash info_hash of the torrent. + * @param seeders Returns the Seeders for the requested torrent. + * @param leechers Returns the Leechers for the requested torrent. + * @param completed Returns the count of completed downloaded reported. + * @return 0 on success, otherwise non-zero. + */ +int db_get_stats (dbConnection *db, uint8_t hash[20], int32_t *seeders, int32_t *leechers, int32_t *completed); + +/** + * Maintenance routine, Calculates stats & releases space from old entries. + * @param db The database connection. + * @return 0 on success; otherwise non-zero. + */ +int db_cleanup (dbConnection *db); + +/** + * Deletes a peer from the database. + * @param db Database connection + * @param hash info_hash of the torrent. + * @param pE The peer's information. + * @return 0 on success; otherwise non-zero. + */ +int db_remove_peer (dbConnection *db, uint8_t hash [20], db_peerEntry *pE); #endif /* DATABASE_H_ */ diff --git a/src/main.c b/src/main.c index 4534c95..4549ac1 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,6 @@ #include #include "multiplatform.h" - #include "udpTracker.h" #include "tools.h" #include @@ -73,14 +72,16 @@ int main(int argc, char *argv[]) printf ("Unknown Error\n"); break; } - return 1; + goto cleanup; } printf("Press Any key to exit.\n"); getchar (); +cleanup: printf("\nGoodbye.\n"); + UDPTracker_destroy(&usi); #ifdef WIN32 diff --git a/src/settings.h b/src/settings.h index 72b91f9..f015248 100644 --- a/src/settings.h +++ b/src/settings.h @@ -40,14 +40,48 @@ typedef struct { char *buffer; } Settings; -void settings_init (Settings *, char *filename); +/** + * Initializes the settings type. + * @param s Pointer to settings to initialize. + * @param filename the settings filename. + */ +void settings_init (Settings *s, char *filename); -int settings_load (Settings *); +/** + * Loads settings from file + * @param s pointer to settings type + * @return 0 on success, otherwise non-zero. + */ +int settings_load (Settings *s); -int settings_save (Settings *); +/** + * Saves settings to file. + * @param s Pointer to settings. + * @return 0 on success; otherwise non-zero. + */ +int settings_save (Settings *s); -void settings_destroy (Settings *); +/** + * Destroys the settings "object" + * @param s Pointer to settings. + */ +void settings_destroy (Settings *s); -char* settings_get (Settings *, char *class, char *name); +/** + * Gets a setting from a Settings type. + * @param s Pointer to a setting type. + * @param class The class of the requested setting. + * @param name The name of the requested setting. + * @return The value for the requested setting, NULL if not available. + */ +char* settings_get (Settings *s, char *class, char *name); -int settings_set (Settings *, char *class, char *name, char *value); +/** + * Sets a setting in a settings type. + * @param s Pointer to settings type. + * @param class The class of the setting. + * @param name The name of the setting. + * @param value The value to set for the setting. + * @return 0 on success, otherwise non-zero. + */ +int settings_set (Settings *s, char *class, char *name, char *value); diff --git a/src/udpTracker.h b/src/udpTracker.h index 7ffb1e1..9ad9d3a 100644 --- a/src/udpTracker.h +++ b/src/udpTracker.h @@ -112,9 +112,25 @@ typedef struct udp_scrape_request ScrapeRequest; typedef struct udp_scrape_response ScrapeResponse; typedef struct udp_error_response ErrorResponse; -void UDPTracker_init (udpServerInstance *, uint16_t port, uint8_t threads); -void UDPTracker_destroy (udpServerInstance *); +/** + * Initializes the UDP Tracker. + * @param usi The Instancfe to initialize. + * @param port The port to bind the server to + * @param threads Amount of threads to start the server with. + */ +void UDPTracker_init (udpServerInstance *usi, uint16_t port, uint8_t threads); -int UDPTracker_start (udpServerInstance *); +/** + * Destroys resources that were created by UDPTracker_init. + * @param usi Instance to destroy. + */ +void UDPTracker_destroy (udpServerInstance *usi); + +/** + * Starts the Initialized instance. + * @param usi Instance to start + * @return 0 on success, otherwise non-zero. + */ +int UDPTracker_start (udpServerInstance *usi); #endif /* UDPTRACKER_H_ */