mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-06 10:16:40 -05:00
tcphub now takes tls config as construtor parameter
This commit is contained in:
parent
f594f5b606
commit
7d43952690
@ -107,7 +107,7 @@ func (this *DokodemoDoor) handleUDPPackets(payload *alloc.Buffer, dest v2net.Des
|
||||
}
|
||||
|
||||
func (this *DokodemoDoor) ListenTCP(port v2net.Port) error {
|
||||
tcpListener, err := hub.ListenTCP(port, this.HandleTCPConnection)
|
||||
tcpListener, err := hub.ListenTCP(port, this.HandleTCPConnection, nil)
|
||||
if err != nil {
|
||||
log.Error("Dokodemo: Failed to listen on port ", port, ": ", err)
|
||||
return err
|
||||
|
@ -60,7 +60,7 @@ func (this *HttpProxyServer) Listen(port v2net.Port) error {
|
||||
}
|
||||
this.listeningPort = port
|
||||
|
||||
tcpListener, err := hub.ListenTCP(port, this.handleConnection)
|
||||
tcpListener, err := hub.ListenTCP(port, this.handleConnection, nil)
|
||||
if err != nil {
|
||||
log.Error("Http: Failed listen on port ", port, ": ", err)
|
||||
return err
|
||||
|
@ -65,7 +65,7 @@ func (this *Shadowsocks) Listen(port v2net.Port) error {
|
||||
}
|
||||
}
|
||||
|
||||
tcpHub, err := hub.ListenTCP(port, this.handleConnection)
|
||||
tcpHub, err := hub.ListenTCP(port, this.handleConnection, nil)
|
||||
if err != nil {
|
||||
log.Error("Shadowsocks: Failed to listen TCP on port ", port, ": ", err)
|
||||
return err
|
||||
|
@ -77,7 +77,7 @@ func (this *Server) Listen(port v2net.Port) error {
|
||||
}
|
||||
this.listeningPort = port
|
||||
|
||||
listener, err := hub.ListenTCP(port, this.handleConnection)
|
||||
listener, err := hub.ListenTCP(port, this.handleConnection, nil)
|
||||
if err != nil {
|
||||
log.Error("Socks: failed to listen on port ", port, ": ", err)
|
||||
return err
|
||||
|
@ -103,7 +103,7 @@ func (this *VMessInboundHandler) Listen(port v2net.Port) error {
|
||||
}
|
||||
this.listeningPort = port
|
||||
|
||||
tcpListener, err := hub.ListenTCP(port, this.HandleConnection)
|
||||
tcpListener, err := hub.ListenTCP(port, this.HandleConnection, nil)
|
||||
if err != nil {
|
||||
log.Error("Unable to listen tcp port ", port, ": ", err)
|
||||
return err
|
||||
|
@ -1,6 +1,7 @@
|
||||
package hub
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
@ -13,12 +14,12 @@ var (
|
||||
)
|
||||
|
||||
type TCPHub struct {
|
||||
listener *net.TCPListener
|
||||
listener net.Listener
|
||||
connCallback ConnectionHandler
|
||||
accepting bool
|
||||
}
|
||||
|
||||
func ListenTCP(port v2net.Port, callback ConnectionHandler) (*TCPHub, error) {
|
||||
func ListenTCP(port v2net.Port, callback ConnectionHandler, tlsConfig *tls.Config) (*TCPHub, error) {
|
||||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||
IP: []byte{0, 0, 0, 0},
|
||||
Port: int(port),
|
||||
@ -27,12 +28,22 @@ func ListenTCP(port v2net.Port, callback ConnectionHandler) (*TCPHub, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tcpListener := &TCPHub{
|
||||
listener: listener,
|
||||
connCallback: callback,
|
||||
var hub *TCPHub
|
||||
if tlsConfig != nil {
|
||||
tlsListener := tls.NewListener(listener, tlsConfig)
|
||||
hub = &TCPHub{
|
||||
listener: tlsListener,
|
||||
connCallback: callback,
|
||||
}
|
||||
} else {
|
||||
hub = &TCPHub{
|
||||
listener: listener,
|
||||
connCallback: callback,
|
||||
}
|
||||
}
|
||||
go tcpListener.start()
|
||||
return tcpListener, nil
|
||||
|
||||
go hub.start()
|
||||
return hub, nil
|
||||
}
|
||||
|
||||
func (this *TCPHub) Close() {
|
||||
@ -44,7 +55,7 @@ func (this *TCPHub) Close() {
|
||||
func (this *TCPHub) start() {
|
||||
this.accepting = true
|
||||
for this.accepting {
|
||||
conn, err := this.listener.AcceptTCP()
|
||||
conn, err := this.listener.Accept()
|
||||
if err != nil {
|
||||
if this.accepting {
|
||||
log.Warning("Listener: Failed to accept new TCP connection: ", err)
|
||||
|
Loading…
Reference in New Issue
Block a user