aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-daemon-vpn-dns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/vpn/gnunet-daemon-vpn-dns.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn-dns.c')
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.c222
1 files changed, 119 insertions, 103 deletions
diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c
index 6ccef5869..d6f842e34 100644
--- a/src/vpn/gnunet-daemon-vpn-dns.c
+++ b/src/vpn/gnunet-daemon-vpn-dns.c
@@ -52,56 +52,67 @@ struct answer_packet_list *answer_proc_tail;
52 * {{{ 52 * {{{
53 */ 53 */
54size_t 54size_t
55send_query(void* cls __attribute__((unused)), size_t size, void* buf) { 55send_query (void *cls __attribute__ ((unused)), size_t size, void *buf)
56 size_t len; 56{
57 size_t len;
58
59 /*
60 * Send the rehijack-message
61 */
62 if (restart_hijack == 1)
63 {
64 restart_hijack = 0;
57 /* 65 /*
58 * Send the rehijack-message 66 * The message is just a header
59 */ 67 */
60 if (restart_hijack == 1) 68 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) <= size);
61 { 69 struct GNUNET_MessageHeader *hdr = buf;
62 restart_hijack = 0; 70
63 /* 71 len = sizeof (struct GNUNET_MessageHeader);
64 * The message is just a header 72 hdr->size = htons (len);
65 */ 73 hdr->type = htons (GNUNET_MESSAGE_TYPE_REHIJACK);
66 GNUNET_assert(sizeof(struct GNUNET_MessageHeader) <= size); 74 }
67 struct GNUNET_MessageHeader* hdr = buf; 75 else if (head != NULL)
68 len = sizeof(struct GNUNET_MessageHeader); 76 {
69 hdr->size = htons(len); 77 struct query_packet_list *query = head;
70 hdr->type = htons(GNUNET_MESSAGE_TYPE_REHIJACK); 78
71 } 79 len = ntohs (query->pkt.hdr.size);
72 else if (head != NULL) 80
73 { 81 GNUNET_assert (len <= size);
74 struct query_packet_list* query = head; 82
75 len = ntohs(query->pkt.hdr.size); 83 memcpy (buf, &query->pkt.hdr, len);
76 84
77 GNUNET_assert(len <= size); 85 GNUNET_CONTAINER_DLL_remove (head, tail, query);
78 86
79 memcpy(buf, &query->pkt.hdr, len); 87 GNUNET_free (query);
80 88 }
81 GNUNET_CONTAINER_DLL_remove (head, tail, query); 89 else
82 90 {
83 GNUNET_free(query); 91 GNUNET_break (0);
84 } 92 len = 0;
85 else 93 }
86 { 94
87 GNUNET_break(0); 95 /*
88 len = 0; 96 * Check whether more data is to be sent
89 } 97 */
90 98 if (head != NULL)
91 /* 99 {
92 * Check whether more data is to be sent 100 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
93 */ 101 ntohs (head->pkt.hdr.size),
94 if (head != NULL) 102 GNUNET_TIME_UNIT_FOREVER_REL,
95 { 103 GNUNET_YES, &send_query, NULL);
96 GNUNET_CLIENT_notify_transmit_ready(dns_connection, ntohs(head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); 104 }
97 } 105 else if (restart_hijack == 1)
98 else if (restart_hijack == 1) 106 {
99 { 107 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
100 GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); 108 sizeof (struct GNUNET_MessageHeader),
101 } 109 GNUNET_TIME_UNIT_FOREVER_REL,
102 110 GNUNET_YES, &send_query, NULL);
103 return len; 111 }
112
113 return len;
104} 114}
115
105/* }}} */ 116/* }}} */
106 117
107 118
@@ -109,33 +120,37 @@ send_query(void* cls __attribute__((unused)), size_t size, void* buf) {
109 * Connect to the service-dns 120 * Connect to the service-dns
110 */ 121 */
111void 122void
112connect_to_service_dns (void *cls __attribute__((unused)), 123connect_to_service_dns (void *cls __attribute__ ((unused)),
113 const struct GNUNET_SCHEDULER_TaskContext *tc) { 124 const struct GNUNET_SCHEDULER_TaskContext *tc)
114 conn_task = GNUNET_SCHEDULER_NO_TASK; 125{
115 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 126 conn_task = GNUNET_SCHEDULER_NO_TASK;
116 return; 127 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
117 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n"); 128 return;
118 GNUNET_assert (dns_connection == NULL); 129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n");
119 dns_connection = GNUNET_CLIENT_connect ("dns", cfg); 130 GNUNET_assert (dns_connection == NULL);
120 /* This would most likely be a misconfiguration */ 131 dns_connection = GNUNET_CLIENT_connect ("dns", cfg);
121 GNUNET_assert(NULL != dns_connection); 132 /* This would most likely be a misconfiguration */
122 GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); 133 GNUNET_assert (NULL != dns_connection);
123 134 GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
124 /* We might not yet be connected. Yay, mps. */ 135 GNUNET_TIME_UNIT_FOREVER_REL);
125 if (NULL == dns_connection) return; 136
126 137 /* We might not yet be connected. Yay, mps. */
127 /* If a packet is already in the list, schedule to send it */ 138 if (NULL == dns_connection)
128 if (head != NULL) 139 return;
129 GNUNET_CLIENT_notify_transmit_ready(dns_connection, 140
130 ntohs(head->pkt.hdr.size), 141 /* If a packet is already in the list, schedule to send it */
131 GNUNET_TIME_UNIT_FOREVER_REL, 142 if (head != NULL)
132 GNUNET_YES, 143 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
133 &send_query, 144 ntohs (head->pkt.hdr.size),
134 NULL); 145 GNUNET_TIME_UNIT_FOREVER_REL,
135 else if (restart_hijack == 1) 146 GNUNET_YES, &send_query, NULL);
136 { 147 else if (restart_hijack == 1)
137 GNUNET_CLIENT_notify_transmit_ready(dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); 148 {
138 } 149 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
150 sizeof (struct GNUNET_MessageHeader),
151 GNUNET_TIME_UNIT_FOREVER_REL,
152 GNUNET_YES, &send_query, NULL);
153 }
139} 154}
140 155
141/** 156/**
@@ -143,33 +158,34 @@ connect_to_service_dns (void *cls __attribute__((unused)),
143 * handle it 158 * handle it
144 */ 159 */
145void 160void
146dns_answer_handler(void* cls __attribute__((unused)), const struct GNUNET_MessageHeader *msg) { 161dns_answer_handler (void *cls
147 /* the service disconnected, reconnect after short wait */ 162 __attribute__ ((unused)),
148 if (msg == NULL) 163 const struct GNUNET_MessageHeader *msg)
149 { 164{
150 GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO); 165 /* the service disconnected, reconnect after short wait */
151 dns_connection = NULL; 166 if (msg == NULL)
152 conn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 167 {
153 &connect_to_service_dns, 168 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
154 NULL); 169 dns_connection = NULL;
155 return; 170 conn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
156 } 171 &connect_to_service_dns, NULL);
157 172 return;
158 /* the service did something strange, reconnect immediately */ 173 }
159 if (msg->type != htons(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS)) 174
160 { 175 /* the service did something strange, reconnect immediately */
161 GNUNET_break (0); 176 if (msg->type != htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS))
162 GNUNET_CLIENT_disconnect(dns_connection, GNUNET_NO); 177 {
163 dns_connection = NULL; 178 GNUNET_break (0);
164 conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns, 179 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
165 NULL); 180 dns_connection = NULL;
166 return; 181 conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns, NULL);
167 } 182 return;
168 void *pkt = GNUNET_malloc(ntohs(msg->size)); 183 }
169 184 void *pkt = GNUNET_malloc (ntohs (msg->size));
170 memcpy(pkt, msg, ntohs(msg->size)); 185
171 186 memcpy (pkt, msg, ntohs (msg->size));
172 GNUNET_SCHEDULER_add_now(process_answer, pkt); 187
173 GNUNET_CLIENT_receive(dns_connection, &dns_answer_handler, NULL, GNUNET_TIME_UNIT_FOREVER_REL); 188 GNUNET_SCHEDULER_add_now (process_answer, pkt);
189 GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
190 GNUNET_TIME_UNIT_FOREVER_REL);
174} 191}
175