Class: Girl::ProxydWorker
- Inherits:
-
Object
- Object
- Girl::ProxydWorker
- Includes:
- Dns
- Defined in:
- lib/girl/proxyd_worker.rb
Instance Method Summary collapse
-
#initialize(proxyd_port, memd_port, nameservers, reset_traff_day, ims, p2d_host, p2d_port, head_len, h_a_new_source, h_a_new_p2, h_dst_close, h_heartbeat, h_p1_close, h_p2_close, h_p2_traffic, h_p1_overflow, h_p1_underhalf, h_p2_overflow, h_p2_underhalf, h_query, h_response, h_src_close, h_traffic, h_src_overflow, h_src_underhalf, h_dst_overflow, h_dst_underhalf, expire_connecting, expire_long_after, expire_proxy_after, expire_resolv_cache, expire_short_after, is_debug, is_server_fastopen) ⇒ ProxydWorker
constructor
A new instance of ProxydWorker.
- #looping ⇒ Object
- #quit! ⇒ Object
Methods included from Dns
#pack_a_query, #pack_domain, #seek_dn, #seek_ip, #seek_question, #seek_question_dn, #seek_rr_ip
Constructor Details
#initialize(proxyd_port, memd_port, nameservers, reset_traff_day, ims, p2d_host, p2d_port, head_len, h_a_new_source, h_a_new_p2, h_dst_close, h_heartbeat, h_p1_close, h_p2_close, h_p2_traffic, h_p1_overflow, h_p1_underhalf, h_p2_overflow, h_p2_underhalf, h_query, h_response, h_src_close, h_traffic, h_src_overflow, h_src_underhalf, h_dst_overflow, h_dst_underhalf, expire_connecting, expire_long_after, expire_proxy_after, expire_resolv_cache, expire_short_after, is_debug, is_server_fastopen) ⇒ ProxydWorker
Returns a new instance of ProxydWorker.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/girl/proxyd_worker.rb', line 5 def initialize( proxyd_port, memd_port, nameservers, reset_traff_day, ims, p2d_host, p2d_port, head_len, h_a_new_source, h_a_new_p2, h_dst_close, h_heartbeat, h_p1_close, h_p2_close, h_p2_traffic, h_p1_overflow, h_p1_underhalf, h_p2_overflow, h_p2_underhalf, h_query, h_response, h_src_close, h_traffic, h_src_overflow, h_src_underhalf, h_dst_overflow, h_dst_underhalf, expire_connecting, expire_long_after, expire_proxy_after, expire_resolv_cache, expire_short_after, is_debug, is_server_fastopen ) @nameserver_addrs = nameservers.map{ | n | Socket.sockaddr_in( 53, n ) } @reset_traff_day = reset_traff_day @update_roles = [ :dns, :dst, :mem, :p2, :proxy, :rsv ] # 参与淘汰的角色 @updates_limit = 1011 - ims.size # 淘汰池上限,1015(mac) - info, infod, memd, proxyd, p2ds(=ims) @eliminate_count = 0 # 淘汰次数 @reads = [] # 读池 @writes = [] # 写池 @roles = {} # sock => :dns / :dst / :infod / :mem / :memd / :p2 / :p2d / :proxy / :proxyd / :rsv @updates = {} # sock => updated_at @proxy_infos = {} # proxy => { :addrinfo :im :paused_dsts :paused_p2s :rbuff :src_infos :wbuff } @im_infos = {} # im => { :addrinfo :in :out :p2d :p2d_host :p2d_port :proxy } @mem_infos = {} # mem => { :wbuff } @dst_infos = {} # dst => { :closing :connected :domain :im :ip :overflowing :port :proxy :rbuffs :src_id :wbuff } @dns_infos = {} # dns => { :domain :im :port :proxy :src_id } @rsv_infos = {} # rsv => { :domain :im :near_id :proxy } @resolv_caches = {} # domain => [ ip, created_at, im ] @p2d_infos = {} # p2d => { :im } @p2_infos = {} # p2 => { :addrinfo :closing :im :overflowing :p2_id :wbuff } @head_len = head_len @h_a_new_source = h_a_new_source @h_a_new_p2 = h_a_new_p2 @h_dst_close = h_dst_close @h_heartbeat = h_heartbeat @h_p1_close = h_p1_close @h_p2_close = h_p2_close @h_p2_traffic = h_p2_traffic @h_p1_overflow = h_p1_overflow @h_p1_underhalf = h_p1_underhalf @h_p2_overflow = h_p2_overflow @h_p2_underhalf = h_p2_underhalf @h_query = h_query @h_response = h_response @h_src_close = h_src_close @h_traffic = h_traffic @h_src_overflow = h_src_overflow @h_src_underhalf = h_src_underhalf @h_dst_overflow = h_dst_overflow @h_dst_underhalf = h_dst_underhalf @expire_connecting = expire_connecting @expire_long_after = expire_long_after @expire_proxy_after = expire_proxy_after @expire_resolv_cache = expire_resolv_cache @expire_short_after = expire_short_after @is_debug = is_debug @is_server_fastopen = is_server_fastopen init_im_infos( ims, p2d_host, p2d_port ) new_a_proxyd( proxyd_port ) new_a_infod( proxyd_port ) new_a_memd( memd_port ) end |
Instance Method Details
#looping ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/girl/proxyd_worker.rb', line 94 def looping puts "looping" loop_heartbeat loop_check_traff loop do rs, ws = IO.select( @reads, @writes ) rs.each do | sock | role = @roles[ sock ] case role when :dns then read_dns( sock ) when :dst then read_dst( sock ) when :infod then read_infod( sock ) when :mem then read_mem( sock ) when :memd then read_memd( sock ) when :p2 then read_p2( sock ) when :p2d then read_p2d( sock ) when :rsv then read_rsv( sock ) when :proxy then read_proxy( sock ) when :proxyd then read_proxyd( sock ) else close_sock( sock ) end end ws.each do | sock | role = @roles[ sock ] case role when :dst then write_dst( sock ) when :mem then write_mem( sock ) when :p2 then write_p2( sock ) when :proxy then write_proxy( sock ) else close_sock( sock ) end end end rescue Interrupt => e puts e.class quit! end |
#quit! ⇒ Object
153 154 155 |
# File 'lib/girl/proxyd_worker.rb', line 153 def quit! exit end |