1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-06-19 09:19:55 -04:00

protobuf for stream settings

This commit is contained in:
Darien Raymond
2016-10-02 23:43:58 +02:00
parent 5ec948f690
commit 1d13f47f9c
59 changed files with 1243 additions and 323 deletions

View File

@@ -1,7 +1,6 @@
package internet
import (
"crypto/tls"
"net"
)
@@ -12,56 +11,6 @@ type Reusable interface {
SetReusable(reuse bool)
}
type StreamConnectionType int
const (
StreamConnectionTypeRawTCP StreamConnectionType = 1
StreamConnectionTypeTCP StreamConnectionType = 2
StreamConnectionTypeKCP StreamConnectionType = 4
StreamConnectionTypeWebSocket StreamConnectionType = 8
)
type StreamSecurityType int
const (
StreamSecurityTypeNone StreamSecurityType = 0
StreamSecurityTypeTLS StreamSecurityType = 1
)
var (
globalSessionCache = tls.NewLRUClientSessionCache(128)
)
type TLSSettings struct {
AllowInsecure bool
Certs []tls.Certificate
}
func (this *TLSSettings) GetTLSConfig() *tls.Config {
config := &tls.Config{
ClientSessionCache: globalSessionCache,
}
if this == nil {
return config
}
config.InsecureSkipVerify = this.AllowInsecure
config.Certificates = this.Certs
config.BuildNameToCertificate()
return config
}
type StreamSettings struct {
Type StreamConnectionType
Security StreamSecurityType
TLSSettings *TLSSettings
}
func (this *StreamSettings) IsCapableOf(streamType StreamConnectionType) bool {
return (this.Type & streamType) == streamType
}
type Connection interface {
net.Conn
Reusable