diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-16 20:05:40 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-16 20:05:40 +0000 |
commit | f49e139a6fbcde654b2130e78665e48712713612 (patch) | |
tree | 7bfa44d2ade2420938cff9b8ca7c1be92265e00a /src/gns/gnunet-service-gns.c | |
parent | 18805673bf25fb6924280a54754e240a1402f46f (diff) | |
download | gnunet-f49e139a6fbcde654b2130e78665e48712713612.tar.gz gnunet-f49e139a6fbcde654b2130e78665e48712713612.zip |
- commit after up, ty!
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 181 |
1 files changed, 105 insertions, 76 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 25e066d00..ca732c78e 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -27,14 +27,19 @@ | |||
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
29 | #include "gnunet_dns_service.h" | 29 | #include "gnunet_dns_service.h" |
30 | #include "gnunet_dnsparser_lib.h" | ||
30 | #include "gnunet_gns_service.h" | 31 | #include "gnunet_gns_service.h" |
31 | #include "gnunet-service-gns.h" | 32 | #include "gns.h" |
32 | 33 | ||
33 | 34 | ||
35 | /* TODO into gnunet_protocols */ | ||
36 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 | ||
37 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_RESULT 24 | ||
38 | |||
34 | /** | 39 | /** |
35 | * Our handle to the DNS handler library | 40 | * Our handle to the DNS handler library |
36 | */ | 41 | */ |
37 | struct GNUNET_DNS_Handle *dns_handler; | 42 | struct GNUNET_DNS_Handle *dns_handle; |
38 | 43 | ||
39 | /** | 44 | /** |
40 | * The configuration the GNS service is running with | 45 | * The configuration the GNS service is running with |
@@ -42,6 +47,11 @@ struct GNUNET_DNS_Handle *dns_handler; | |||
42 | const struct GNUNET_CONFIGURATION_Handle *GNS_cfg; | 47 | const struct GNUNET_CONFIGURATION_Handle *GNS_cfg; |
43 | 48 | ||
44 | /** | 49 | /** |
50 | * Our notification context. | ||
51 | */ | ||
52 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
53 | |||
54 | /** | ||
45 | * Task run during shutdown. | 55 | * Task run during shutdown. |
46 | * | 56 | * |
47 | * @param cls unused | 57 | * @param cls unused |
@@ -50,7 +60,7 @@ const struct GNUNET_CONFIGURATION_Handle *GNS_cfg; | |||
50 | static void | 60 | static void |
51 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 61 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
52 | { | 62 | { |
53 | GNUNET_DNS_disconnect(dns_handle); | 63 | GNUNET_DNS_disconnect(dns_handle); |
54 | } | 64 | } |
55 | 65 | ||
56 | /** | 66 | /** |
@@ -63,55 +73,74 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
63 | */ | 73 | */ |
64 | void | 74 | void |
65 | handle_dns_request(void *cls, | 75 | handle_dns_request(void *cls, |
66 | struct GNUNET_DNS_RequestHandle *rh, | 76 | struct GNUNET_DNS_RequestHandle *rh, |
67 | size_t request_length, | 77 | size_t request_length, |
68 | const char *request) | 78 | const char *request) |
69 | { | 79 | { |
70 | /** | 80 | /** |
71 | * TODO: parse request for tld | 81 | * TODO: parse request for tld |
72 | * Queue rh and gns handle (or use cls) | 82 | * Queue rh and gns handle (or use cls) |
73 | * How should lookup behave: | 83 | * How should lookup behave: |
74 | * - sync and return result or "NX" | 84 | * - sync and return result or "NX" |
75 | * - async like dht with iter | 85 | * - async like dht with iter |
76 | * Maybe provide both, useful for cli app | 86 | * Maybe provide both, useful for cli app |
77 | **/ | 87 | **/ |
78 | struct GNUNET_DNSPARSER_Packet *p; | 88 | struct GNUNET_DNSPARSER_Packet *p; |
79 | int namelen; | 89 | int namelen; |
80 | 90 | int i; | |
81 | p = GNUNET_DNSPARSER_parse (request, request_length); | 91 | char *tail; |
82 | if (NULL == p) | 92 | |
83 | { | 93 | p = GNUNET_DNSPARSER_parse (request, request_length); |
84 | fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n"); | 94 | if (NULL == p) |
85 | GNUNET_DNS_request_forward (rh); | 95 | { |
86 | return; | 96 | fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n"); |
87 | } | 97 | GNUNET_DNS_request_forward (rh); |
88 | /** | 98 | return; |
89 | * TODO factor out | 99 | } |
90 | * Check tld and decide if we or | 100 | /** |
91 | * legacy dns is responsible | 101 | * TODO factor out |
92 | **/ | 102 | * Check tld and decide if we or |
93 | for (i=0;i<p->num_queries;i++) | 103 | * legacy dns is responsible |
94 | { | 104 | **/ |
95 | namelen = strlen(&p->queries[i]->name); | 105 | for (i=0;i<p->num_queries;i++) |
96 | if (namelen >= 7) | 106 | { |
97 | { | 107 | namelen = strlen(p->queries[i].name); |
98 | /** | 108 | if (namelen >= 7) |
99 | * TODO off by 1? | 109 | { |
100 | * Move our tld/root to config file | 110 | /** |
101 | * Generate fake DNS reply that replaces .gnunet with .org | 111 | * TODO off by 1? |
102 | **/ | 112 | * Move our tld/root to config file |
103 | if (0 == strcmp((&p->queries[i]->name)+(namelen-7), ".gnunet")) | 113 | * Generate fake DNS reply that replaces .gnunet with .org |
104 | { | 114 | **/ |
105 | GNUNET_DNS_request_answer(rh, 0 /*length*/, NULL/*reply*/); | 115 | tail = p->queries[i].name+(namelen-7); |
106 | } | 116 | if (0 == strcmp(tail, ".gnunet")) |
107 | else | 117 | { |
108 | { | 118 | /* Do db lookup here. Make dht lookup if necessary */ |
109 | GNUNET_DNS_request_forward (rh); | 119 | GNUNET_DNS_request_answer(rh, 0 /*length*/, NULL/*reply*/); |
110 | } | 120 | } |
111 | } | 121 | else |
112 | } | 122 | { |
123 | GNUNET_DNS_request_forward (rh); | ||
124 | } | ||
125 | } | ||
126 | } | ||
113 | } | 127 | } |
114 | 128 | ||
129 | /*TODO*/ | ||
130 | static void | ||
131 | handle_client_record_lookup(void *cls, | ||
132 | struct GNUNET_SERVER_Client *client, | ||
133 | const struct GNUNET_MessageHeader *message) | ||
134 | { | ||
135 | } | ||
136 | |||
137 | /*TODO*/ | ||
138 | static void | ||
139 | handle_client_record_add(void *cls, | ||
140 | struct GNUNET_SERVER_Client *client, | ||
141 | const struct GNUNET_MessageHeader *message) | ||
142 | { | ||
143 | } | ||
115 | 144 | ||
116 | /** | 145 | /** |
117 | * Process GNS requests. | 146 | * Process GNS requests. |
@@ -124,35 +153,35 @@ static void | |||
124 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 153 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
125 | const struct GNUNET_CONFIGURATION_Handle *c) | 154 | const struct GNUNET_CONFIGURATION_Handle *c) |
126 | { | 155 | { |
127 | /* The IPC message types */ | 156 | /* The IPC message types */ |
128 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 157 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
129 | /* callback, cls, type, size */ | 158 | /* callback, cls, type, size */ |
130 | {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_LOOKUP, | 159 | {&handle_client_record_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP, |
131 | sizeof (struct GNUNET_GNS_Lookup)}, | 160 | 0}, |
132 | {&handle_client_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_RECORD_ADD, | 161 | /*{&handle_client_record_add, NULL, GNUNET_MESSAGE_TYPE_GNS_CLIENT_ADD, |
133 | sizeof (struct GNUNET_GNS_Record)}, | 162 | 0},*/ |
134 | {NULL, NULL, 0, 0} | 163 | {NULL, NULL, 0, 0} |
135 | }; | 164 | }; |
136 | 165 | ||
137 | nc = GNUNET_SERVER_notification_context_create (server, 1); | 166 | nc = GNUNET_SERVER_notification_context_create (server, 1); |
138 | 167 | ||
139 | /* TODO do some config parsing */ | 168 | /* TODO do some config parsing */ |
140 | 169 | ||
141 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 170 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
142 | NULL); | 171 | NULL); |
143 | /** | 172 | /** |
144 | * Do gnunet dns init here | 173 | * Do gnunet dns init here |
145 | * */ | 174 | * */ |
146 | dns_handle = GNUNET_DNS_connect(c, | 175 | dns_handle = GNUNET_DNS_connect(c, |
147 | GNUNET_DNS_FLAG_PRE_RESOLUTION, | 176 | GNUNET_DNS_FLAG_PRE_RESOLUTION, |
148 | &handle_dns_request, /* rh */ | 177 | &handle_dns_request, /* rh */ |
149 | NULL); /* Closure */ | 178 | NULL); /* Closure */ |
150 | GNUNET_SERVER_add_handlers (server, handlers); | 179 | GNUNET_SERVER_add_handlers (server, handlers); |
151 | /** | 180 | /** |
152 | * Esp the lookup would require to keep track of the clients' context | 181 | * Esp the lookup would require to keep track of the clients' context |
153 | * See dht. | 182 | * See dht. |
154 | * GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); | 183 | * GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); |
155 | **/ | 184 | **/ |
156 | } | 185 | } |
157 | 186 | ||
158 | 187 | ||