forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrk_benchmark_announce.lua
More file actions
53 lines (46 loc) · 1.41 KB
/
wrk_benchmark_announce.lua
File metadata and controls
53 lines (46 loc) · 1.41 KB
1
2
3
4
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
-- else the randomness would be the same every run
math.randomseed(os.time())
local charset = "0123456789ABCDEF"
function hexToChar(hex)
local n = tonumber(hex, 16)
local f = string.char(n)
return f
end
function hexStringToCharString(hex)
local ret = {}
local r
for i = 0, 19 do
local x = i * 2
r = hex:sub(x+1, x+2)
local f = hexToChar(r)
table.insert(ret, f)
end
return table.concat(ret)
end
function urlEncode(str)
str = string.gsub (str, "([^0-9a-zA-Z !'()*._~-])", -- locale independent
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
return str
end
function genHexString(length)
local ret = {}
local r
for i = 1, length do
r = math.random(1, #charset)
table.insert(ret, charset:sub(r, r))
end
return table.concat(ret)
end
function randomInfoHash()
local hexString = genHexString(40)
local str = hexStringToCharString(hexString)
return urlEncode(str)
end
-- the request function that will run at each request
request = function()
path = "/announce?info_hash=" .. randomInfoHash() .. "&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"
headers = {}
headers["X-Forwarded-For"] = "1.1.1.1"
return wrk.format("GET", path, headers)
end