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

Commit

Permalink
Merge pull request #39 from SkynetLabs/limits-broken-on-non-accounts-…
Browse files Browse the repository at this point in the history
…portals

set limits to anon on portals without accounts
  • Loading branch information
kwypchlo authored Oct 12, 2022
2 parents 051df52 + 19fb9d5 commit e7aea77
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions nginx/conf.d/include/location-skylink
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ access_by_lua_block {
if skynet_account.is_access_forbidden() then
return skynet_account.exit_access_forbidden()
end
end

-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()
-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()

-- apply download speed limit
ngx.var.limit_rate = limits.download
end
-- apply download speed limit
ngx.var.limit_rate = limits.download
}

limit_rate_after 512k;
Expand Down
14 changes: 7 additions & 7 deletions nginx/conf.d/include/location-skynet-registry
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ access_by_lua_block {
if skynet_account.is_access_forbidden() then
return skynet_account.exit_access_forbidden()
end
end

-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()

-- apply registry rate limits (forced delay)
if limits.registry > 0 then
ngx.sleep(limits.registry / 1000)
end
-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()

-- apply registry rate limits (forced delay)
if limits.registry > 0 then
ngx.sleep(limits.registry / 1000)
end
}
32 changes: 16 additions & 16 deletions nginx/conf.d/server/server.api
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ location /skynet/registry/subscription {
if skynet_account.is_access_forbidden() then
return skynet_account.exit_access_forbidden()
end
end

-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()
-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()

-- apply bandwidth limit and notification delay
ngx.var.bandwidthlimit = limits.download
ngx.var.notificationdelay = limits.registry
end
-- apply bandwidth limit and notification delay
ngx.var.bandwidthlimit = limits.download
ngx.var.notificationdelay = limits.registry
}

proxy_set_header User-Agent: Sia-Agent;
Expand Down Expand Up @@ -299,13 +299,13 @@ location /skynet/tus {
if skynet_account.is_access_forbidden() then
return skynet_account.exit_access_forbidden()
end
end

-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()
-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()

-- apply upload size limits
ngx.req.set_header("SkynetMaxUploadSize", limits.maxUploadSize)
end
-- apply upload size limits
ngx.req.set_header("SkynetMaxUploadSize", limits.maxUploadSize)
}

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

-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()
-- get account limits of currently authenticated user
local limits = skynet_account.get_account_limits()

-- apply download speed limit
ngx.var.limit_rate = limits.download
end
-- apply download speed limit
ngx.var.limit_rate = limits.download
}

limit_rate_after 512k;
Expand Down
4 changes: 2 additions & 2 deletions nginx/libs/skynet/account.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function _M.get_account_limits()
local utils = require('utils')
local auth_headers = _M.get_auth_headers()

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

Expand Down

0 comments on commit e7aea77

Please sign in to comment.