Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 19fb9d5

Browse files
committed
set limits to anon on portals without accounts
1 parent 051df52 commit 19fb9d5

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

nginx/conf.d/include/location-skylink

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ access_by_lua_block {
2727
if skynet_account.is_access_forbidden() then
2828
return skynet_account.exit_access_forbidden()
2929
end
30+
end
3031

31-
-- get account limits of currently authenticated user
32-
local limits = skynet_account.get_account_limits()
32+
-- get account limits of currently authenticated user
33+
local limits = skynet_account.get_account_limits()
3334

34-
-- apply download speed limit
35-
ngx.var.limit_rate = limits.download
36-
end
35+
-- apply download speed limit
36+
ngx.var.limit_rate = limits.download
3737
}
3838

3939
limit_rate_after 512k;

nginx/conf.d/include/location-skynet-registry

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ access_by_lua_block {
2525
if skynet_account.is_access_forbidden() then
2626
return skynet_account.exit_access_forbidden()
2727
end
28+
end
2829

29-
-- get account limits of currently authenticated user
30-
local limits = skynet_account.get_account_limits()
31-
32-
-- apply registry rate limits (forced delay)
33-
if limits.registry > 0 then
34-
ngx.sleep(limits.registry / 1000)
35-
end
30+
-- get account limits of currently authenticated user
31+
local limits = skynet_account.get_account_limits()
32+
33+
-- apply registry rate limits (forced delay)
34+
if limits.registry > 0 then
35+
ngx.sleep(limits.registry / 1000)
3636
end
3737
}

nginx/conf.d/server/server.api

+16-16
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ location /skynet/registry/subscription {
187187
if skynet_account.is_access_forbidden() then
188188
return skynet_account.exit_access_forbidden()
189189
end
190+
end
190191

191-
-- get account limits of currently authenticated user
192-
local limits = skynet_account.get_account_limits()
192+
-- get account limits of currently authenticated user
193+
local limits = skynet_account.get_account_limits()
193194

194-
-- apply bandwidth limit and notification delay
195-
ngx.var.bandwidthlimit = limits.download
196-
ngx.var.notificationdelay = limits.registry
197-
end
195+
-- apply bandwidth limit and notification delay
196+
ngx.var.bandwidthlimit = limits.download
197+
ngx.var.notificationdelay = limits.registry
198198
}
199199

200200
proxy_set_header User-Agent: Sia-Agent;
@@ -299,13 +299,13 @@ location /skynet/tus {
299299
if skynet_account.is_access_forbidden() then
300300
return skynet_account.exit_access_forbidden()
301301
end
302+
end
302303

303-
-- get account limits of currently authenticated user
304-
local limits = skynet_account.get_account_limits()
304+
-- get account limits of currently authenticated user
305+
local limits = skynet_account.get_account_limits()
305306

306-
-- apply upload size limits
307-
ngx.req.set_header("SkynetMaxUploadSize", limits.maxUploadSize)
308-
end
307+
-- apply upload size limits
308+
ngx.req.set_header("SkynetMaxUploadSize", limits.maxUploadSize)
309309
}
310310

311311
# extract skylink from base64 encoded upload metadata and assign to a proper header
@@ -466,13 +466,13 @@ location /skynet/trustless/basesector {
466466
if skynet_account.is_access_forbidden() then
467467
return skynet_account.exit_access_forbidden()
468468
end
469+
end
469470

470-
-- get account limits of currently authenticated user
471-
local limits = skynet_account.get_account_limits()
471+
-- get account limits of currently authenticated user
472+
local limits = skynet_account.get_account_limits()
472473

473-
-- apply download speed limit
474-
ngx.var.limit_rate = limits.download
475-
end
474+
-- apply download speed limit
475+
ngx.var.limit_rate = limits.download
476476
}
477477

478478
limit_rate_after 512k;

nginx/libs/skynet/account.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ function _M.get_account_limits()
8181
local utils = require('utils')
8282
local auth_headers = _M.get_auth_headers()
8383

84-
-- simple case of anonymous request - none of available auth headers exist
85-
if utils.is_table_empty(auth_headers) then
84+
-- simple case of anonymous request - none of available auth headers exist or accounts are not enabled
85+
if utils.is_table_empty(auth_headers) or _M.accounts_disabled() then
8686
return anon_limits
8787
end
8888

0 commit comments

Comments
 (0)