Class: Girl::ProxyWorker
- Inherits:
-
Object
- Object
- Girl::ProxyWorker
- Includes:
- Dns
- Defined in:
- lib/girl/proxy_worker.rb
Instance Method Summary collapse
-
#initialize(redir_host, redir_port, memd_port, tspd_host, tspd_port, proxyd_host, proxyd_port, bigd_port, nameservers, im, directs, remotes, appd_host, appd_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, expire_connecting, expire_long_after, expire_proxy_after, expire_resolv_cache, expire_short_after, is_debug, is_client_fastopen, is_server_fastopen) ⇒ ProxyWorker
constructor
A new instance of ProxyWorker.
- #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(redir_host, redir_port, memd_port, tspd_host, tspd_port, proxyd_host, proxyd_port, bigd_port, nameservers, im, directs, remotes, appd_host, appd_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, expire_connecting, expire_long_after, expire_proxy_after, expire_resolv_cache, expire_short_after, is_debug, is_client_fastopen, is_server_fastopen) ⇒ ProxyWorker
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 93 94 95 96 |
# File 'lib/girl/proxy_worker.rb', line 5 def initialize( redir_host, redir_port, memd_port, tspd_host, tspd_port, proxyd_host, proxyd_port, bigd_port, nameservers, im, directs, remotes, appd_host, appd_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, expire_connecting, expire_long_after, expire_proxy_after, expire_resolv_cache, expire_short_after, is_debug, is_client_fastopen, is_server_fastopen) @proxyd_host = proxyd_host @proxyd_addr = Socket.sockaddr_in(proxyd_port, proxyd_host) @bigd_addr = Socket.sockaddr_in(bigd_port, proxyd_host) @nameserver_addrs = nameservers.map{|n| Socket.sockaddr_in(53, n)} @im = im @directs = directs @remotes = remotes @local_ips = Socket.ip_address_list.select{|info| info.ipv4?}.map{|info| info.ip_address} @update_roles = [:dns, :dst, :mem, :p1, :src, :rsv] # 参与淘汰的角色 @updates_limit = 1008 # 淘汰池上限,1015(mac) - [info infod memd proxy redir rsvd tspd] @eliminate_count = 0 # 淘汰次数 @reads = [] # 读池 @writes = [] # 写池 @roles = {} # sock => :big / :dns / :dst / :infod / :mem / :memd / :p1 / :proxy / :redir / :rsv / :rsvd / :src / :tspd @updates = {} # sock => updated_at @proxy_infos = {} # proxy => {:is_syn :rbuff :recv_at :wbuff} @big_infos = {} # big => {:is_syn :overflowing :rbuff :recv_at :wbuff} @mem_infos = {} # mem => {:wbuff} @src_infos = {} # src => {:addrinfo :closing :destination_domain :destination_port :dst :in :is_big :is_connect :overflowing :proxy_proto :proxy_type :rbuff :src_id :wbuff} @dst_infos = {} # dst => {:closing :connected :domain :ip :overflowing :port :src :wbuff} @dns_infos = {} # dns => {:domain :src} @rsv_infos = {} # rsv => {:addrinfo :domain :type} @near_infos = {} # near_id => {:addrinfo :created_at :domain :id :type} @resolv_caches = {} # domain => [ip created_at] @is_direct_caches = {} # ip => true / false @response_caches = {} # domain => [response created_at ip is_remote] @response6_caches = {} # domain => [response created_at ip is_remote] @p1_infos = {} # p1 => {:closing :connected :in :is_big :overflowing :p2_id :wbuff} @appd_addr = Socket.sockaddr_in(appd_port, appd_host) @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 @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_client_fastopen = is_client_fastopen @is_server_fastopen = is_server_fastopen new_a_redir(redir_host, redir_port) new_a_infod(redir_port) new_a_memd(memd_port) new_a_rsvd(tspd_host, tspd_port) new_a_tspd(tspd_host, tspd_port) new_a_proxy new_a_big end |
Instance Method Details
#looping ⇒ Object
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 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/girl/proxy_worker.rb', line 98 def looping puts "looping" loop_heartbeat loop do rs, ws = IO.select(@reads, @writes) rs.each do |sock| role = @roles[sock] case role when :big read_big(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 :p1 read_p1(sock) when :proxy read_proxy(sock) when :redir read_redir(sock) when :rsv read_rsv(sock) when :rsvd read_rsvd(sock) when :src read_src(sock) when :tspd read_tspd(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 :p1 write_p1(sock) when :proxy write_proxy(sock) when :src write_src(sock) else close_sock(sock) end end end rescue Interrupt => e puts e.class quit! end |
#quit! ⇒ Object
166 167 168 |
# File 'lib/girl/proxy_worker.rb', line 166 def quit! exit end |