Class: Girl::ProxydWorker
- Inherits:
-
Object
- Object
- Girl::ProxydWorker
- Includes:
- Dns
- Defined in:
- lib/girl/proxyd_worker.rb
Instance Method Summary collapse
-
#initialize(proxyd_port, bigd_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_query, h_response, h_src_close, h_traffic, h_dst_switch_to_big, h_p2_switch_to_big, h_src_switch_to_big, h_p1_switch_to_big, expire_connecting, expire_long_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, bigd_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_query, h_response, h_src_close, h_traffic, h_dst_switch_to_big, h_p2_switch_to_big, h_src_switch_to_big, h_p1_switch_to_big, expire_connecting, expire_long_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 |
# File 'lib/girl/proxyd_worker.rb', line 5 def initialize( proxyd_port, bigd_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_query, h_response, h_src_close, h_traffic, h_dst_switch_to_big, h_p2_switch_to_big, h_src_switch_to_big, h_p1_switch_to_big, expire_connecting, expire_long_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 = [:big, :dns, :dst, :mem, :p2, :proxy, :rsv] # 参与淘汰的角色 @updates_limit = 1010 - ims.size # 淘汰池上限,1015(mac) - [bigd info infod memd proxyd] - p2ds @eliminate_count = 0 # 淘汰次数 @reads = [] # 读池 @writes = [] # 写池 @roles = {} # sock => :big / :bigd / :dns / :dst / :infod / :mem / :memd / :p2 / :p2d / :proxy / :proxyd / :rsv @updates = {} # sock => updated_at @proxy_infos = {} # proxy => {:addrinfo :im :rbuff :wbuff} @big_infos = {} # big => {:addrinfo :im :overflowing :rbuff :wbuff} @im_infos = {} # im => {:addrinfo :big :big_connect_at :in :out :p2d :p2d_host :p2d_port :proxy :proxy_connect_at} @src_infos = {} # src_id => {:created_at :dst :im :rbuff} @mem_infos = {} # mem => {:wbuff} @dst_infos = {} # dst => {:closing :connected :domain :im :in :ip :is_big :overflowing :port :rbuffs :src_id :switched :wbuff :wpend} @dns_infos = {} # dns => {:domain :im :port :src_id} @rsv_infos = {} # rsv => {:domain :im :near_id} @resolv_caches = {} # domain => [ip created_at] @p2d_infos = {} # p2d => {:im} @p2_infos = {} # p2 => {:addrinfo :closing :im :in :is_big :overflowing :p2_id :switched :wbuff :wpend} @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_query = h_query @h_response = h_response @h_src_close = h_src_close @h_traffic = h_traffic @h_dst_switch_to_big = h_dst_switch_to_big @h_p2_switch_to_big = h_p2_switch_to_big @h_src_switch_to_big = h_src_switch_to_big @h_p1_switch_to_big = h_p1_switch_to_big @expire_connecting = expire_connecting @expire_long_after = expire_long_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_bigd(bigd_port) new_a_infod(proxyd_port) new_a_memd(memd_port) end |
Instance Method Details
#looping ⇒ Object
85 86 87 88 89 90 91 92 93 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 |
# File 'lib/girl/proxyd_worker.rb', line 85 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 :big read_big(sock) when :bigd read_bigd(sock) when :dns read_dns(sock) when :dst read_dst(sock) when :infod read_infod(sock) when :mem read_mem(sock) when :memd read_memd(sock) when :p2 read_p2(sock) when :p2d read_p2d(sock) when :rsv read_rsv(sock) when :proxy read_proxy(sock) when :proxyd read_proxyd(sock) else close_sock(sock) end end ws.each do |sock| role = @roles[sock] case role when :big write_big(sock) when :dst write_dst(sock) when :mem write_mem(sock) when :p2 write_p2(sock) when :proxy write_proxy(sock) else close_sock(sock) end end end rescue Interrupt => e puts e.class quit! end |
#quit! ⇒ Object
150 151 152 |
# File 'lib/girl/proxyd_worker.rb', line 150 def quit! exit end |