dtlstransportstate.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package webrtc
  2. // DTLSTransportState indicates the DTLS transport establishment state.
  3. type DTLSTransportState int
  4. const (
  5. // DTLSTransportStateNew indicates that DTLS has not started negotiating
  6. // yet.
  7. DTLSTransportStateNew DTLSTransportState = iota + 1
  8. // DTLSTransportStateConnecting indicates that DTLS is in the process of
  9. // negotiating a secure connection and verifying the remote fingerprint.
  10. DTLSTransportStateConnecting
  11. // DTLSTransportStateConnected indicates that DTLS has completed
  12. // negotiation of a secure connection and verified the remote fingerprint.
  13. DTLSTransportStateConnected
  14. // DTLSTransportStateClosed indicates that the transport has been closed
  15. // intentionally as the result of receipt of a close_notify alert, or
  16. // calling close().
  17. DTLSTransportStateClosed
  18. // DTLSTransportStateFailed indicates that the transport has failed as
  19. // the result of an error (such as receipt of an error alert or failure to
  20. // validate the remote fingerprint).
  21. DTLSTransportStateFailed
  22. )
  23. // This is done this way because of a linter.
  24. const (
  25. dtlsTransportStateNewStr = "new"
  26. dtlsTransportStateConnectingStr = "connecting"
  27. dtlsTransportStateConnectedStr = "connected"
  28. dtlsTransportStateClosedStr = "closed"
  29. dtlsTransportStateFailedStr = "failed"
  30. )
  31. func newDTLSTransportState(raw string) DTLSTransportState {
  32. switch raw {
  33. case dtlsTransportStateNewStr:
  34. return DTLSTransportStateNew
  35. case dtlsTransportStateConnectingStr:
  36. return DTLSTransportStateConnecting
  37. case dtlsTransportStateConnectedStr:
  38. return DTLSTransportStateConnected
  39. case dtlsTransportStateClosedStr:
  40. return DTLSTransportStateClosed
  41. case dtlsTransportStateFailedStr:
  42. return DTLSTransportStateFailed
  43. default:
  44. return DTLSTransportState(Unknown)
  45. }
  46. }
  47. func (t DTLSTransportState) String() string {
  48. switch t {
  49. case DTLSTransportStateNew:
  50. return dtlsTransportStateNewStr
  51. case DTLSTransportStateConnecting:
  52. return dtlsTransportStateConnectingStr
  53. case DTLSTransportStateConnected:
  54. return dtlsTransportStateConnectedStr
  55. case DTLSTransportStateClosed:
  56. return dtlsTransportStateClosedStr
  57. case DTLSTransportStateFailed:
  58. return dtlsTransportStateFailedStr
  59. default:
  60. return ErrUnknownType.Error()
  61. }
  62. }