connection.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2015 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package model
  7. import (
  8. "crypto/tls"
  9. "net"
  10. "github.com/syncthing/syncthing/lib/protocol"
  11. )
  12. type IntermediateConnection struct {
  13. *tls.Conn
  14. Type ConnectionType
  15. }
  16. type Connection struct {
  17. net.Conn
  18. protocol.Connection
  19. Type ConnectionType
  20. }
  21. const (
  22. ConnectionTypeDirectAccept ConnectionType = iota
  23. ConnectionTypeDirectDial
  24. ConnectionTypeRelayAccept
  25. ConnectionTypeRelayDial
  26. )
  27. type ConnectionType int
  28. func (t ConnectionType) String() string {
  29. switch t {
  30. case ConnectionTypeDirectAccept:
  31. return "direct-accept"
  32. case ConnectionTypeDirectDial:
  33. return "direct-dial"
  34. case ConnectionTypeRelayAccept:
  35. return "relay-accept"
  36. case ConnectionTypeRelayDial:
  37. return "relay-dial"
  38. }
  39. return "unknown"
  40. }
  41. func (t ConnectionType) IsDirect() bool {
  42. return t == ConnectionTypeDirectAccept || t == ConnectionTypeDirectDial
  43. }