-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
socks5.go
46 lines (40 loc) · 1.34 KB
/
socks5.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
// Copyright (c) 2016-present Cloud <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 3 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package brook
import (
"github.com/txthinking/brook/limits"
"github.com/txthinking/socks5"
)
type Socks5Server struct {
Server *socks5.Server
}
func NewSocks5Server(addr, ip, userName, password string, tcpTimeout, udpTimeout int) (*Socks5Server, error) {
if err := limits.Raise(); err != nil {
Log(Error{"when": "try to raise system limits", "warning": err.Error()})
}
s5, err := socks5.NewClassicServer(addr, ip, userName, password, tcpTimeout, udpTimeout)
if err != nil {
return nil, err
}
x := &Socks5Server{
Server: s5,
}
return x, nil
}
func (x *Socks5Server) ListenAndServe() error {
return x.Server.ListenAndServe(nil)
}
func (x *Socks5Server) Shutdown() error {
return x.Server.Shutdown()
}