-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
56 lines (46 loc) · 988 Bytes
/
config.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
package client
import (
"crypto/tls"
"net"
"net/url"
"time"
"github.com/gorilla/websocket"
"github.com/YuanDdQiao/websocks/core"
)
type Config struct {
ListenAddr string
ServerURL string
SNI string
InsecureCert bool
Mux bool
}
//GetClient return client from path
func (config *Config) GetClient() (client *WebSocksClient, err error) {
//tackle config
serverURL, err := url.Parse(config.ServerURL)
if err != nil {
return
}
laddr, err := net.ResolveTCPAddr("tcp", config.ListenAddr)
if err != nil {
return
}
tlsConfig := &tls.Config{
InsecureSkipVerify: config.InsecureCert,
ServerName: config.SNI,
}
client = &WebSocksClient{
ServerURL: serverURL,
ListenAddr: laddr,
dialer: &websocket.Dialer{
ReadBufferSize: 4 * 1024,
WriteBufferSize: 4 * 1024,
HandshakeTimeout: 10 * time.Second,
TLSClientConfig: tlsConfig,
},
Mux: config.Mux,
CreatedAt: time.Now(),
Stats: core.NewStats(),
}
return
}