Annotate

util/jsonpointer.lua @ 12468:353836684009

net.connect: Fix accumulation of connection attempt references Connection attempts that failed the Happy Eyeballs race were not unreferenced and would accumulate. Tested by inspecting the 'pending_connections_map' after establishing s2s with a s2s target where the IPv6 port has a -j DROP rule causing it to time out and the IPv4 attempt wins the race. Expected is that the losing connection stays around until net.server timeouts kick in where it should be removed. The map table should tend towards being empty during idle times.
author Kim Alvefur <zash@zash.se>
date Wed, 20 Apr 2022 22:41:54 +0200
parent 12131:b4c0efff8dd3
child 12496:87c3d45208ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12131
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local function unescape_token(escaped_token)
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local unescaped = escaped_token:gsub("~1", "/"):gsub("~0", "~")
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 return unescaped
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 end
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local function resolve_json_pointer(ref, path)
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local ptr_len = #path + 1
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 for part, pos in path:gmatch("/([^/]*)()") do
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local token = unescape_token(part)
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 if not (type(ref) == "table") then
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 return nil
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 end
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local idx = next(ref)
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local new_ref
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 if type(idx) == "string" then
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 new_ref = ref[token]
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 elseif math.type(idx) == "integer" then
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local i = tonumber(token)
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 if token == "-" then
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 i = #ref + 1
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 end
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 new_ref = ref[i]
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 else
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 return nil, "invalid-table"
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 if pos == ptr_len then
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 return new_ref
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 elseif type(new_ref) == "table" then
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 ref = new_ref
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 elseif not (type(ref) == "table") then
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 return nil, "invalid-path"
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 end
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 return ref
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39
b4c0efff8dd3 util.jsonpointer: Resolve JSON Pointers per RFC 6901
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 return { resolve = resolve_json_pointer }