(addr, ip, server, password string, tcpTimeout, udpTimeout int, withoutbrook bool)
| 39 | } |
| 40 | |
| 41 | func NewWSClient(addr, ip, server, password string, tcpTimeout, udpTimeout int, withoutbrook bool) (*WSClient, error) { |
| 42 | if err := limits.Raise(); err != nil { |
| 43 | Log(Error{"when": "try to raise system limits", "warning": err.Error()}) |
| 44 | } |
| 45 | s5, err := socks5.NewClassicServer(addr, ip, "", "", tcpTimeout, udpTimeout) |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | u, err := url.Parse(server) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | path := u.Path |
| 54 | if path == "" { |
| 55 | path = "/ws" |
| 56 | } |
| 57 | p := []byte(password) |
| 58 | if withoutbrook { |
| 59 | p, err = SHA256Bytes([]byte(password)) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | } |
| 64 | x := &WSClient{ |
| 65 | ServerHost: u.Host, |
| 66 | Server: s5, |
| 67 | Password: p, |
| 68 | TCPTimeout: tcpTimeout, |
| 69 | UDPTimeout: udpTimeout, |
| 70 | Path: path, |
| 71 | WithoutBrook: withoutbrook, |
| 72 | PacketConnFactory: NewPacketConnFactory(), |
| 73 | } |
| 74 | if u.Scheme == "wss" { |
| 75 | h, _, err := net.SplitHostPort(u.Host) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | x.TLSConfig = &tls.Config{ServerName: h, NextProtos: []string{"http/1.1"}} |
| 80 | } |
| 81 | return x, nil |
| 82 | } |
| 83 | |
| 84 | func (x *WSClient) ListenAndServe() error { |
| 85 | return x.Server.ListenAndServe(x) |
nothing calls this directly
no test coverage detected