summaryrefslogtreecommitdiff
path: root/src/shared.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared.h')
-rw-r--r--src/shared.h76
1 files changed, 49 insertions, 27 deletions
diff --git a/src/shared.h b/src/shared.h
index a615f83..77c9d3f 100644
--- a/src/shared.h
+++ b/src/shared.h
@@ -47,49 +47,71 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
extern int server_sockfd;
+uint64_t get_time(void);
+
+#define TIME_SECOND (1000000000llu)
+#define TIME_MINUTE (60 * TIME_SECOND)
+#define TIME_HOUR (60 * TIME_MINUTE)
+
+// shared
+
+typedef struct job_s job_t;
+
+// database.c
+
+enum {
+ DB_INVALID,
+ DB_IN_PROGRESS,
+ DB_VALID
+};
+
+typedef struct {
+ int state;
+ uint64_t exp_time;
+ char *data;
+} db_entry_field;
+
+typedef struct {
+ uint32_t ipv4;
+
+ db_entry_field revdns, whois;
+
+ bool cached_result_valid;
+ int cached_result;
+
+ job_t *waiting_jobs;
+
+ eli_header ht_chain;
+ pthread_mutex_t mutex;
+} db_entry;
+
+db_entry *db_find(uint32_t ipv4);
+void db_destroy(void);
+
// worker.c
typedef enum {
- JOB_TEST,
JOB_REVDNS,
- JOB_WHOIS
+ JOB_WHOIS,
+ JOB_REPLY,
} job_type_t;
-typedef struct job_s job_t;
struct job_s {
job_type_t type;
- uint32_t query;
- struct sockaddr_in reply_to;
+ db_entry *entry;
+ struct sockaddr_in ret_addr; // for JOB_REPLY
+ uint32_t ipv4; // for other jobs
- eli_header list, dep_list;
- job_t *parent, *deps;
- size_t num_deps, deps_done;
- pthread_mutex_t mutex;
+ eli_header queue_list, waiting_list;
};
-job_t *job_create(void);
+job_t *job_create(job_type_t type, db_entry *entry);
+void job_destroy(job_t *job);
void job_enqueue(job_t *job);
void job_quit(void);
void *worker_main(void *unused);
-// cache.c
-
-typedef struct {
- uint32_t ipv4;
-
- char *revdns;
- uint64_t revdns_exptime; // FIXME: implement this already
- char *whois;
- uint64_t whois_exptime;
-
- eli_header ht_list;
- pthread_mutex_t mutex;
-} cache_entry_t;
-
-cache_entry_t *cache_find(uint32_t ipv4);
-void cache_destroy(void);
-
// lexer.c
typedef struct {