github.com/pion/webrtc/v3@v3.2.24/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 // DTLSTransportStateNew indicates that DTLS has not started negotiating 11 // yet. 12 DTLSTransportStateNew DTLSTransportState = iota + 1 13 14 // DTLSTransportStateConnecting indicates that DTLS is in the process of 15 // negotiating a secure connection and verifying the remote fingerprint. 16 DTLSTransportStateConnecting 17 18 // DTLSTransportStateConnected indicates that DTLS has completed 19 // negotiation of a secure connection and verified the remote fingerprint. 20 DTLSTransportStateConnected 21 22 // DTLSTransportStateClosed indicates that the transport has been closed 23 // intentionally as the result of receipt of a close_notify alert, or 24 // calling close(). 25 DTLSTransportStateClosed 26 27 // DTLSTransportStateFailed indicates that the transport has failed as 28 // the result of an error (such as receipt of an error alert or failure to 29 // validate the remote fingerprint). 30 DTLSTransportStateFailed 31 ) 32 33 // This is done this way because of a linter. 34 const ( 35 dtlsTransportStateNewStr = "new" 36 dtlsTransportStateConnectingStr = "connecting" 37 dtlsTransportStateConnectedStr = "connected" 38 dtlsTransportStateClosedStr = "closed" 39 dtlsTransportStateFailedStr = "failed" 40 ) 41 42 func newDTLSTransportState(raw string) DTLSTransportState { 43 switch raw { 44 case dtlsTransportStateNewStr: 45 return DTLSTransportStateNew 46 case dtlsTransportStateConnectingStr: 47 return DTLSTransportStateConnecting 48 case dtlsTransportStateConnectedStr: 49 return DTLSTransportStateConnected 50 case dtlsTransportStateClosedStr: 51 return DTLSTransportStateClosed 52 case dtlsTransportStateFailedStr: 53 return DTLSTransportStateFailed 54 default: 55 return DTLSTransportState(Unknown) 56 } 57 } 58 59 func (t DTLSTransportState) String() string { 60 switch t { 61 case DTLSTransportStateNew: 62 return dtlsTransportStateNewStr 63 case DTLSTransportStateConnecting: 64 return dtlsTransportStateConnectingStr 65 case DTLSTransportStateConnected: 66 return dtlsTransportStateConnectedStr 67 case DTLSTransportStateClosed: 68 return dtlsTransportStateClosedStr 69 case DTLSTransportStateFailed: 70 return dtlsTransportStateFailedStr 71 default: 72 return ErrUnknownType.Error() 73 } 74 } 75 76 // MarshalText implements encoding.TextMarshaler 77 func (t DTLSTransportState) MarshalText() ([]byte, error) { 78 return []byte(t.String()), nil 79 } 80 81 // UnmarshalText implements encoding.TextUnmarshaler 82 func (t *DTLSTransportState) UnmarshalText(b []byte) error { 83 *t = newDTLSTransportState(string(b)) 84 return nil 85 }