mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-28 04:55:37 -05:00
tls config
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package internet
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2tls "github.com/v2ray/v2ray-core/transport/internet/tls"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -29,6 +31,7 @@ type TCPHub struct {
|
||||
listener Listener
|
||||
connCallback ConnectionHandler
|
||||
accepting bool
|
||||
tlsConfig *tls.Config
|
||||
}
|
||||
|
||||
func ListenTCP(address v2net.Address, port v2net.Port, callback ConnectionHandler, settings *StreamSettings) (*TCPHub, error) {
|
||||
@@ -51,9 +54,15 @@ func ListenTCP(address v2net.Address, port v2net.Port, callback ConnectionHandle
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tlsConfig *tls.Config
|
||||
if settings.Security == StreamSecurityTypeTLS {
|
||||
tlsConfig = settings.TLSSettings.GetTLSConfig()
|
||||
}
|
||||
|
||||
hub := &TCPHub{
|
||||
listener: listener,
|
||||
connCallback: callback,
|
||||
tlsConfig: tlsConfig,
|
||||
}
|
||||
|
||||
go hub.start()
|
||||
@@ -76,6 +85,10 @@ func (this *TCPHub) start() {
|
||||
}
|
||||
continue
|
||||
}
|
||||
if this.tlsConfig != nil {
|
||||
tlsConn := tls.Server(conn, this.tlsConfig)
|
||||
conn = v2tls.NewConnection(tlsConn)
|
||||
}
|
||||
go this.connCallback(conn)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user