-
Notifications
You must be signed in to change notification settings - Fork 1
/
gota.go
48 lines (40 loc) · 1.14 KB
/
gota.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
package gota
var (
Version = "gota_version"
Commit = "gota_commit"
)
// Gota provides quick usage for gota
type Gota struct {
ConnManager *ConnManager
TunnelManager *TunnelManager
}
func init() {
setupSIGUSR1Trap()
}
// NewGota returns a Gota with mounted ConnManager and TunnelManager
func NewGota(config interface{}, auth *TunnelAuthCredential) *Gota {
cm := NewConnManager()
tm := NewTunnelManager(cm.WriteToTunnelChannel(), cm.ReadFromTunnelChannel(), TMAuth(auth))
tm.SetConfig(config)
tm.SetCCIDChannel(cm.NewCCIDChannel())
tm.SetClientID(cm.clientID)
tm.cleanUpAllConnCh = cm.cleanUpCHChanClientID
return &Gota{
ConnManager: cm,
TunnelManager: tm,
}
}
// ListenAndServe listen at local for user connections and connect remote tunnel for forwarding traffic
func (g *Gota) ListenAndServe(addr string) {
g.TunnelManager.mode = ActiveMode
g.ConnManager.mode = ActiveMode
go g.TunnelManager.Start()
g.ConnManager.ListenAndServe(addr)
}
// Serve listen at local for tunnels
func (g *Gota) Serve(addr string) {
g.TunnelManager.mode = PassiveMode
g.ConnManager.mode = PassiveMode
go g.TunnelManager.Start()
g.ConnManager.Serve(addr)
}