|
| 1 | +-- else the randomness would be the same every run |
| 2 | +math.randomseed(os.time()) |
| 3 | + |
| 4 | +local charset = "0123456789ABCDEF" |
| 5 | + |
| 6 | +function hex_to_char(hex) |
| 7 | + local n = tonumber(hex, 16) |
| 8 | + local f = string.char(n) |
| 9 | + return f |
| 10 | +end |
| 11 | + |
| 12 | +function hex_string_to_char_string(hex) |
| 13 | + local ret = {} |
| 14 | + local r |
| 15 | + for i = 0, 19 do |
| 16 | + local x = i * 2 |
| 17 | + r = hex:sub(x+1, x+2) |
| 18 | + local f = hex_to_char(r) |
| 19 | + table.insert(ret, f) |
| 20 | + end |
| 21 | + return table.concat(ret) |
| 22 | +end |
| 23 | + |
| 24 | +function url_encode(str) |
| 25 | + str = string.gsub (str, "([^0-9a-zA-Z !'()*._~-])", -- locale independent |
| 26 | + function (c) return string.format ("%%%02X", string.byte(c)) end) |
| 27 | + str = string.gsub (str, " ", "+") |
| 28 | + return str |
| 29 | +end |
| 30 | + |
| 31 | +function gen_hex_string(length) |
| 32 | + local ret = {} |
| 33 | + local r |
| 34 | + for i = 1, length do |
| 35 | + r = math.random(1, #charset) |
| 36 | + table.insert(ret, charset:sub(r, r)) |
| 37 | + end |
| 38 | + return table.concat(ret) |
| 39 | +end |
| 40 | + |
| 41 | +function random_info_hash() |
| 42 | + local hexString = gen_hex_string(40) |
| 43 | + local str = hex_string_to_char_string(hexString) |
| 44 | + return url_encode(str) |
| 45 | +end |
| 46 | + |
1 | 47 | function generate_unique_info_hashes(size)
|
2 | 48 | local result = {}
|
3 |
| - local seen = {} |
4 |
| - |
5 |
| - for i = 0, size - 1 do |
6 |
| - local bytes = {} |
7 |
| - bytes[1] = i & 0xFF |
8 |
| - bytes[2] = (i >> 8) & 0xFF |
9 |
| - bytes[3] = (i >> 16) & 0xFF |
10 |
| - bytes[4] = (i >> 24) & 0xFF |
11 |
| - |
12 |
| - local info_hash = bytes |
13 |
| - local key = table.concat(info_hash, ",") |
14 |
| - |
15 |
| - if not seen[key] then |
16 |
| - table.insert(result, info_hash) |
17 |
| - seen[key] = true |
18 |
| - end |
| 49 | + |
| 50 | + for i = 1, size do |
| 51 | + result[i] = random_info_hash() |
19 | 52 | end
|
20 | 53 |
|
21 | 54 | return result
|
22 | 55 | end
|
23 | 56 |
|
24 |
| -info_hashes = generate_unique_info_hashes(10000000) |
| 57 | +info_hashes = generate_unique_info_hashes(5000000) |
25 | 58 |
|
26 |
| -index = 0 |
| 59 | +index = 1 |
27 | 60 |
|
28 | 61 | -- the request function that will run at each request
|
29 | 62 | request = function()
|
30 | 63 | path = "/announce?info_hash=" .. info_hashes[index] .. "&peer_id=-lt0D80-a%D4%10%19%99%A6yh%9A%E1%CD%96&port=54434&uploaded=885&downloaded=0&left=0&corrupt=0&key=A78381BD&numwant=200&compact=1&no_peer_id=1&supportcrypto=1&redundant=0"
|
31 |
| - index += 1 |
| 64 | + index = index + 1 |
32 | 65 | headers = {}
|
33 | 66 | headers["X-Forwarded-For"] = "1.1.1.1"
|
34 | 67 | return wrk.format("GET", path, headers)
|
|
0 commit comments