-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws_listener.go
68 lines (58 loc) · 1.29 KB
/
ws_listener.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
62
63
64
65
66
67
68
package lurker
import (
"context"
"fmt"
"github.com/portmapping/go-reuse"
"github.com/portmapping/lurker/common"
"net"
"net/http"
"github.com/portmapping/lurker/nat"
)
type wsListener struct {
ctx context.Context
cancel context.CancelFunc
port int
mappingPort int
nat nat.NAT
listener net.Listener
cfg *Config
ready bool
handler http.Handler
certFile string
keyFile string
}
// Listen ...
func (ws *wsListener) Listen(c chan<- Connector) (err error) {
tcpAddr := common.LocalTCPAddr(ws.port)
if ws.cfg.UseSecret {
ws.listener, err = reuse.ListenTLS("tcp", DefaultLocalTCPAddr.String(), ws.cfg.secret)
http.Serve(ws.listener, ws.handler)
} else {
ws.listener, err = reuse.ListenTCP("tcp", tcpAddr)
http.ServeTLS(ws.listener, ws.handler, ws.certFile, ws.keyFile)
}
if err != nil {
return err
}
fmt.Println("listen tcp on address:", tcpAddr.String())
ws.ready = true
return
}
// Stop ...
func (ws *wsListener) Stop() error {
panic("implement me")
}
// IsReady ...
func (ws *wsListener) IsReady() bool {
panic("implement me")
}
// IsSupport ...
func (ws *wsListener) IsSupport() bool {
panic("implement me")
}
// NAT ...
func (ws *wsListener) NAT() nat.NAT {
panic("implement me")
}
func (ws *wsListener) newHandle() {
}