Skip to content

Commit d116015

Browse files
committed
all: rmv Gostr and Gobyt
1 parent ddb17fa commit d116015

60 files changed

Lines changed: 654 additions & 661 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

intra/backend/core_iptree.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,37 @@ import (
2121
// A IpTree is a thread-safe trie that supports insertion, deletion, and route matching IP CIDRs.
2222
type IpTree interface {
2323
// Adds value v to the cidr route.
24-
Add(cidr, v *Gostr) error
24+
Add(cidr, v string) error
2525
// Sets cidr route to v, overwriting any previous value.
26-
Set(cidr, v *Gostr) error
26+
Set(cidr, v string) error
2727
// Removes value v, if found.
28-
Esc(cidr, v *Gostr) bool
28+
Esc(cidr, v string) bool
2929
// Deletes cidr route. Returns true if cidr was found.
30-
Del(cidr *Gostr) bool
30+
Del(cidr string) bool
3131
// Gets the value of cidr or "" if cidr is not found.
32-
Get(cidr *Gostr) (*Gostr, error)
32+
Get(cidr string) (string, error)
3333
// Returns true if the cidr route is found.
34-
Has(cidr *Gostr) (bool, error)
34+
Has(cidr string) (bool, error)
3535
// Returns csv of all routes matching cidr or "".
36-
Routes(cidr *Gostr) *Gostr
36+
Routes(cidr string) string
3737
// Returns csv of values of all routes matching cidr or "".
38-
Values(cidr *Gostr) *Gostr
38+
Values(cidr string) string
3939
// Returns the route@csv(value) of any route matching cidr or "".
40-
GetAny(cidr *Gostr) (*Gostr, error)
40+
GetAny(cidr string) (string, error)
4141
// Returns true if any route matches cidr.
42-
HasAny(cidr *Gostr) (bool, error)
42+
HasAny(cidr string) (bool, error)
4343
// Removes values like v ("*v*") for cidr.
44-
EscLike(cidr, likev *Gostr) int32
44+
EscLike(cidr, likev string) int32
4545
// Returns csv of all routes with any value like v matching cidr.
46-
RoutesLike(cidr, likev *Gostr) *Gostr
46+
RoutesLike(cidr, likev string) string
4747
// Returns csv of all routes with values like v for cidr.
48-
ValuesLike(cidr, likev *Gostr) *Gostr
48+
ValuesLike(cidr, likev string) string
4949
// Returns csv of all values like v for cidr.
50-
GetLike(cidr, likev *Gostr) *Gostr
50+
GetLike(cidr, likev string) string
5151
// Returns the longest route for cidr as "r1@csv(v)|r2@csv(v2)" or "".
52-
GetAll(cidr *Gostr) (*Gostr, error)
52+
GetAll(cidr string) (string, error)
5353
// Deletes all routes matching cidr. Returns the number of routes deleted.
54-
DelAll(cidr *Gostr) int32
54+
DelAll(cidr string) int32
5555
// Clears the trie.
5656
Clear()
5757
// Returns the number of routes.
@@ -83,8 +83,8 @@ func NewIpTree() IpTree {
8383
return &iptree{t: critbitgo.NewNet()}
8484
}
8585

86-
func (c *iptree) Add(cidr *Gostr, v *Gostr) error {
87-
return c.add(cidr.V(), v.V())
86+
func (c *iptree) Add(cidr string, v string) error {
87+
return c.add(cidr, v)
8888
}
8989

9090
func (c *iptree) add(cidr string, v string) error {
@@ -108,9 +108,9 @@ func (c *iptree) add(cidr string, v string) error {
108108
return c.set(cidr, x+Vsep+v)
109109
}
110110

111-
func (c *iptree) Set(cidr *Gostr, v *Gostr) error {
112-
c.del(cidr.V()) // delete any previous value
113-
return c.add(cidr.V(), v.V())
111+
func (c *iptree) Set(cidr string, v string) error {
112+
c.del(cidr) // delete any previous value
113+
return c.add(cidr, v)
114114
}
115115

116116
func (c *iptree) set(cidr string, v string) error {
@@ -125,8 +125,8 @@ func (c *iptree) set(cidr string, v string) error {
125125
return c.t.Add(r, v)
126126
}
127127

128-
func (c *iptree) Del(cidr *Gostr) bool {
129-
return c.del(cidr.V())
128+
func (c *iptree) Del(cidr string) bool {
129+
return c.del(cidr)
130130
}
131131

132132
func (c *iptree) del(cidr string) bool {
@@ -142,8 +142,8 @@ func (c *iptree) del(cidr string) bool {
142142
return ok && err == nil
143143
}
144144

145-
func (c *iptree) Esc(cidr *Gostr, v *Gostr) bool {
146-
return c.esc(cidr.V(), v.V())
145+
func (c *iptree) Esc(cidr string, v string) bool {
146+
return c.esc(cidr, v)
147147
}
148148

149149
func (c *iptree) esc(cidr string, v string) bool {
@@ -170,8 +170,8 @@ func (c *iptree) esc(cidr string, v string) bool {
170170
return false
171171
}
172172

173-
func (c *iptree) Has(cidr *Gostr) (bool, error) {
174-
return c.has(cidr.V())
173+
func (c *iptree) Has(cidr string) (bool, error) {
174+
return c.has(cidr)
175175
}
176176

177177
func (c *iptree) has(cidr string) (bool, error) {
@@ -187,8 +187,8 @@ func (c *iptree) has(cidr string) (bool, error) {
187187
return ok, err
188188
}
189189

190-
func (c *iptree) DelAll(cidr *Gostr) (n int32) {
191-
return c.delAll(cidr.V())
190+
func (c *iptree) DelAll(cidr string) (n int32) {
191+
return c.delAll(cidr)
192192
}
193193

194194
func (c *iptree) delAll(cidr string) (n int32) {
@@ -214,8 +214,8 @@ func (c *iptree) delAll(cidr string) (n int32) {
214214
return
215215
}
216216

217-
func (c *iptree) HasAny(cidr *Gostr) (bool, error) {
218-
return c.hasAny(cidr.V())
217+
func (c *iptree) HasAny(cidr string) (bool, error) {
218+
return c.hasAny(cidr)
219219
}
220220

221221
func (c *iptree) hasAny(cidr string) (bool, error) {
@@ -231,12 +231,12 @@ func (c *iptree) hasAny(cidr string) (bool, error) {
231231
return m != nil, err
232232
}
233233

234-
func (c *iptree) Get(cidr *Gostr) (*Gostr, error) {
235-
r, err := c.get(cidr.V())
234+
func (c *iptree) Get(cidr string) (string, error) {
235+
r, err := c.get(cidr)
236236
if err != nil {
237-
return nil, err
237+
return "", err
238238
}
239-
return StrOf(r), nil // r may be empty
239+
return r, nil // r may be empty
240240
}
241241

242242
func (c *iptree) get(cidr string) (v string, err error) {
@@ -259,12 +259,12 @@ func (c *iptree) get(cidr string) (v string, err error) {
259259
return
260260
}
261261

262-
func (c *iptree) GetAny(cidr *Gostr) (*Gostr, error) {
263-
r, err := c.getAny(cidr.V())
262+
func (c *iptree) GetAny(cidr string) (string, error) {
263+
r, err := c.getAny(cidr)
264264
if err != nil {
265-
return nil, err
265+
return "", err
266266
}
267-
return StrOf(r), nil // r may be empty
267+
return r, nil // r may be empty
268268
}
269269

270270
func (c *iptree) getAny(cidr string) (rv string, err error) {
@@ -291,12 +291,12 @@ func (c *iptree) getAny(cidr string) (rv string, err error) {
291291
return
292292
}
293293

294-
func (c *iptree) GetAll(cidr *Gostr) (*Gostr, error) {
295-
r, err := c.getAll(cidr.V())
294+
func (c *iptree) GetAll(cidr string) (string, error) {
295+
r, err := c.getAll(cidr)
296296
if err != nil {
297-
return nil, err
297+
return "", err
298298
}
299-
return StrOf(r), nil // r may be empty
299+
return r, nil // r may be empty
300300
}
301301

302302
func (c *iptree) getAll(cidr string) (rv string, err error) {
@@ -324,8 +324,8 @@ func (c *iptree) getAll(cidr string) (rv string, err error) {
324324
return strings.TrimRight(rv, KVsep), nil
325325
}
326326

327-
func (c *iptree) Routes(cidr *Gostr) *Gostr {
328-
return StrOf(c.routes(cidr.V()))
327+
func (c *iptree) Routes(cidr string) string {
328+
return c.routes(cidr)
329329
}
330330

331331
func (c *iptree) routes(cidr string) string {
@@ -347,8 +347,8 @@ func (c *iptree) routes(cidr string) string {
347347
return strings.Join(rt, Ksep)
348348
}
349349

350-
func (c *iptree) Values(cidr *Gostr) *Gostr {
351-
return StrOf(c.values(cidr.V()))
350+
func (c *iptree) Values(cidr string) string {
351+
return c.values(cidr)
352352
}
353353

354354
func (c *iptree) values(cidr string) string {
@@ -372,8 +372,8 @@ func (c *iptree) values(cidr string) string {
372372
return strings.Join(vt, Vsep)
373373
}
374374

375-
func (c *iptree) EscLike(cidr, like *Gostr) int32 {
376-
return c.escLike(cidr.V(), like.V())
375+
func (c *iptree) EscLike(cidr, like string) int32 {
376+
return c.escLike(cidr, like)
377377
}
378378

379379
func (c *iptree) escLike(cidr, like string) int32 {
@@ -410,8 +410,8 @@ func (c *iptree) escLike(cidr, like string) int32 {
410410
return 0 // not found
411411
}
412412

413-
func (c *iptree) GetLike(cidr, like *Gostr) *Gostr {
414-
return StrOf(c.getLike(cidr.V(), like.V()))
413+
func (c *iptree) GetLike(cidr, like string) string {
414+
return c.getLike(cidr, like)
415415
}
416416

417417
func (c *iptree) getLike(cidr, like string) string {
@@ -435,8 +435,8 @@ func (c *iptree) getLike(cidr, like string) string {
435435
return "" // not found
436436
}
437437

438-
func (c *iptree) RoutesLike(cidr, like *Gostr) *Gostr {
439-
return StrOf(c.routesLike(cidr.V(), like.V()))
438+
func (c *iptree) RoutesLike(cidr, like string) string {
439+
return c.routesLike(cidr, like)
440440
}
441441

442442
func (c *iptree) routesLike(cidr, like string) string {
@@ -469,8 +469,8 @@ func (c *iptree) routesLike(cidr, like string) string {
469469
return strings.Join(rt, Ksep)
470470
}
471471

472-
func (c *iptree) ValuesLike(cidr, like *Gostr) *Gostr {
473-
return StrOf(c.valuesLike(cidr.V(), like.V()))
472+
func (c *iptree) ValuesLike(cidr, like string) string {
473+
return c.valuesLike(cidr, like)
474474
}
475475

476476
func (c *iptree) valuesLike(cidr, like string) string {

intra/backend/core_iptree_test.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,60 @@ import (
1010
func Test192(tst *testing.T) {
1111
log := tst.Log
1212
t := NewIpTree()
13-
t.Add(StrOf("192.0.0.0/8"), StrOf("app192:443"))
14-
t.Add(StrOf("192.0.0.0/8"), StrOf("dup192:443"))
15-
t.Add(StrOf("192.1.0.0/16"), StrOf("app192:80"))
16-
t.Add(StrOf("1.1.1.0/24"), StrOf("*:80"))
17-
t.Add(StrOf("192.1.0.0/16"), StrOf("app1921:80"))
18-
t.Set(StrOf("192.2.0.0/16"), StrOf("app1922:0"))
19-
t.Set(StrOf("192.2.0.0/16"), StrOf("app1922:unset"))
20-
t.Add(StrOf("192.1.1.1/32"), StrOf("app192111:0"))
21-
t.Add(StrOf("0.0.0.0/0"), StrOf("test0000"))
22-
t.Add(StrOf("192.0.0.0/8"), StrOf("app192:443"))
13+
t.Add("192.0.0.0/8", "app192:443")
14+
t.Add("192.0.0.0/8", "dup192:443")
15+
t.Add("192.1.0.0/16", "app192:80")
16+
t.Add("1.1.1.0/24", "*:80")
17+
t.Add("192.1.0.0/16", "app1921:80")
18+
t.Set("192.2.0.0/16", "app1922:0")
19+
t.Set("192.2.0.0/16", "app1922:unset")
20+
t.Add("192.1.1.1/32", "app192111:0")
21+
t.Add("0.0.0.0/0", "test0000")
22+
t.Add("192.0.0.0/8", "app192:443")
2323

24-
g8, err := t.Get(StrOf("192.0.0.0/8"))
24+
g8, err := t.Get("192.0.0.0/8")
2525
ko(tst, err)
26-
log("g8", g8.V()) // app192:443 dup192:443
26+
log("g8", g8) // app192:443 dup192:443
2727

28-
g16, err := t.Get(StrOf("192.1.0.0/16"))
29-
rmv := t.Esc(StrOf("1.1.0.0/16"), StrOf("test16.2")) // false
30-
g16any, err1 := t.GetAny(StrOf("192.1.0.0/16"))
28+
g16, err := t.Get("192.1.0.0/16")
29+
rmv := t.Esc("1.1.0.0/16", "test16.2") // false
30+
g16any, err1 := t.GetAny("192.1.0.0/16")
3131
ko(tst, err)
3232
ko(tst, err1)
33-
log("g16", g16.V(), "g16any", g16any.V(), "esc?", rmv)
33+
log("g16", g16, "g16any", g16any, "esc?", rmv)
3434

35-
g32any, err := t.GetAny(StrOf("192.1.1.2/32"))
35+
g32any, err := t.GetAny("192.1.1.2/32")
3636
ko(tst, err)
37-
log("g32any", g32any.V())
37+
log("g32any", g32any)
3838

39-
gall, err := t.GetAll(StrOf("192.1.1.1/32"))
39+
gall, err := t.GetAll("192.1.1.1/32")
4040
ko(tst, err)
41-
log("gall", gall.V())
41+
log("gall", gall)
4242

43-
route := t.Routes(StrOf("192.1.0.0/16"))
44-
rlike := t.RoutesLike(StrOf("192.1.0.0/16"), StrOf(":80"))
45-
val := t.Values(StrOf("192.1.0.0/16"))
46-
vlike := t.ValuesLike(StrOf("192.1.0.0/16"), StrOf(":80"))
47-
vlike2 := t.ValuesLike(StrOf("192.1.0.0/16"), StrOf("app192:80"))
48-
log("val", val.V())
49-
log("route", route.V())
50-
log("vlike", vlike.V(), "vlike(1app):", vlike2.V())
51-
log("rlike", rlike.V())
43+
route := t.Routes("192.1.0.0/16")
44+
rlike := t.RoutesLike("192.1.0.0/16", ":80")
45+
val := t.Values("192.1.0.0/16")
46+
vlike := t.ValuesLike("192.1.0.0/16", ":80")
47+
vlike2 := t.ValuesLike("192.1.0.0/16", "app192:80")
48+
log("val", val)
49+
log("route", route)
50+
log("vlike", vlike, "vlike(1app):", vlike2)
51+
log("rlike", rlike)
5252
}
5353

5454
func TestUn(tst *testing.T) {
5555
ll.SetLevel(ll.VVERBOSE)
5656
settings.Debug = true
5757

5858
trie := NewRadixTree()
59-
trie.Add(StrOf("fritz.box")) // exact domain
60-
trie.Add(StrOf(".lan")) // subdomain ending with .lan
61-
trie.Add(StrOf(".sub.tld")) // subdomain ending with .sub.tld
59+
trie.Add("fritz.box") // exact domain
60+
trie.Add(".lan") // subdomain ending with .lan
61+
trie.Add(".sub.tld") // subdomain ending with .sub.tld
6262

63-
noma1 := trie.HasAny(StrOf("test.fritz.box")) // no subdomain matches
64-
yma1 := trie.HasAny(StrOf("fritz.box")) // exact match for fritz.box
65-
yma2 := trie.HasAny(StrOf("test.lan")) // subdomain match for .lan
66-
yma3 := trie.HasAny(StrOf("mu.st.sub.tld")) // subdomain match for sub.tld
63+
noma1 := trie.HasAny("test.fritz.box") // no subdomain matches
64+
yma1 := trie.HasAny("fritz.box") // exact match for fritz.box
65+
yma2 := trie.HasAny("test.lan") // subdomain match for .lan
66+
yma3 := trie.HasAny("mu.st.sub.tld") // subdomain match for sub.tld
6767

6868
ll.V("no: %t, yes: [%t %t %t]", noma1, yma1, yma2, yma3)
6969
}

0 commit comments

Comments
 (0)