1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/transport/internet/connection.go

65 lines
1.2 KiB
Go
Raw Normal View History

2016-06-14 16:54:08 -04:00
package internet
import (
2016-07-10 09:27:58 -04:00
"crypto/tls"
2016-06-14 16:54:08 -04:00
"net"
)
type ConnectionHandler func(Connection)
type Reusable interface {
Reusable() bool
SetReusable(reuse bool)
}
type StreamConnectionType int
2016-07-10 09:27:58 -04:00
const (
2016-08-13 09:41:13 -04:00
StreamConnectionTypeRawTCP StreamConnectionType = 1
StreamConnectionTypeTCP StreamConnectionType = 2
StreamConnectionTypeKCP StreamConnectionType = 4
StreamConnectionTypeWebSocket StreamConnectionType = 8
2016-06-14 16:54:08 -04:00
)
2016-07-10 09:27:58 -04:00
type StreamSecurityType int
const (
StreamSecurityTypeNone StreamSecurityType = 0
StreamSecurityTypeTLS StreamSecurityType = 1
)
type TLSSettings struct {
2016-07-10 09:30:48 -04:00
AllowInsecure bool
Certs []tls.Certificate
2016-07-10 09:27:58 -04:00
}
func (this *TLSSettings) GetTLSConfig() *tls.Config {
config := &tls.Config{
2016-07-10 09:30:48 -04:00
InsecureSkipVerify: this.AllowInsecure,
2016-07-10 09:27:58 -04:00
}
config.Certificates = this.Certs
config.BuildNameToCertificate()
return config
}
2016-06-14 16:54:08 -04:00
type StreamSettings struct {
2016-07-10 09:27:58 -04:00
Type StreamConnectionType
Security StreamSecurityType
TLSSettings *TLSSettings
2016-06-14 16:54:08 -04:00
}
func (this *StreamSettings) IsCapableOf(streamType StreamConnectionType) bool {
return (this.Type & streamType) == streamType
}
type Connection interface {
net.Conn
Reusable
}
2016-06-29 18:08:20 -04:00
type SysFd interface {
SysFd() (int, error)
}