1 2 #ifndef _EXT_SEARCHES_H_ 3 #define _EXT_SEARCHES_H_ 4 5 #include <stdio.h> 6 7 // Authentication states 8 enum AUTH_STATE { 9 AUTH_OK, // Authentication successful or not needed 10 AUTH_AGAIN, // Was already successful, but needs to be retested 11 AUTH_FAILED, // Verification failed 12 AUTH_ERROR, // No reply 13 AUTH_SKIP, // Skipped, only one result needed 14 AUTH_PROGRESS, // In progress 15 AUTH_WAITING // Not yet started 16 }; 17 18 typedef void auth_callback(void); 19 20 // An address that was received as a result of an id search 21 struct result_t { 22 struct result_t *next; 23 IP addr; 24 enum AUTH_STATE state; 25 }; 26 27 // A bucket of results received when in search of an id 28 struct search_t { 29 struct search_t *next; 30 uint8_t id[SHA1_BIN_LENGTH]; 31 uint16_t done; 32 char query[QUERY_MAX_SIZE]; 33 time_t start_time; 34 struct result_t *results; 35 auth_callback *callback; 36 }; 37 38 void searches_set_auth_state(const char query[], const IP *addr, const int state); 39 struct result_t *searches_get_auth_target(char query[], IP *addr, auth_callback *callback); 40 int is_valid_result(const struct result_t *result); 41 42 void searches_setup(void); 43 void searches_free(void); 44 45 // Start a search 46 struct search_t *searches_start(const char query[]); 47 48 // Find a search by infohash, so we can add results 49 struct search_t *searches_find_by_id(const uint8_t id[]); 50 51 // Add an address to a result bucket 52 void searches_add_addr(struct search_t *search, const IP *addr); 53 54 void searches_debug(FILE *fp); 55 56 57 #endif // _EXT_SEARCHES_H_ 58