connection.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package internet
  2. import (
  3. "crypto/tls"
  4. "net"
  5. )
  6. type ConnectionHandler func(Connection)
  7. type Reusable interface {
  8. Reusable() bool
  9. SetReusable(reuse bool)
  10. }
  11. type StreamConnectionType int
  12. const (
  13. StreamConnectionTypeRawTCP StreamConnectionType = 1
  14. StreamConnectionTypeTCP StreamConnectionType = 2
  15. StreamConnectionTypeKCP StreamConnectionType = 4
  16. )
  17. type StreamSecurityType int
  18. const (
  19. StreamSecurityTypeNone StreamSecurityType = 0
  20. StreamSecurityTypeTLS StreamSecurityType = 1
  21. )
  22. type TLSSettings struct {
  23. Certs []tls.Certificate
  24. }
  25. func (this *TLSSettings) GetTLSConfig() *tls.Config {
  26. config := &tls.Config{
  27. InsecureSkipVerify: true,
  28. }
  29. config.Certificates = this.Certs
  30. config.BuildNameToCertificate()
  31. return config
  32. }
  33. type StreamSettings struct {
  34. Type StreamConnectionType
  35. Security StreamSecurityType
  36. TLSSettings *TLSSettings
  37. }
  38. func (this *StreamSettings) IsCapableOf(streamType StreamConnectionType) bool {
  39. return (this.Type & streamType) == streamType
  40. }
  41. type Connection interface {
  42. net.Conn
  43. Reusable
  44. }
  45. type SysFd interface {
  46. SysFd() (int, error)
  47. }