PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/libevent/libeventd/EvDns.d

http://gool.googlecode.com/
D | 231 lines | 172 code | 52 blank | 7 comment | 0 complexity | b55a967eb9ac04bc2befeaa372559968 MD5 | raw file
  1. module libeventd.EvDns ;
  2. import
  3. libeventd.Types;
  4. alias ubyte u8;
  5. alias ushort u16;
  6. alias uint u32;
  7. alias uint ev_socklen_t ;
  8. alias void* search_state;
  9. alias void* evdns_callback_type ;
  10. alias void* evdns_request_callback_fn_type;
  11. const MAX_V4_ADDRS = 32 ;
  12. const MAX_V6_ADDRS = 32 ;
  13. const HOST_NAME_MAX = 255 ;
  14. const _SS_PAD1SIZE = 6 ;
  15. const _SS_PAD2SIZE =112 ;
  16. alias ev_int sa_family_t;
  17. struct in6_addr {
  18. ev_uint8_t[16] s6_addr;
  19. }
  20. struct sockaddr_in6 {
  21. sa_family_t sin6_family;
  22. ev_uint16_t sin6_port;
  23. in6_addr sin6_addr;
  24. }
  25. struct sockaddr_storage {
  26. ev_short ss_family;
  27. char[_SS_PAD1SIZE] __ss_pad1;
  28. long __ss_align;
  29. char[_SS_PAD2SIZE] __ss_pad2;
  30. }
  31. extern(C):
  32. static in6_addr in6addr_any ;
  33. struct evdns_request {
  34. request* current_req;
  35. ev_int search_index;
  36. search_state* __search_state;
  37. char* search_origname; /* needs to be free()ed */
  38. ev_int search_flags;
  39. }
  40. struct request {
  41. u8* __request; /* the dns packet data */
  42. u8 request_type; /* TYPE_PTR or TYPE_A or TYPE_AAAA */
  43. ev_uint request_len;
  44. ev_int reissue_count;
  45. ev_int tx_count; /* the number of times that this packet has been sent */
  46. void* user_pointer; /* the pointer given to us for this request */
  47. evdns_callback_type user_callback;
  48. nameserver* ns; /* the server which we last sent it */
  49. request* next, prev;
  50. event timeout_event;
  51. u16 trans_id; /* the transaction id */
  52. ev_uint __request_appended ; // :1 /* true if the request pointer is data which follows this struct */
  53. ev_uint __transmit_me ; //:1 /* needs to be transmitted */
  54. /* XXXX This is a horrible hack. */
  55. char** put_cname_in_ptr; /* store the cname here if we get one. */
  56. evdns_base* base;
  57. evdns_request* handle;
  58. }
  59. struct reply {
  60. ev_uint type;
  61. ev_uint __have_answer; // : 1
  62. union {
  63. struct {
  64. u32 __addrcount_4;
  65. u32[MAX_V4_ADDRS] __addresses_4;
  66. } // a;
  67. struct {
  68. u32 __addrcount_6;
  69. in6_addr[MAX_V6_ADDRS] __addresses_6;
  70. } //aaaa;
  71. struct {
  72. char[HOST_NAME_MAX] __name;
  73. } // ptr;
  74. } // data;
  75. }
  76. struct nameserver {
  77. evutil_socket_t socket; /* a connected UDP socket */
  78. sockaddr_storage address;
  79. ev_socklen_t addrlen;
  80. ev_int failed_times; /* number of times which we have given this server a chance */
  81. ev_int timedout; /* number of times in a row a request has timed out */
  82. event __event;
  83. nameserver* next, prev;
  84. event timeout_event; /* used to keep the timeout for */
  85. evdns_request* probe_request;
  86. char state; /* zero if we think that this server is down */
  87. char choked; /* true if we have an EAGAIN from this server's socket */
  88. char write_waiting; /* true if we are waiting for EV_WRITE events */
  89. evdns_base* base;
  90. }
  91. struct evdns_server_port {
  92. evutil_socket_t socket; /* socket we use to read queries and write replies. */
  93. int refcnt; /* reference count. */
  94. char choked; /* Are we currently blocked from writing? */
  95. char closing; /* Are we trying to close this port, pending writes? */
  96. evdns_request_callback_fn_type user_callback; /* Fn to handle requests */
  97. void* user_data; /* Opaque pointer passed to user_callback */
  98. event __event;
  99. server_request* pending_replies;
  100. event_base* __event_base;
  101. version(_EVENT_DISABLE_THREAD_SUPPORT){}else{
  102. void* lock;
  103. }
  104. }
  105. /* Represents part of a reply being built. (That is, a single RR.) */
  106. struct server_reply_item {
  107. server_reply_item* next; /* next item in sequence. */
  108. char* name; /* name part of the RR */
  109. u16 type; /* The RR type */
  110. u16 __class; /* The RR class (usually CLASS_INET) */
  111. u32 ttl; /* The RR TTL */
  112. char is_name; /* True iff data is a label */
  113. u16 datalen; /* Length of data; -1 if data is a label */
  114. void* data; /* The contents of the RR */
  115. }
  116. struct server_request {
  117. server_request* next_pending;
  118. server_request* prev_pending;
  119. u16 trans_id; /* Transaction id. */
  120. evdns_server_port* port; /* Which port received this request on? */
  121. sockaddr_storage addr; /* Where to send the response */
  122. ev_socklen_t addrlen; /* length of addr */
  123. ev_int n_answer; /* how many answer RRs have been set? */
  124. ev_int n_authority; /* how many authority RRs have been set? */
  125. ev_int n_additional; /* how many additional RRs have been set? */
  126. server_reply_item* answer; /* linked list of answer RRs */
  127. server_reply_item* authority; /* linked list of authority RRs */
  128. server_reply_item* additional; /* linked list of additional RRs */
  129. char* response;
  130. size_t response_len;
  131. evdns_server_request base;
  132. }
  133. struct evdns_base {
  134. request** req_heads;
  135. request* req_waiting_head;
  136. nameserver* server_head;
  137. int n_req_heads;
  138. event_base* __event_base;
  139. int global_good_nameservers;
  140. int global_requests_inflight;
  141. int global_requests_waiting;
  142. int global_max_requests_inflight;
  143. timeval global_timeout; /* 5 seconds by default */
  144. int global_max_reissues; /* a reissue occurs when we get some errors from the server */
  145. int global_max_retransmits; /* number of times we'll retransmit a request which timed out */
  146. int global_max_nameserver_timeout;
  147. /* true iff we will use the 0x20 hack to prevent poisoning attacks. */
  148. int global_randomize_case;
  149. /* The first time that a nameserver fails, how long do we wait before
  150. * probing to see if it has returned? */
  151. timeval global_nameserver_probe_initial_timeout;
  152. /** Port to bind to for outgoing DNS packets. */
  153. sockaddr_storage global_outgoing_address;
  154. /** ev_socklen_t for global_outgoing_address. 0 if it isn't set. */
  155. ev_socklen_t global_outgoing_addrlen;
  156. timeval global_getaddrinfo_allow_skew;
  157. ev_int getaddrinfo_ipv4_timeouts;
  158. ev_int getaddrinfo_ipv6_timeouts;
  159. ev_int getaddrinfo_ipv4_answered;
  160. ev_int getaddrinfo_ipv6_answered;
  161. search_state* global_search_state;
  162. hosts_list hostsdb;
  163. version(_EVENT_DISABLE_THREAD_SUPPORT){}else{
  164. void *lock;
  165. }
  166. }
  167. struct hosts_entry {
  168. TAILQ_ENTRY!(hosts_entry) next;
  169. union {
  170. sockaddr sa;
  171. sockaddr_in sin;
  172. sockaddr_in6 sin6;
  173. } // addr;
  174. int addrlen;
  175. char[1] hostname;
  176. }
  177. struct hosts_list {
  178. mixin TAILQ_HEAD!(hosts_entry);
  179. }