/
net_proxy_uuds.go
62 lines (55 loc) · 1.5 KB
/
net_proxy_uuds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2020-2023 Zhang Jingcheng <diogin@gmail.com>.
// Copyright (c) 2022-2023 HexInfra Co., Ltd.
// All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE.md file.
// UUDS (UDP over Unix Domain Socket) proxy implementation.
package internal
func init() {
RegisterUDPSFilter("uudsProxy", func(name string, stage *Stage, mesher *UDPSMesher) UDPSFilter {
f := new(uudsProxy)
f.onCreate(name, stage, mesher)
return f
})
}
// uudsProxy passes UDP/DTLS links to backend UUDS server.
type uudsProxy struct {
// Mixins
UDPSFilter_
// Assocs
stage *Stage
mesher *UDPSMesher
backend *UUDSBackend
// States
}
func (f *uudsProxy) onCreate(name string, stage *Stage, mesher *UDPSMesher) {
f.MakeComp(name)
f.stage = stage
f.mesher = mesher
}
func (f *uudsProxy) OnShutdown() {
f.mesher.SubDone()
}
func (f *uudsProxy) OnConfigure() {
// toBackend
if v, ok := f.Find("toBackend"); ok {
if name, ok := v.String(); ok && name != "" {
if backend := f.stage.Backend(name); backend == nil {
UseExitf("unknown backend: '%s'\n", name)
} else if uudsBackend, ok := backend.(*UUDSBackend); ok {
f.backend = uudsBackend
} else {
UseExitf("incorrect backend '%s' for uudsProxy\n", name)
}
} else {
UseExitln("invalid toBackend")
}
} else {
UseExitln("toBackend is required for uudsProxy")
}
}
func (f *uudsProxy) OnPrepare() {
}
func (f *uudsProxy) Deal(link *UDPSLink) (next bool) { // reverse only
// TODO
return
}