mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-18 07:17:32 -05:00
Added Stoppable listener for TLS listener
This commit is contained in:
parent
c8cd1320c7
commit
062d05fdcf
@ -83,7 +83,12 @@ func (wsl *WSListener) listenws(address v2net.Address, port v2net.Port) error {
|
||||
|
||||
if effectiveConfig.Pto == "wss" {
|
||||
listenerfunc = func() error {
|
||||
return http.ListenAndServeTLS(address.String()+":"+strconv.Itoa(int(port.Value())), effectiveConfig.Cert, effectiveConfig.PrivKey, nil)
|
||||
var err error
|
||||
wsl.listener, err = getstopableTLSlistener(effectiveConfig.Cert, effectiveConfig.PrivKey, address.String()+":"+strconv.Itoa(int(port.Value())))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return http.Serve(wsl.listener, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
18
transport/internet/ws/stopabletlslistener.go
Normal file
18
transport/internet/ws/stopabletlslistener.go
Normal file
@ -0,0 +1,18 @@
|
||||
package ws
|
||||
|
||||
import "crypto/tls"
|
||||
|
||||
func getstopableTLSlistener(cert, key, listenaddr string) (*StoppableListener, error) {
|
||||
cer, err := tls.LoadX509KeyPair(cert, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config := &tls.Config{Certificates: []tls.Certificate{cer}}
|
||||
ln, err := tls.Listen("tcp", listenaddr, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lns, err := NewStoppableListener(ln)
|
||||
return lns, err
|
||||
}
|
Loading…
Reference in New Issue
Block a user