-
Notifications
You must be signed in to change notification settings - Fork 0
/
wildfire.go
61 lines (46 loc) · 886 Bytes
/
wildfire.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
package wildfire
import (
"bufio"
"fmt"
"github.com/aaomidi/wildfire/config"
"github.com/labstack/gommon/log"
"io"
"net"
)
const (
SocksVersion = 5
)
func Serve(config config.Config) {
listener, err := net.Listen("tcp", config.GetConnectionString())
if err != nil {
log.Error(err)
return
}
serve(&listener)
}
func serve(listener *net.Listener) {
for {
conn, err := (*listener).Accept()
if err != nil {
log.Error(err)
}
go serveConnection(conn)
}
}
func serveConnection(conn net.Conn) error {
defer conn.Close()
reader := bufio.NewReader(conn)
version := []byte{0}
nmethods := []byte{0}
_, err := io.ReadFull(reader, version)
if err != nil {
return err
}
_, err = io.ReadFull(reader, nmethods)
if err != nil {
return err
}
if version[0] != SocksVersion {
return fmt.Errorf("Unrecognized version number for connection.\n")
}
}