-
Notifications
You must be signed in to change notification settings - Fork 12
/
connection.go
73 lines (59 loc) · 1.68 KB
/
connection.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
63
64
65
66
67
68
69
70
71
72
73
package clients
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"strings"
"github.com/Doridian/wsvpn/client/connectors"
"github.com/Doridian/wsvpn/shared"
"github.com/Doridian/wsvpn/shared/commands"
)
func (c *Client) GetProxyURL() *url.URL {
return c.ProxyURL
}
func (c *Client) GetTLSConfig() *tls.Config {
return c.TLSConfig.Clone()
}
func (c *Client) GetHeaders() http.Header {
return c.Headers.Clone()
}
func (c *Client) GetServerURL() *url.URL {
return c.ServerURL
}
func (c *Client) EnhanceConn(conn net.Conn) error {
if c.FirewallMark <= 0 {
return nil
}
return setFirewallMark(conn, c.FirewallMark)
}
func (c *Client) RegisterDefaultConnectors() {
c.registerConnector(connectors.NewWebSocketConnector())
c.registerConnector(connectors.NewWebTransportConnector())
}
func (c *Client) registerConnector(connector connectors.SocketConnector) {
for _, scheme := range connector.GetSchemes() {
c.connectors[scheme] = connector
}
}
func (c *Client) connectAdapter() error {
scheme := strings.ToLower(c.ServerURL.Scheme)
connector, ok := c.connectors[scheme]
if !ok {
return fmt.Errorf("invalid protocol: %s", scheme)
}
adapter, err := connector.Dial(c)
if err != nil {
return err
}
c.adapter = adapter
c.log.Printf("Command serialization: %s", commands.SerializationTypeToString(adapter.GetCommandSerializationType()))
tlsConnState, ok := c.adapter.GetTLSConnectionState()
if ok {
c.log.Printf("TLS %s %s connection established with cipher=%s", shared.TLSVersionString(tlsConnState.Version), c.adapter.Name(), tls.CipherSuiteName(tlsConnState.CipherSuite))
} else {
c.log.Printf("Unencrypted %s connection established", c.adapter.Name())
}
return nil
}