github.com/pion/webrtc/v4@v4.0.1/dtlstransportstate.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package webrtc 5 6 // DTLSTransportState indicates the DTLS transport establishment state. 7 type DTLSTransportState int 8 9 const ( 10 // DTLSTransportStateUnknown is the enum's zero-value 11 DTLSTransportStateUnknown DTLSTransportState = iota 12 13 // DTLSTransportStateNew indicates that DTLS has not started negotiating 14 // yet. 15 DTLSTransportStateNew 16 17 // DTLSTransportStateConnecting indicates that DTLS is in the process of 18 // negotiating a secure connection and verifying the remote fingerprint. 19 DTLSTransportStateConnecting 20 21 // DTLSTransportStateConnected indicates that DTLS has completed 22 // negotiation of a secure connection and verified the remote fingerprint. 23 DTLSTransportStateConnected 24 25 // DTLSTransportStateClosed indicates that the transport has been closed 26 // intentionally as the result of receipt of a close_notify alert, or 27 // calling close(). 28 DTLSTransportStateClosed 29 30 // DTLSTransportStateFailed indicates that the transport has failed as 31 // the result of an error (such as receipt of an error alert or failure to 32 // validate the remote fingerprint). 33 DTLSTransportStateFailed 34 ) 35 36 // This is done this way because of a linter. 37 const ( 38 dtlsTransportStateNewStr = "new" 39 dtlsTransportStateConnectingStr = "connecting" 40 dtlsTransportStateConnectedStr = "connected" 41 dtlsTransportStateClosedStr = "closed" 42 dtlsTransportStateFailedStr = "failed" 43 ) 44 45 func newDTLSTransportState(raw string) DTLSTransportState { 46 switch raw { 47 case dtlsTransportStateNewStr: 48 return DTLSTransportStateNew 49 case dtlsTransportStateConnectingStr: 50 return DTLSTransportStateConnecting 51 case dtlsTransportStateConnectedStr: 52 return DTLSTransportStateConnected 53 case dtlsTransportStateClosedStr: 54 return DTLSTransportStateClosed 55 case dtlsTransportStateFailedStr: 56 return DTLSTransportStateFailed 57 default: 58 return DTLSTransportStateUnknown 59 } 60 } 61 62 func (t DTLSTransportState) String() string { 63 switch t { 64 case DTLSTransportStateNew: 65 return dtlsTransportStateNewStr 66 case DTLSTransportStateConnecting: 67 return dtlsTransportStateConnectingStr 68 case DTLSTransportStateConnected: 69 return dtlsTransportStateConnectedStr 70 case DTLSTransportStateClosed: 71 return dtlsTransportStateClosedStr 72 case DTLSTransportStateFailed: 73 return dtlsTransportStateFailedStr 74 default: 75 return ErrUnknownType.Error() 76 } 77 } 78 79 // MarshalText implements encoding.TextMarshaler 80 func (t DTLSTransportState) MarshalText() ([]byte, error) { 81 return []byte(t.String()), nil 82 } 83 84 // UnmarshalText implements encoding.TextUnmarshaler 85 func (t *DTLSTransportState) UnmarshalText(b []byte) error { 86 *t = newDTLSTransportState(string(b)) 87 return nil 88 }