Class: RHACK::Proxy::Checker
Instance Attribute Summary collapse
-
#fpl ⇒ Object
readonly
Returns the value of attribute fpl.
-
#ics ⇒ Object
readonly
Returns the value of attribute ics.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#pl ⇒ Object
readonly
Returns the value of attribute pl.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#wpl ⇒ Object
readonly
Returns the value of attribute wpl.
Instance Method Summary collapse
- #charge(pl = @pl, target = @target.req) ⇒ Object
- #check(*argv, &callback) ⇒ Object
- #DL(scout, target) ⇒ Object
- #expected?(res, target) ⇒ Boolean
- #fastest ⇒ Object
- #Get(scout, target, &callback) ⇒ Object
- #get_by_ping(limit, minlen = 1) ⇒ Object
- #get_by_speed(min) ⇒ Object
-
#initialize(*argv) ⇒ Checker
constructor
A new instance of Checker.
- #inspect ⇒ Object
- #Post(scout, target) ⇒ Object
- #to_a ⇒ Object
- #to_pl ⇒ Object
Constructor Details
#initialize(*argv) ⇒ Checker
Returns a new instance of Checker.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rhack/proxy/checker.rb', line 42 def initialize(*argv) @pl, @target, @opts = argv.fetch_opts [[], DefaultGet] @wpl = {} # proxy => ping @fpl = {} # proxy => Bps @succeed = @failed = 0 @printer = TempPrinter self, "succeed: :succeed\nfailed : :failed" if @opts.page Curl.run @page = IB::Page.new(@opts.page, :rt => true, :form => true) if @opts.page.is String Curl.wait @opts.engine = @page.engine end charge @pl end |
Instance Attribute Details
#fpl ⇒ Object (readonly)
Returns the value of attribute fpl.
40 41 42 |
# File 'lib/rhack/proxy/checker.rb', line 40 def fpl @fpl end |
#ics ⇒ Object (readonly)
Returns the value of attribute ics.
40 41 42 |
# File 'lib/rhack/proxy/checker.rb', line 40 def ics @ics end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
40 41 42 |
# File 'lib/rhack/proxy/checker.rb', line 40 def opts @opts end |
#pl ⇒ Object (readonly)
Returns the value of attribute pl.
40 41 42 |
# File 'lib/rhack/proxy/checker.rb', line 40 def pl @pl end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
40 41 42 |
# File 'lib/rhack/proxy/checker.rb', line 40 def target @target end |
#wpl ⇒ Object (readonly)
Returns the value of attribute wpl.
40 41 42 |
# File 'lib/rhack/proxy/checker.rb', line 40 def wpl @wpl end |
Instance Method Details
#charge(pl = @pl, target = @target.req) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rhack/proxy/checker.rb', line 61 def charge(pl=@pl, target=@target.req) @ics = [] GC.start fail_proc = lambda {|c, e| c.on_complete {} c.base.error = e } target = target.find_is(String) if !target.is String pl.each {|pr| sc = Interceptor.new(target, pr, RHACK.useragents.rand, @opts) sc.http.on_failure(&fail_proc) @ics << sc } self end |
#check(*argv, &callback) ⇒ Object
77 78 79 80 81 82 83 84 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 |
# File 'lib/rhack/proxy/checker.rb', line 77 def check(*argv, &callback) target, query, opts = argv.fetch_opts [@target, @ics], @opts report = opts[:report] cond = opts[:while] carier = opts[:carier] post = opts[:post] || carier || target.is(Array) dl = opts[:dl] unless post division = opts[:div] || 500 if !target.req.is(Array) and @page.resto target.req post ||= target.req == :action target.req = @page.host + @page.send(target.req) end if !query[0].is Interceptor @opts.merge!(opts) query = charge(query, target.req) end testrow = lambda {|d| $log << "\n#{report} = #{instance_eval(report).inspect}" if report throw :break if cond and !instance_eval(&cond) d.each {|s| if post (carier || self).Post(s, target) else if '%s'.in target.req scoped_target = target.dup scoped_target.req %= rand else scoped_target = target end if dl DL(s, scoped_target) else callback ? Get(s, scoped_target, &callback) : Get(s, scoped_target) end end } Curl.wait } dl ? (@fpl = {}) : (@wpl = {}) @succeed = @failed = 0 Curl.execute catch(:break) { query.div(division).each {|d| testrow[d]} } catch(:break) { query.select {|i| i.res.is Array and i.res[0] == Curl::Err::TimeoutError}.div(division).each {|d| testrow[d]} } @printer.end! self end |
#DL(scout, target) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/rhack/proxy/checker.rb', line 135 def DL(scout, target) scout.loadGet(target.req) {|c| res = c.res $log.debug " #{c.base} returned #{res}" if !res.is Array and expected? res, target @fpl[c.proxy_url] = (res.body.size/(c.total_time - @wpl[scout.proxystr].to_f)).to_i @succeed += 1 else @failed += 1 end @printer.p if !$panic } end |
#expected?(res, target) ⇒ Boolean
130 131 132 133 |
# File 'lib/rhack/proxy/checker.rb', line 130 def expected? res, target target.expect[:code] ||= 200 !target.expect.find {|k, v| !( v.is(Proc) ? v[res.__send__(k)] : v === res.__send__(k) )} end |
#fastest ⇒ Object
190 191 192 193 |
# File 'lib/rhack/proxy/checker.rb', line 190 def fastest val = @wpl.values.sort[0] @wpl.find {|k,v| v == val}[0]/':' if val end |
#Get(scout, target, &callback) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/rhack/proxy/checker.rb', line 149 def Get(scout, target, &callback) if callback scout.loadGet(target.req, &callback) else scout.loadGet(target) {|c| res = c.res $log.debug " #{c.base} returned #{res}" if !res.is Array and expected? res, target @wpl[c.proxy_url] = c.total_time @succeed += 1 else @failed += 1 end @printer.p if !$panic } end end |
#get_by_ping(limit, minlen = 1) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/rhack/proxy/checker.rb', line 195 def get_by_ping(limit, minlen=1) newpl = [] case limit when Numeric; @wpl.each {|pr,lt| newpl << pr/':' if lt < limit} when Range begin limit.to_a.each {|i| @wpl.each {|pr,lt| newpl << pr/':' if lt < i} break if newpl.size >= minlen newpl.clear } rescue TypeError @wpl.each {|pr,lt| newpl << pr/':' if lt < limit.min} if newpl.size < minlen newpl.clear @wpl.each {|pr,lt| newpl << pr/':' if lt < limit.max} end end end newpl.to_pl end |
#get_by_speed(min) ⇒ Object
217 218 219 220 221 |
# File 'lib/rhack/proxy/checker.rb', line 217 def get_by_speed(min) newpl = [] @fpl.each {|pr, sp| newpl << pr/':' if sp >= min} newpl.to_pl end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/rhack/proxy/checker.rb', line 57 def inspect "<#ProxyChecker @ics: #{@ics.size} @wpl: #{@wpl.size} @fpl: #{@fpl.size}>" end |
#Post(scout, target) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rhack/proxy/checker.rb', line 167 def Post(scout, target) scout.loadPost(*target.req) {|c| res = c.res $log.debug "#{c.base} returned #{res}" if !res.is Array and expected? res, target# || (res.code == '303' and @opts.engine.is IB::Wakaba) @wpl[c.proxy_url] = c.total_time @succeed += 1 else @failed += 1 end @printer.p if !$panic } end |
#to_a ⇒ Object
181 182 183 184 |
# File 'lib/rhack/proxy/checker.rb', line 181 def to_a deprecation "use #to_pl instead." to_pl end |
#to_pl ⇒ Object
186 187 188 |
# File 'lib/rhack/proxy/checker.rb', line 186 def to_pl @wpl.map {|k,v| [v,k]}.sort.map! {|e| e.last/':'}.to_pl end |