forked from txthinking/brook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socks5.go
52 lines (45 loc) · 1.5 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
47
48
49
50
51
52
// Copyright (c) 2016-present Cloud <cloud@txthinking.com>
//
// 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 (
"log"
"github.com/txthinking/brook/limits"
"github.com/txthinking/socks5"
)
// Socks5Server is raw socks5 server.
type Socks5Server struct {
Server *socks5.Server
}
// NewSocks5Server returns a new Socks5Server.
func NewSocks5Server(addr, ip, userName, password string, tcpTimeout, udpTimeout int) (*Socks5Server, error) {
s5, err := socks5.NewClassicServer(addr, ip, userName, password, tcpTimeout, udpTimeout)
if err != nil {
return nil, err
}
if err := limits.Raise(); err != nil {
log.Println("Try to raise system limits, got", err)
}
x := &Socks5Server{
Server: s5,
}
return x, nil
}
// ListenAndServe will let client start to listen and serve.
func (x *Socks5Server) ListenAndServe() error {
return x.Server.ListenAndServe(nil)
}
// Shutdown used to stop the client.
func (x *Socks5Server) Shutdown() error {
return x.Server.Shutdown()
}