-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathhandler.go
More file actions
40 lines (36 loc) · 788 Bytes
/
handler.go
File metadata and controls
40 lines (36 loc) · 788 Bytes
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
package cracker
import (
"errors"
"fmt"
"io"
"strings"
"time"
)
type Handler struct {
Server string
Secret string
Interval time.Duration
}
func (h *Handler) Connect(addr string) (io.ReadWriteCloser, error) {
if strings.HasSuffix(h.Server, "/") {
h.Server = h.Server[:len(h.Server)-1]
}
conn := &localProxyConn{server: h.Server, secret: h.Secret, interval: h.Interval}
host := strings.Split(addr, ":")[0]
port := strings.Split(addr, ":")[1]
uuid, err := conn.connect(host, port)
if err != nil {
return nil, errors.New(fmt.Sprintf("connect %s %v", addr, err))
}
conn.uuid = uuid
if h.Interval == 0 {
err = conn.pull()
if err != nil {
return nil, err
}
}
conn.close = make(chan bool)
go conn.alive()
return conn, nil
}
func (h *Handler) Clean() {}