Skip to content

Commit

Permalink
doc: update example and manual
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <[email protected]>
  • Loading branch information
hexian000 committed Jan 20, 2025
1 parent 7b4cfc7 commit 366123d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ Process a host name request. Specifically:
- SOCKS5 with host name (a.k.a. "socks5h")
- Any SOCKS4A

*This callback is called from an asynchronous routine.*

**Params**

- `domain`: full qualified domain name and port, like `"www.example.org:80"`
Expand Down Expand Up @@ -155,6 +157,8 @@ Process an IPv4 request. Specifically:
- SOCKS5 with IPv4 address
- Any SOCKS4

*This callback is called from an asynchronous routine.*

**Params**

- `addr`: address and port, like `"203.0.113.1:80"`
Expand All @@ -180,6 +184,8 @@ Process an IPv6 request. Specifically:

- SOCKS5 with IPv6 address

*This callback is called from an asynchronous routine.*

**Params**

- `addr`: address and port, like `"[2001:DB8::1]:80"`
Expand All @@ -203,6 +209,8 @@ end

Periodic timer callback. See [neosocksd.setinterval](#neosocksdsetinterval).

*This callback is NOT called from an asynchronous routine.*

**Params**

- `now`: current timestamp in seconds
Expand All @@ -228,6 +236,8 @@ end

Generate custom information to be provided in the API `/stats`. See also [stats](#stats).

*This callback is NOT called from an asynchronous routine.*

**Params**

- `dt`: seconds elapsed since last call
Expand Down
8 changes: 8 additions & 0 deletions example/ruleset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ function ruleset.stats(dt, q)
return w:concat("\n")
end

function ruleset.tick(now)
libruleset.tick(now)
if stat_requests:get(1) ~= stat_requests:get(2) then
collectgarbage("step")
end
end

local function main(...)
pcall(collectgarbage, "generational")
neosocksd.setinterval(60)
-- inherit undefined fields from libruleset
return setmetatable(ruleset, {
Expand Down

0 comments on commit 366123d

Please sign in to comment.