Skip to main content

rtc_shared/
error.rs

1//! The error type shared across the stack.
2//!
3//! One [`Error`](crate::error::Error) enum spans every layer — buffers, UDP, ICE, DTLS, SCTP, SRTP, RTP/RTCP, SDP and
4//! the data channel — so a value can propagate from the innermost codec to the application
5//! without conversion at each boundary. The higher-level crates re-export it, which is why an
6//! application only ever imports one error type.
7#![allow(dead_code)]
8
9use std::io;
10use std::net;
11use std::net::SocketAddr;
12use std::num::ParseIntError;
13use std::string::FromUtf8Error;
14use std::time::SystemTimeError;
15use substring::Substring;
16use thiserror::Error;
17
18/// A type alias for `std::result::Result` with this crate's [`enum@Error`] type.
19pub type Result<T> = std::result::Result<T, Error>;
20
21/// Unified error type for all WebRTC sub-protocols.
22///
23/// Aggregates errors from every layer of the WebRTC stack — buffers, RTP/RTCP,
24/// SRTP, STUN, TURN, ICE, DTLS, SCTP, data channels, SDP, mDNS, and the
25/// top-level peer connection — into a single enum so callers only need to
26/// handle one error type.
27///
28/// The enum is `#[non_exhaustive]`: new variants may be added in future
29/// releases without a semver-breaking change.
30#[derive(Error, Debug, PartialEq)]
31#[non_exhaustive]
32pub enum Error {
33    /// Buffer: full.
34    #[error("buffer: full")]
35    ErrBufferFull,
36    /// Buffer: closed.
37    #[error("buffer: closed")]
38    ErrBufferClosed,
39    /// Buffer: short.
40    #[error("buffer: short")]
41    ErrBufferShort,
42    /// Packet too big.
43    #[error("packet too big")]
44    ErrPacketTooBig,
45    /// I/O timeout.
46    #[error("i/o timeout")]
47    ErrTimeout,
48    /// UDP: listener closed.
49    #[error("udp: listener closed")]
50    ErrClosedListener,
51    /// UDP: listen queue exceeded.
52    #[error("udp: listen queue exceeded")]
53    ErrListenQueueExceeded,
54    /// UDP: listener accept ch closed.
55    #[error("udp: listener accept ch closed")]
56    ErrClosedListenerAcceptCh,
57    /// Obs cannot be nil.
58    #[error("obs cannot be nil")]
59    ErrObsCannotBeNil,
60    /// Se of closed network connection.
61    #[error("se of closed network connection")]
62    ErrUseClosedNetworkConn,
63    /// Addr is not a net.UDPAddr.
64    #[error("addr is not a net.UDPAddr")]
65    ErrAddrNotUdpAddr,
66    /// Something went wrong with locAddr.
67    #[error("something went wrong with locAddr")]
68    ErrLocAddr,
69    /// Already closed.
70    #[error("already closed")]
71    ErrAlreadyClosed,
72    /// No remAddr defined.
73    #[error("no remAddr defined")]
74    ErrNoRemAddr,
75    /// Address already in use.
76    #[error("address already in use")]
77    ErrAddressAlreadyInUse,
78    /// No such UDPConn.
79    #[error("no such UDPConn")]
80    ErrNoSuchUdpConn,
81    /// Cannot remove unspecified IP by the specified IP.
82    #[error("cannot remove unspecified IP by the specified IP")]
83    ErrCannotRemoveUnspecifiedIp,
84    /// No address assigned.
85    #[error("no address assigned")]
86    ErrNoAddressAssigned,
87    /// 1:1 NAT requires more than one mapping.
88    #[error("1:1 NAT requires more than one mapping")]
89    ErrNatRequriesMapping,
90    /// Length mismtach between mappedIPs and localIPs.
91    #[error("length mismtach between mappedIPs and localIPs")]
92    ErrMismatchLengthIp,
93    /// Non-udp translation is not supported yet.
94    #[error("non-udp translation is not supported yet")]
95    ErrNonUdpTranslationNotSupported,
96    /// No associated local address.
97    #[error("no associated local address")]
98    ErrNoAssociatedLocalAddress,
99    /// No NAT binding found.
100    #[error("no NAT binding found")]
101    ErrNoNatBindingFound,
102    /// Has no permission.
103    #[error("has no permission")]
104    ErrHasNoPermission,
105    /// Host name must not be empty.
106    #[error("host name must not be empty")]
107    ErrHostnameEmpty,
108    /// Failed to parse IP address.
109    #[error("failed to parse IP address")]
110    ErrFailedToParseIpaddr,
111    /// No interface is available.
112    #[error("no interface is available")]
113    ErrNoInterface,
114    /// Not found.
115    #[error("not found")]
116    ErrNotFound,
117    /// Unexpected network.
118    #[error("unexpected network")]
119    ErrUnexpectedNetwork,
120    /// Can't assign requested address.
121    #[error("can't assign requested address")]
122    ErrCantAssignRequestedAddr,
123    /// Unknown network.
124    #[error("unknown network")]
125    ErrUnknownNetwork,
126    /// No router linked.
127    #[error("no router linked")]
128    ErrNoRouterLinked,
129    /// Invalid port number.
130    #[error("invalid port number")]
131    ErrInvalidPortNumber,
132    /// Unexpected type-switch failure.
133    #[error("unexpected type-switch failure")]
134    ErrUnexpectedTypeSwitchFailure,
135    /// Bind failed.
136    #[error("bind failed")]
137    ErrBindFailed,
138    /// End port is less than the start.
139    #[error("end port is less than the start")]
140    ErrEndPortLessThanStart,
141    /// Port space exhausted.
142    #[error("port space exhausted")]
143    ErrPortSpaceExhausted,
144    /// Vnet is not enabled.
145    #[error("vnet is not enabled")]
146    ErrVnetDisabled,
147    /// Invalid local IP in static_ips.
148    #[error("invalid local IP in static_ips")]
149    ErrInvalidLocalIpInStaticIps,
150    /// Mapped in static_ips is beyond subnet.
151    #[error("mapped in static_ips is beyond subnet")]
152    ErrLocalIpBeyondStaticIpsSubset,
153    /// All static_ips must have associated local IPs.
154    #[error("all static_ips must have associated local IPs")]
155    ErrLocalIpNoStaticsIpsAssociated,
156    /// Router already started.
157    #[error("router already started")]
158    ErrRouterAlreadyStarted,
159    /// Router already stopped.
160    #[error("router already stopped")]
161    ErrRouterAlreadyStopped,
162    /// Static IP is beyond subnet.
163    #[error("static IP is beyond subnet")]
164    ErrStaticIpIsBeyondSubnet,
165    /// Address space exhausted.
166    #[error("address space exhausted")]
167    ErrAddressSpaceExhausted,
168    /// No IP address is assigned for eth0.
169    #[error("no IP address is assigned for eth0")]
170    ErrNoIpaddrEth0,
171    /// Invalid mask.
172    #[error("Invalid mask")]
173    ErrInvalidMask,
174
175    //ExportKeyingMaterial errors
176    /// TLS handshake is in progress.
177    #[error("tls handshake is in progress")]
178    HandshakeInProgress,
179    /// Context is not supported for export_keying_material.
180    #[error("context is not supported for export_keying_material")]
181    ContextUnsupported,
182    /// Export_keying_material can not be used with a reserved label.
183    #[error("export_keying_material can not be used with a reserved label")]
184    ReservedExportKeyingMaterial,
185    /// No cipher suite for export_keying_material.
186    #[error("no cipher suite for export_keying_material")]
187    CipherSuiteUnset,
188    /// Export_keying_material hash.
189    #[error("export_keying_material hash: {0}")]
190    Hash(String),
191    /// Mutex poison.
192    #[error("mutex poison: {0}")]
193    PoisonError(String),
194
195    //RTCP errors
196    /// Wrong marshal size.
197    #[error("Wrong marshal size")]
198    WrongMarshalSize,
199    /// Packet lost exceeds maximum amount of packets
200    /// that can possibly be lost.
201    #[error("Invalid total lost count")]
202    InvalidTotalLost,
203    /// Packet contains an invalid header.
204    #[error("Invalid header")]
205    InvalidHeader,
206    /// Packet contains empty compound.
207    #[error("Empty compound packet")]
208    EmptyCompound,
209    /// Invalid first packet in compound packets. First packet
210    /// should either be a SenderReport packet or ReceiverReport
211    #[error("First packet in compound must be SR or RR")]
212    BadFirstPacket,
213    /// CNAME was not defined.
214    #[error("Compound missing SourceDescription with CNAME")]
215    MissingCname,
216    /// Packet was defined before CNAME.
217    #[error("Feedback packet seen before CNAME")]
218    PacketBeforeCname,
219    /// Too many reports.
220    #[error("Too many reports")]
221    TooManyReports,
222    /// Too many chunks.
223    #[error("Too many chunks")]
224    TooManyChunks,
225    /// Too many sources.
226    #[error("too many sources")]
227    TooManySources,
228    /// Packet received is too short.
229    #[error("Packet too short to be read")]
230    PacketTooShort,
231    /// Buffer is too short.
232    #[error("Buffer too short to be written")]
233    BufferTooShort,
234    /// Wrong packet type.
235    #[error("Wrong packet type")]
236    WrongType,
237    /// SDES received is too long.
238    #[error("SDES must be < 255 octets long")]
239    SdesTextTooLong,
240    /// SDES type is missing.
241    #[error("SDES item missing type")]
242    SdesMissingType,
243    /// Reason is too long.
244    #[error("Reason must be < 255 octets long")]
245    ReasonTooLong,
246    /// Invalid packet version.
247    #[error("Invalid packet version")]
248    BadVersion,
249    /// Invalid padding value.
250    #[error("Invalid padding value")]
251    WrongPadding,
252    /// Wrong feedback message type.
253    #[error("Wrong feedback message type")]
254    WrongFeedbackType,
255    /// Wrong payload type.
256    #[error("Wrong payload type")]
257    WrongPayloadType,
258    /// Header length is too small.
259    #[error("Header length is too small")]
260    HeaderTooSmall,
261    /// Media ssrc was defined as zero.
262    #[error("Media SSRC must be 0")]
263    SsrcMustBeZero,
264    /// Missing REMB identifier.
265    #[error("Missing REMB identifier")]
266    MissingRembIdentifier,
267    /// SSRC number and length mismatches.
268    #[error("SSRC num and length do not match")]
269    SsrcNumAndLengthMismatch,
270    /// Invalid size or start index.
271    #[error("Invalid size or startIndex")]
272    InvalidSizeOrStartIndex,
273    /// Delta exceeds limit.
274    #[error("Delta exceed limit")]
275    DeltaExceedLimit,
276    /// Packet status chunk is not 2 bytes.
277    #[error("Packet status chunk must be 2 bytes")]
278    PacketStatusChunkLength,
279    /// Invalid bitrate.
280    #[error("Invalid bitrate")]
281    InvalidBitrate,
282    /// Wrong chunk type.
283    #[error("Wrong chunk type")]
284    WrongChunkType,
285    /// Struct contains unexpected member type.
286    #[error("Struct contains unexpected member type")]
287    BadStructMemberType,
288    /// Cannot read into non-pointer.
289    #[error("Cannot read into non-pointer")]
290    BadReadParameter,
291    /// Invalid block size.
292    #[error("Invalid block size")]
293    InvalidBlockSize,
294
295    //RTP errors
296    /// RTP header size insufficient.
297    #[error("RTP header size insufficient")]
298    ErrHeaderSizeInsufficient,
299    /// RTP header size insufficient for extension.
300    #[error("RTP header size insufficient for extension")]
301    ErrHeaderSizeInsufficientForExtension,
302    /// Buffer too small.
303    #[error("buffer too small")]
304    ErrBufferTooSmall,
305    /// Extension not enabled.
306    #[error("extension not enabled")]
307    ErrHeaderExtensionsNotEnabled,
308    /// Extension not found.
309    #[error("extension not found")]
310    ErrHeaderExtensionNotFound,
311
312    /// Header extension id must be between 1 and 14 for RFC 5285 extensions.
313    #[error("header extension id must be between 1 and 14 for RFC 5285 extensions")]
314    ErrRfc8285oneByteHeaderIdrange,
315    /// Header extension payload must be 16bytes or less for RFC 5285 one byte extensions.
316    #[error("header extension payload must be 16bytes or less for RFC 5285 one byte extensions")]
317    ErrRfc8285oneByteHeaderSize,
318
319    /// Header extension id must be between 1 and 255 for RFC 5285 extensions.
320    #[error("header extension id must be between 1 and 255 for RFC 5285 extensions")]
321    ErrRfc8285twoByteHeaderIdrange,
322    /// Header extension payload must be 255bytes or less for RFC 5285 two byte extensions.
323    #[error("header extension payload must be 255bytes or less for RFC 5285 two byte extensions")]
324    ErrRfc8285twoByteHeaderSize,
325
326    /// Header extension id must be 0 for none RFC 5285 extensions.
327    #[error("header extension id must be 0 for none RFC 5285 extensions")]
328    ErrRfc3550headerIdrange,
329
330    /// Packet is not large enough.
331    #[error("packet is not large enough")]
332    ErrShortPacket,
333    /// Invalid nil packet.
334    #[error("invalid nil packet")]
335    ErrNilPacket,
336    /// Too many PDiff.
337    #[error("too many PDiff")]
338    ErrTooManyPDiff,
339    /// A unit fragmented across packets is larger than what is reassembled.
340    #[error("reassembled unit is too large")]
341    ErrReassembledUnitTooLarge,
342    /// Too many spatial layers.
343    #[error("too many spatial layers")]
344    ErrTooManySpatialLayers,
345    /// NALU Type is unhandled.
346    #[error("NALU Type is unhandled")]
347    ErrUnhandledNaluType,
348
349    /// Corrupted H265 packet.
350    #[error("corrupted h265 packet")]
351    ErrH265CorruptedPacket,
352    /// Invalid H265 packet type.
353    #[error("invalid h265 packet type")]
354    ErrInvalidH265PacketType,
355
356    /// Payload is too small for OBU extension header.
357    #[error("payload is too small for OBU extension header")]
358    ErrPayloadTooSmallForObuExtensionHeader,
359    /// Payload is too small for OBU payload size.
360    #[error("payload is too small for OBU payload size")]
361    ErrPayloadTooSmallForObuPayloadSize,
362
363    /// Extension_payload must be in 32-bit words.
364    #[error("extension_payload must be in 32-bit words")]
365    HeaderExtensionPayloadNot32BitWords,
366    /// Audio level overflow.
367    #[error("audio level overflow")]
368    AudioLevelOverflow,
369    /// Playout delay overflow.
370    #[error("playout delay overflow")]
371    PlayoutDelayOverflow,
372    /// Payload is not large enough.
373    #[error("payload is not large enough")]
374    PayloadIsNotLargeEnough,
375    /// STAP-A declared size is larger than buffer.
376    #[error("STAP-A declared size({0}) is larger than buffer({1})")]
377    StapASizeLargerThanBuffer(usize, usize),
378    /// NALU type is currently not handled.
379    #[error("nalu type {0} is currently not handled")]
380    NaluTypeIsNotHandled(u8),
381
382    //SRTP
383    /// Duplicated packet.
384    #[error("duplicated packet")]
385    ErrDuplicated,
386    /// SRTP master key is not long enough.
387    #[error("SRTP master key is not long enough")]
388    ErrShortSrtpMasterKey,
389    /// SRTP master salt is not long enough.
390    #[error("SRTP master salt is not long enough")]
391    ErrShortSrtpMasterSalt,
392    /// No such SRTP Profile.
393    #[error("no such SRTP Profile")]
394    ErrNoSuchSrtpProfile,
395    /// IndexOverKdr > 0 is not supported yet.
396    #[error("indexOverKdr > 0 is not supported yet")]
397    ErrNonZeroKdrNotSupported,
398    /// Exporter called with wrong label.
399    #[error("exporter called with wrong label")]
400    ErrExporterWrongLabel,
401    /// No config provided.
402    #[error("no config provided")]
403    ErrNoConfig,
404    /// No conn provided.
405    #[error("no conn provided")]
406    ErrNoConn,
407    /// Failed to verify auth tag.
408    #[error("failed to verify auth tag")]
409    ErrFailedToVerifyAuthTag,
410    /// Packet is too short to be RTP packet.
411    #[error("packet is too short to be RTP packet")]
412    ErrTooShortRtp,
413    /// Packet is too short to be RTCP packet.
414    #[error("packet is too short to be RTCP packet")]
415    ErrTooShortRtcp,
416    /// Payload differs.
417    #[error("payload differs")]
418    ErrPayloadDiffers,
419    /// Started channel used incorrectly, should only be closed.
420    #[error("started channel used incorrectly, should only be closed")]
421    ErrStartedChannelUsedIncorrectly,
422    /// Stream has not been inited, unable to close.
423    #[error("stream has not been inited, unable to close")]
424    ErrStreamNotInited,
425    /// Stream is already closed.
426    #[error("stream is already closed")]
427    ErrStreamAlreadyClosed,
428    /// Stream is already inited.
429    #[error("stream is already inited")]
430    ErrStreamAlreadyInited,
431    /// Failed to cast child.
432    #[error("failed to cast child")]
433    ErrFailedTypeAssertion,
434    /// Exceeded the maximum number of packets.
435    #[error("exceeded the maximum number of packets")]
436    ErrExceededMaxPackets,
437
438    /// Index_over_kdr > 0 is not supported yet.
439    #[error("index_over_kdr > 0 is not supported yet")]
440    UnsupportedIndexOverKdr,
441    /// Invalid master key length for AES_256_cm.
442    #[error("invalid master key length for aes_256_cm")]
443    InvalidMasterKeyLength,
444    /// Invalid master salt length for AES_256_cm.
445    #[error("invalid master salt length for aes_256_cm")]
446    InvalidMasterSaltLength,
447    /// Out_len > 32 is not supported for AES_256_cm.
448    #[error("out_len > 32 is not supported for aes_256_cm")]
449    UnsupportedOutLength,
450    /// SRTP Master Key must be len , got.
451    #[error("SRTP Master Key must be len {0}, got {1}")]
452    SrtpMasterKeyLength(usize, usize),
453    /// SRTP Salt must be len , got.
454    #[error("SRTP Salt must be len {0}, got {1}")]
455    SrtpSaltLength(usize, usize),
456    /// SyntaxError.
457    #[error("SyntaxError: {0}")]
458    ExtMapParse(String),
459    /// SSRC not exist in SRTP_SSRC_state.
460    #[error("ssrc {0} not exist in srtp_ssrc_state")]
461    SsrcMissingFromSrtp(u32),
462    /// SRTP SSRC= index=: duplicated.
463    #[error("srtp ssrc={0} index={1}: duplicated")]
464    SrtpSsrcDuplicated(u32, u16),
465    /// Srtcp SSRC= index=: duplicated.
466    #[error("srtcp ssrc={0} index={1}: duplicated")]
467    SrtcpSsrcDuplicated(u32, usize),
468    /// SSRC not exist in srtcp_SSRC_state.
469    #[error("ssrc {0} not exist in srtcp_ssrc_state")]
470    SsrcMissingFromSrtcp(u32),
471    /// Stream with SSRC exists.
472    #[error("Stream with ssrc {0} exists")]
473    StreamWithSsrcExists(u32),
474    /// Session RTP/RTCP type must be same as input buffer.
475    #[error("Session RTP/RTCP type must be same as input buffer")]
476    SessionRtpRtcpTypeMismatch,
477    /// Session EOF.
478    #[error("Session EOF")]
479    SessionEof,
480    /// Too short SRTP packet: only bytes, expected > bytes.
481    #[error("too short SRTP packet: only {0} bytes, expected > {1} bytes")]
482    SrtpTooSmall(usize, usize),
483    /// Too short SRTCP packet: only bytes, expected > bytes.
484    #[error("too short SRTCP packet: only {0} bytes, expected > {1} bytes")]
485    SrtcpTooSmall(usize, usize),
486    /// Failed to verify RTP auth tag.
487    #[error("failed to verify rtp auth tag")]
488    RtpFailedToVerifyAuthTag,
489    /// Too short auth tag: only bytes, expected > bytes.
490    #[error("too short auth tag: only {0} bytes, expected > {1} bytes")]
491    RtcpInvalidLengthAuthTag(usize, usize),
492    /// Failed to verify RTCP auth tag.
493    #[error("failed to verify rtcp auth tag")]
494    RtcpFailedToVerifyAuthTag,
495    /// SessionSRTP has been closed.
496    #[error("SessionSRTP has been closed")]
497    SessionSrtpAlreadyClosed,
498    /// This stream is not a RTPStream.
499    #[error("this stream is not a RTPStream")]
500    InvalidRtpStream,
501    /// This stream is not a RTCPStream.
502    #[error("this stream is not a RTCPStream")]
503    InvalidRtcpStream,
504
505    //STUN errors
506    /// Attribute not found.
507    #[error("attribute not found")]
508    ErrAttributeNotFound,
509    /// Transaction is stopped.
510    #[error("transaction is stopped")]
511    ErrTransactionStopped,
512    /// Transaction not exists.
513    #[error("transaction not exists")]
514    ErrTransactionNotExists,
515    /// Transaction exists with same id.
516    #[error("transaction exists with same id")]
517    ErrTransactionExists,
518    /// Agent is closed.
519    #[error("agent is closed")]
520    ErrAgentClosed,
521    /// Transaction is timed out.
522    #[error("transaction is timed out")]
523    ErrTransactionTimeOut,
524    /// No default reason for ErrorCode.
525    #[error("no default reason for ErrorCode")]
526    ErrNoDefaultReason,
527    /// Unexpected EOF.
528    #[error("unexpected EOF")]
529    ErrUnexpectedEof,
530    /// Attribute size is invalid.
531    #[error("attribute size is invalid")]
532    ErrAttributeSizeInvalid,
533    /// Attribute size overflow.
534    #[error("attribute size overflow")]
535    ErrAttributeSizeOverflow,
536    /// Attempt to decode to nil message.
537    #[error("attempt to decode to nil message")]
538    ErrDecodeToNil,
539    /// Unexpected EOF: not enough bytes to read header.
540    #[error("unexpected EOF: not enough bytes to read header")]
541    ErrUnexpectedHeaderEof,
542    /// Integrity check failed.
543    #[error("integrity check failed")]
544    ErrIntegrityMismatch,
545    /// Fingerprint check failed.
546    #[error("fingerprint check failed")]
547    ErrFingerprintMismatch,
548    /// FINGERPRINT before MESSAGE-INTEGRITY attribute.
549    #[error("FINGERPRINT before MESSAGE-INTEGRITY attribute")]
550    ErrFingerprintBeforeIntegrity,
551    /// Bad UNKNOWN-ATTRIBUTES size.
552    #[error("bad UNKNOWN-ATTRIBUTES size")]
553    ErrBadUnknownAttrsSize,
554    /// Invalid length of IP value.
555    #[error("invalid length of IP value")]
556    ErrBadIpLength,
557    /// No connection provided.
558    #[error("no connection provided")]
559    ErrNoConnection,
560    /// Client is closed.
561    #[error("client is closed")]
562    ErrClientClosed,
563    /// No agent is set.
564    #[error("no agent is set")]
565    ErrNoAgent,
566    /// Collector is closed.
567    #[error("collector is closed")]
568    ErrCollectorClosed,
569    /// Unsupported network.
570    #[error("unsupported network")]
571    ErrUnsupportedNetwork,
572    /// Invalid URL.
573    #[error("invalid url")]
574    ErrInvalidUrl,
575    /// Unknown scheme type.
576    #[error("unknown scheme type")]
577    ErrSchemeType,
578    /// Invalid hostname.
579    #[error("invalid hostname")]
580    ErrHost,
581
582    // TURN errors
583    /// TURN: RelayAddress must be valid IP to use RelayAddressGeneratorStatic.
584    #[error("turn: RelayAddress must be valid IP to use RelayAddressGeneratorStatic")]
585    ErrRelayAddressInvalid,
586    /// TURN: PacketConnConfigs and ConnConfigs are empty, unable to proceed.
587    #[error("turn: PacketConnConfigs and ConnConfigs are empty, unable to proceed")]
588    ErrNoAvailableConns,
589    /// TURN: PacketConnConfig must have a non-nil Conn.
590    #[error("turn: PacketConnConfig must have a non-nil Conn")]
591    ErrConnUnset,
592    /// TURN: ListenerConfig must have a non-nil Listener.
593    #[error("turn: ListenerConfig must have a non-nil Listener")]
594    ErrListenerUnset,
595    /// TURN: RelayAddressGenerator has invalid ListeningAddress.
596    #[error("turn: RelayAddressGenerator has invalid ListeningAddress")]
597    ErrListeningAddressInvalid,
598    /// TURN: RelayAddressGenerator in RelayConfig is unset.
599    #[error("turn: RelayAddressGenerator in RelayConfig is unset")]
600    ErrRelayAddressGeneratorUnset,
601    /// TURN: max retries exceeded.
602    #[error("turn: max retries exceeded")]
603    ErrMaxRetriesExceeded,
604    /// TURN: MaxPort must be not 0.
605    #[error("turn: MaxPort must be not 0")]
606    ErrMaxPortNotZero,
607    /// TURN: MaxPort must be not 0.
608    #[error("turn: MaxPort must be not 0")]
609    ErrMinPortNotZero,
610    /// TURN: MaxPort less than MinPort.
611    #[error("turn: MaxPort less than MinPort")]
612    ErrMaxPortLessThanMinPort,
613    /// TURN: relay_conn cannot not be nil.
614    #[error("turn: relay_conn cannot not be nil")]
615    ErrNilConn,
616    /// TURN: TODO.
617    #[error("turn: TODO")]
618    ErrTodo,
619    /// TURN: already listening.
620    #[error("turn: already listening")]
621    ErrAlreadyListening,
622    /// TURN: Server failed to close.
623    #[error("turn: Server failed to close")]
624    ErrFailedToClose,
625    /// TURN: failed to retransmit transaction.
626    #[error("turn: failed to retransmit transaction")]
627    ErrFailedToRetransmitTransaction,
628    /// All retransmissions failed.
629    #[error("all retransmissions failed")]
630    ErrAllRetransmissionsFailed,
631    /// No binding found for channel.
632    #[error("no binding found for channel")]
633    ErrChannelBindNotFound,
634    /// STUN server address is not set for the client.
635    #[error("STUN server address is not set for the client")]
636    ErrStunserverAddressNotSet,
637    /// Only one Allocate caller is allowed.
638    #[error("only one Allocate() caller is allowed")]
639    ErrOneAllocateOnly,
640    /// Already allocated.
641    #[error("already allocated")]
642    ErrAlreadyAllocated,
643    /// Non-STUN message from STUN server.
644    #[error("non-STUN message from STUN server")]
645    ErrNonStunmessage,
646    /// Failed to decode STUN message.
647    #[error("failed to decode STUN message")]
648    ErrFailedToDecodeStun,
649    /// Unexpected STUN request message.
650    #[error("unexpected STUN request message")]
651    ErrUnexpectedStunrequestMessage,
652    /// Channel number not in [0x4000, 0x7FFF].
653    #[error("channel number not in [0x4000, 0x7FFF]")]
654    ErrInvalidChannelNumber,
655    /// ChannelData length != len(Data).
656    #[error("channelData length != len(Data)")]
657    ErrBadChannelDataLength,
658    /// Invalid value for requested family attribute.
659    #[error("invalid value for requested family attribute")]
660    ErrInvalidRequestedFamilyValue,
661    /// Fake error.
662    #[error("fake error")]
663    ErrFakeErr,
664    /// Use of closed network connection.
665    #[error("use of closed network connection")]
666    ErrClosed,
667    /// Addr is not a net.UDPAddr.
668    #[error("addr is not a net.UDPAddr")]
669    ErrUdpaddrCast,
670    /// Try-lock is already locked.
671    #[error("try-lock is already locked")]
672    ErrDoubleLock,
673    /// Transaction closed.
674    #[error("transaction closed")]
675    ErrTransactionClosed,
676    /// Wait_for_result called on non-result transaction.
677    #[error("wait_for_result called on non-result transaction")]
678    ErrWaitForResultOnNonResultTransaction,
679    /// Failed to build refresh request.
680    #[error("failed to build refresh request")]
681    ErrFailedToBuildRefreshRequest,
682    /// Failed to refresh allocation.
683    #[error("failed to refresh allocation")]
684    ErrFailedToRefreshAllocation,
685    /// Failed to get lifetime from refresh response.
686    #[error("failed to get lifetime from refresh response")]
687    ErrFailedToGetLifetime,
688    /// Too short buffer.
689    #[error("too short buffer")]
690    ErrShortBuffer,
691    /// Unexpected response type.
692    #[error("unexpected response type")]
693    ErrUnexpectedResponse,
694    /// AllocatePacketConn must be set.
695    #[error("AllocatePacketConn must be set")]
696    ErrAllocatePacketConnMustBeSet,
697    /// AllocateConn must be set.
698    #[error("AllocateConn must be set")]
699    ErrAllocateConnMustBeSet,
700    /// LeveledLogger must be set.
701    #[error("LeveledLogger must be set")]
702    ErrLeveledLoggerMustBeSet,
703    /// You cannot use the same channel number with different peer.
704    #[error("you cannot use the same channel number with different peer")]
705    ErrSameChannelDifferentPeer,
706    /// Allocations must not be created with nil FivTuple.
707    #[error("allocations must not be created with nil FivTuple")]
708    ErrNilFiveTuple,
709    /// Allocations must not be created with nil FiveTuple.src_addr.
710    #[error("allocations must not be created with nil FiveTuple.src_addr")]
711    ErrNilFiveTupleSrcAddr,
712    /// Allocations must not be created with nil FiveTuple.dst_addr.
713    #[error("allocations must not be created with nil FiveTuple.dst_addr")]
714    ErrNilFiveTupleDstAddr,
715    /// Allocations must not be created with nil turnSocket.
716    #[error("allocations must not be created with nil turnSocket")]
717    ErrNilTurnSocket,
718    /// Allocations must not be created with a lifetime of 0.
719    #[error("allocations must not be created with a lifetime of 0")]
720    ErrLifetimeZero,
721    /// Allocation attempt created with duplicate FiveTuple.
722    #[error("allocation attempt created with duplicate FiveTuple")]
723    ErrDupeFiveTuple,
724    /// Failed to cast net.Addr to *net.UDPAddr.
725    #[error("failed to cast net.Addr to *net.UDPAddr")]
726    ErrFailedToCastUdpaddr,
727    /// Failed to generate nonce.
728    #[error("failed to generate nonce")]
729    ErrFailedToGenerateNonce,
730    /// Failed to send error message.
731    #[error("failed to send error message")]
732    ErrFailedToSendError,
733    /// Duplicated Nonce generated, discarding request.
734    #[error("duplicated Nonce generated, discarding request")]
735    ErrDuplicatedNonce,
736    /// No such user exists.
737    #[error("no such user exists")]
738    ErrNoSuchUser,
739    /// Unexpected class.
740    #[error("unexpected class")]
741    ErrUnexpectedClass,
742    /// Unexpected method.
743    #[error("unexpected method")]
744    ErrUnexpectedMethod,
745    /// Failed to handle.
746    #[error("failed to handle")]
747    ErrFailedToHandle,
748    /// Unhandled STUN packet.
749    #[error("unhandled STUN packet")]
750    ErrUnhandledStunpacket,
751    /// Unable to handle ChannelData.
752    #[error("unable to handle ChannelData")]
753    ErrUnableToHandleChannelData,
754    /// Failed to create STUN message from packet.
755    #[error("failed to create stun message from packet")]
756    ErrFailedToCreateStunpacket,
757    /// Failed to create channel data from packet.
758    #[error("failed to create channel data from packet")]
759    ErrFailedToCreateChannelData,
760    /// Relay already allocated for 5-TUPLE.
761    #[error("relay already allocated for 5-TUPLE")]
762    ErrRelayAlreadyAllocatedForFiveTuple,
763    /// RequestedTransport must be UDP.
764    #[error("RequestedTransport must be UDP")]
765    ErrRequestedTransportMustBeUdp,
766    /// No support for DONT-FRAGMENT.
767    #[error("no support for DONT-FRAGMENT")]
768    ErrNoDontFragmentSupport,
769    /// Request must not contain RESERVATION-TOKEN and EVEN-PORT.
770    #[error("Request must not contain RESERVATION-TOKEN and EVEN-PORT")]
771    ErrRequestWithReservationTokenAndEvenPort,
772    /// No allocation found.
773    #[error("no allocation found")]
774    ErrNoAllocationFound,
775    /// Unable to handle send-indication, no permission added.
776    #[error("unable to handle send-indication, no permission added")]
777    ErrNoPermission,
778    /// Packet write smaller than packet.
779    #[error("packet write smaller than packet")]
780    ErrShortWrite,
781    /// No such channel bind.
782    #[error("no such channel bind")]
783    ErrNoSuchChannelBind,
784    /// Failed writing to socket.
785    #[error("failed writing to socket")]
786    ErrFailedWriteSocket,
787
788    // ICE errors
789    /// Indicates an error with Unknown info.
790    #[error("Unknown type")]
791    ErrUnknownType,
792
793    /// Indicates query arguments are provided in a STUN URL.
794    #[error("queries not supported in stun address")]
795    ErrStunQuery,
796
797    /// Indicates an malformed query is provided.
798    #[error("invalid query")]
799    ErrInvalidQuery,
800
801    /// Indicates malformed port is provided.
802    #[error("url parse: invalid port number")]
803    ErrPort,
804
805    /// Indicates local username fragment insufficient bits are provided.
806    /// Have to be at least 24 bits long.
807    #[error("local username fragment is less than 24 bits long")]
808    ErrLocalUfragInsufficientBits,
809
810    /// Indicates local passoword insufficient bits are provided.
811    /// Have to be at least 128 bits long.
812    #[error("local password is less than 128 bits long")]
813    ErrLocalPwdInsufficientBits,
814
815    /// Indicates an unsupported transport type was provided.
816    #[error("invalid transport protocol type")]
817    ErrProtoType,
818
819    /// Indicates agent does not have a valid candidate pair.
820    #[error("no candidate pairs available")]
821    ErrNoCandidatePairs,
822
823    /// Indicates agent connection was canceled by the caller.
824    #[error("connecting canceled by caller")]
825    ErrCanceledByCaller,
826
827    /// Indicates agent was started twice.
828    #[error("attempted to start agent twice")]
829    ErrMultipleStart,
830
831    /// Indicates agent was started with an empty remote ufrag.
832    #[error("remote ufrag is empty")]
833    ErrRemoteUfragEmpty,
834
835    /// Indicates agent was started with an empty remote pwd.
836    #[error("remote pwd is empty")]
837    ErrRemotePwdEmpty,
838
839    /// Indicates agent was started without on_candidate.
840    #[error("no on_candidate provided")]
841    ErrNoOnCandidateHandler,
842
843    /// Indicates GatherCandidates has been called multiple times.
844    #[error("attempting to gather candidates during gathering state")]
845    ErrMultipleGatherAttempted,
846
847    /// Indicates agent was give TURN URL with an empty Username.
848    #[error("username is empty")]
849    ErrUsernameEmpty,
850
851    /// Indicates agent was give TURN URL with an empty Password.
852    #[error("password is empty")]
853    ErrPasswordEmpty,
854
855    /// Indicates we were unable to parse a candidate address.
856    #[error("failed to parse address")]
857    ErrAddressParseFailed,
858
859    /// Indicates that non host candidates were selected for a lite agent.
860    #[error("lite agents must only use host candidates")]
861    ErrLiteUsingNonHostCandidates,
862
863    /// Indicates that current ice agent supports Lite only
864    #[error("lite support only")]
865    ErrLiteSupportOnly,
866
867    /// Indicates that one or more URL was provided to the agent but no host candidate required them.
868    #[error("agent does not need URL with selected candidate types")]
869    ErrUselessUrlsProvided,
870
871    /// Indicates that the specified NAT1To1IPCandidateType is unsupported.
872    #[error("unsupported 1:1 NAT IP candidate type")]
873    ErrUnsupportedNat1to1IpCandidateType,
874
875    /// Indicates that the given 1:1 NAT IP mapping is invalid.
876    #[error("invalid 1:1 NAT IP mapping")]
877    ErrInvalidNat1to1IpMapping,
878
879    /// IPNotFound in NAT1To1IPMapping.
880    #[error("external mapped IP not found")]
881    ErrExternalMappedIpNotFound,
882
883    /// Indicates that the mDNS gathering cannot be used along with 1:1 NAT IP mapping for host
884    /// candidate.
885    #[error("mDNS gathering cannot be used with 1:1 NAT IP mapping for host candidate")]
886    ErrMulticastDnsWithNat1to1IpMapping,
887
888    /// Indicates that 1:1 NAT IP mapping for host candidate is requested, but the host candidate
889    /// type is disabled.
890    #[error("1:1 NAT IP mapping for host candidate ineffective")]
891    ErrIneffectiveNat1to1IpMappingHost,
892
893    /// Indicates that 1:1 NAT IP mapping for srflx candidate is requested, but the srflx candidate
894    /// type is disabled.
895    #[error("1:1 NAT IP mapping for srflx candidate ineffective")]
896    ErrIneffectiveNat1to1IpMappingSrflx,
897
898    /// Indicates an invalid MulticastDNSHostName.
899    #[error("invalid mDNS HostName, must end with .local and can only contain a single '.'")]
900    ErrInvalidMulticastDnshostName,
901
902    /// Indicates mdns is not supported.
903    #[error("mdns is not supported")]
904    ErrMulticastDnsNotSupported,
905
906    /// Indicates Restart was called when Agent is in GatheringStateGathering.
907    #[error("ICE Agent can not be restarted when gathering")]
908    ErrRestartWhenGathering,
909
910    /// Indicates a run operation was canceled by its individual done.
911    #[error("run was canceled by done")]
912    ErrRunCanceled,
913
914    /// Initialized Indicates TCPMux is not initialized and that invalidTCPMux is used.
915    #[error("TCPMux is not initialized")]
916    ErrTcpMuxNotInitialized,
917
918    /// Indicates we already have the connection with same remote addr.
919    #[error("conn with same remote addr already exists")]
920    ErrTcpRemoteAddrAlreadyExists,
921
922    /// Failed to send packet.
923    #[error("failed to send packet")]
924    ErrSendPacket,
925    /// Attribute not long enough to be ICE candidate.
926    #[error("attribute not long enough to be ICE candidate")]
927    ErrAttributeTooShortIceCandidate,
928    /// Could not parse component.
929    #[error("could not parse component")]
930    ErrParseComponent,
931    /// Could not parse priority.
932    #[error("could not parse priority")]
933    ErrParsePriority,
934    /// Could not parse port.
935    #[error("could not parse port")]
936    ErrParsePort,
937    /// Could not parse related addresses.
938    #[error("could not parse related addresses")]
939    ErrParseRelatedAddr,
940    /// Could not parse type.
941    #[error("could not parse type")]
942    ErrParseType,
943    /// Unknown candidate type.
944    #[error("unknown candidate type")]
945    ErrUnknownCandidateType,
946    /// Failed to get XOR-MAPPED-ADDRESS response.
947    #[error("failed to get XOR-MAPPED-ADDRESS response")]
948    ErrGetXorMappedAddrResponse,
949    /// Connection with same remote address already exists.
950    #[error("connection with same remote address already exists")]
951    ErrConnectionAddrAlreadyExist,
952    /// Error reading streaming packet.
953    #[error("error reading streaming packet")]
954    ErrReadingStreamingPacket,
955    /// Error writing to.
956    #[error("error writing to")]
957    ErrWriting,
958    /// Error closing connection.
959    #[error("error closing connection")]
960    ErrClosingConnection,
961    /// Unable to determine networkType.
962    #[error("unable to determine networkType")]
963    ErrDetermineNetworkType,
964    /// Missing protocol scheme.
965    #[error("missing protocol scheme")]
966    ErrMissingProtocolScheme,
967    /// Too many colons in address.
968    #[error("too many colons in address")]
969    ErrTooManyColonsAddr,
970    /// Unexpected error trying to read.
971    #[error("unexpected error trying to read")]
972    ErrRead,
973    /// Unknown role.
974    #[error("unknown role")]
975    ErrUnknownRole,
976    /// Username mismatch.
977    #[error("username mismatch")]
978    ErrMismatchUsername,
979    /// The ICE conn can't write STUN messages.
980    #[error("the ICE conn can't write STUN messages")]
981    ErrIceWriteStunMessage,
982    /// URL parse: relative URL without a base.
983    #[error("url parse: relative URL without a base")]
984    ErrUrlParse,
985    /// Candidate IP could not be found.
986    #[error("Candidate IP could not be found")]
987    ErrCandidateIpNotFound,
988
989    // DTLS errors
990    /// Conn is closed.
991    #[error("conn is closed")]
992    ErrConnClosed,
993    /// Read/write timeout.
994    #[error("read/write timeout")]
995    ErrDeadlineExceeded,
996    /// Context is not supported for export_keying_material.
997    #[error("context is not supported for export_keying_material")]
998    ErrContextUnsupported,
999    /// Packet is too short.
1000    #[error("packet is too short")]
1001    ErrDtlspacketInvalidLength,
1002    /// Handshake is in progress.
1003    #[error("handshake is in progress")]
1004    ErrHandshakeInProgress,
1005    /// Invalid content type.
1006    #[error("invalid content type")]
1007    ErrInvalidContentType,
1008    /// Invalid mac.
1009    #[error("invalid mac")]
1010    ErrInvalidMac,
1011    /// Packet length and declared length do not match.
1012    #[error("packet length and declared length do not match")]
1013    ErrInvalidPacketLength,
1014    /// Export_keying_material can not be used with a reserved label.
1015    #[error("export_keying_material can not be used with a reserved label")]
1016    ErrReservedExportKeyingMaterial,
1017    /// Client sent certificate verify but we have no certificate to verify.
1018    #[error("client sent certificate verify but we have no certificate to verify")]
1019    ErrCertificateVerifyNoCertificate,
1020    /// Client+server do not support any shared cipher suites.
1021    #[error("client+server do not support any shared cipher suites")]
1022    ErrCipherSuiteNoIntersection,
1023    /// Server hello can not be created without a cipher suite.
1024    #[error("server hello can not be created without a cipher suite")]
1025    ErrCipherSuiteUnset,
1026    /// Client sent certificate but did not verify it.
1027    #[error("client sent certificate but did not verify it")]
1028    ErrClientCertificateNotVerified,
1029    /// Server required client verification, but got none.
1030    #[error("server required client verification, but got none")]
1031    ErrClientCertificateRequired,
1032    /// Server responded with SRTP Profile we do not support.
1033    #[error("server responded with SRTP Profile we do not support")]
1034    ErrClientNoMatchingSrtpProfile,
1035    /// Client required Extended Master Secret extension, but server does not support it.
1036    #[error("client required Extended Master Secret extension, but server does not support it")]
1037    ErrClientRequiredButNoServerEms,
1038    /// Server hello can not be created without a compression method.
1039    #[error("server hello can not be created without a compression method")]
1040    ErrCompressionMethodUnset,
1041    /// Client+server cookie does not match.
1042    #[error("client+server cookie does not match")]
1043    ErrCookieMismatch,
1044    /// Cookie must not be longer then 255 bytes.
1045    #[error("cookie must not be longer then 255 bytes")]
1046    ErrCookieTooLong,
1047    /// PSK Identity Hint provided but PSK is nil.
1048    #[error("PSK Identity Hint provided but PSK is nil")]
1049    ErrIdentityNoPsk,
1050    /// No certificate provided.
1051    #[error("no certificate provided")]
1052    ErrInvalidCertificate,
1053    /// Cipher spec invalid.
1054    #[error("cipher spec invalid")]
1055    ErrInvalidCipherSpec,
1056    /// Invalid or unknown cipher suite.
1057    #[error("invalid or unknown cipher suite")]
1058    ErrInvalidCipherSuite,
1059    /// Unable to determine if ClientKeyExchange is a public key or PSK Identity.
1060    #[error("unable to determine if ClientKeyExchange is a public key or PSK Identity")]
1061    ErrInvalidClientKeyExchange,
1062    /// Invalid or unknown compression method.
1063    #[error("invalid or unknown compression method")]
1064    ErrInvalidCompressionMethod,
1065    /// ECDSA signature contained zero or negative values.
1066    #[error("ECDSA signature contained zero or negative values")]
1067    ErrInvalidEcdsasignature,
1068    /// Invalid or unknown elliptic curve type.
1069    #[error("invalid or unknown elliptic curve type")]
1070    ErrInvalidEllipticCurveType,
1071    /// Invalid extension type.
1072    #[error("invalid extension type")]
1073    ErrInvalidExtensionType,
1074    /// Invalid hash algorithm.
1075    #[error("invalid hash algorithm")]
1076    ErrInvalidHashAlgorithm,
1077    /// Invalid named curve.
1078    #[error("invalid named curve")]
1079    ErrInvalidNamedCurve,
1080    /// Invalid private key type.
1081    #[error("invalid private key type")]
1082    ErrInvalidPrivateKey,
1083    /// Named curve and private key type does not match.
1084    #[error("named curve and private key type does not match")]
1085    ErrNamedCurveAndPrivateKeyMismatch,
1086    /// Invalid server name format.
1087    #[error("invalid server name format")]
1088    ErrInvalidSniFormat,
1089    /// Invalid signature algorithm.
1090    #[error("invalid signature algorithm")]
1091    ErrInvalidSignatureAlgorithm,
1092    /// Expected and actual key signature do not match.
1093    #[error("expected and actual key signature do not match")]
1094    ErrKeySignatureMismatch,
1095    /// Conn can not be created with a nil nextConn.
1096    #[error("Conn can not be created with a nil nextConn")]
1097    ErrNilNextConn,
1098    /// Connection can not be created, no CipherSuites satisfy this Config.
1099    #[error("connection can not be created, no CipherSuites satisfy this Config")]
1100    ErrNoAvailableCipherSuites,
1101    /// Connection can not be created, no SignatureScheme satisfy this Config.
1102    #[error("connection can not be created, no SignatureScheme satisfy this Config")]
1103    ErrNoAvailableSignatureSchemes,
1104    /// No certificates configured.
1105    #[error("no certificates configured")]
1106    ErrNoCertificates,
1107    /// No config provided.
1108    #[error("no config provided")]
1109    ErrNoConfigProvided,
1110    /// Client requested zero or more elliptic curves that are not supported by the server.
1111    #[error("client requested zero or more elliptic curves that are not supported by the server")]
1112    ErrNoSupportedEllipticCurves,
1113    /// Unsupported protocol version.
1114    #[error("unsupported protocol version")]
1115    ErrUnsupportedProtocolVersion,
1116    /// Certificate and PSK provided.
1117    #[error("Certificate and PSK provided")]
1118    ErrPskAndCertificate,
1119    /// PSK and PSK Identity Hint must both be set for client.
1120    #[error("PSK and PSK Identity Hint must both be set for client")]
1121    ErrPskAndIdentityMustBeSetForClient,
1122    /// SRTP support was requested but server did not respond with use_SRTP extension.
1123    #[error("SRTP support was requested but server did not respond with use_srtp extension")]
1124    ErrRequestedButNoSrtpExtension,
1125    /// Certificate is mandatory for server.
1126    #[error("Certificate is mandatory for server")]
1127    ErrServerMustHaveCertificate,
1128    /// Client requested SRTP but we have no matching profiles.
1129    #[error("client requested SRTP but we have no matching profiles")]
1130    ErrServerNoMatchingSrtpProfile,
1131    /// Server requires the Extended Master Secret extension, but the client does not support it.
1132    #[error(
1133        "server requires the Extended Master Secret extension, but the client does not support it"
1134    )]
1135    ErrServerRequiredButNoClientEms,
1136    /// Expected and actual verify data does not match.
1137    #[error("expected and actual verify data does not match")]
1138    ErrVerifyDataMismatch,
1139    /// Handshake message unset, unable to marshal.
1140    #[error("handshake message unset, unable to marshal")]
1141    ErrHandshakeMessageUnset,
1142    /// Invalid flight number.
1143    #[error("invalid flight number")]
1144    ErrInvalidFlight,
1145    /// Unable to generate key signature, unimplemented.
1146    #[error("unable to generate key signature, unimplemented")]
1147    ErrKeySignatureGenerateUnimplemented,
1148    /// Unable to verify key signature, unimplemented.
1149    #[error("unable to verify key signature, unimplemented")]
1150    ErrKeySignatureVerifyUnimplemented,
1151    /// Data length and declared length do not match.
1152    #[error("data length and declared length do not match")]
1153    ErrLengthMismatch,
1154    /// Buffer not long enough to contain nonce.
1155    #[error("buffer not long enough to contain nonce")]
1156    ErrNotEnoughRoomForNonce,
1157    /// Feature has not been implemented yet.
1158    #[error("feature has not been implemented yet")]
1159    ErrNotImplemented,
1160    /// Sequence number overflow.
1161    #[error("sequence number overflow")]
1162    ErrSequenceNumberOverflow,
1163    /// Unable to marshal fragmented handshakes.
1164    #[error("unable to marshal fragmented handshakes")]
1165    ErrUnableToMarshalFragmented,
1166    /// Invalid state machine transition.
1167    #[error("invalid state machine transition")]
1168    ErrInvalidFsmTransition,
1169    /// ApplicationData with epoch of 0.
1170    #[error("ApplicationData with epoch of 0")]
1171    ErrApplicationDataEpochZero,
1172    /// Unhandled contentType.
1173    #[error("unhandled contentType")]
1174    ErrUnhandledContextType,
1175    /// Context canceled.
1176    #[error("context canceled")]
1177    ErrContextCanceled,
1178    /// Empty fragment.
1179    #[error("empty fragment")]
1180    ErrEmptyFragment,
1181    /// Alert is Fatal or Close Notify.
1182    #[error("Alert is Fatal or Close Notify")]
1183    ErrAlertFatalOrClose,
1184    /// Fragment buffer overflow. New size is greater than specified max.
1185    #[error(
1186        "Fragment buffer overflow. New size {new_size} is greater than specified max {max_size}"
1187    )]
1188    ErrFragmentBufferOverflow {
1189        /// The size the buffer would have grown to.
1190        new_size: usize,
1191        /// The configured maximum.
1192        max_size: usize,
1193    },
1194    /// Client transport is not set yet.
1195    #[error("Client transport is not set yet")]
1196    ErrClientTransportNotSet,
1197
1198    /// The endpoint can no longer create new connections
1199    ///
1200    /// Indicates that a necessary component of the endpoint has been dropped or otherwise disabled.
1201    #[error("endpoint stopping")]
1202    EndpointStopping,
1203    /// The number of active connections on the local endpoint is at the limit
1204    ///
1205    /// Try using longer connection IDs.
1206    #[error("too many connections")]
1207    TooManyConnections,
1208    /// The domain name supplied was malformed
1209    #[error("invalid DNS name: {0}")]
1210    InvalidDnsName(String),
1211    /// The remote [`SocketAddr`] supplied was malformed
1212    ///
1213    /// Examples include attempting to connect to port 0, or using an inappropriate address family.
1214    #[error("invalid remote address: {0}")]
1215    InvalidRemoteAddress(SocketAddr),
1216    /// No client configuration was set up
1217    #[error("no client config")]
1218    NoClientConfig,
1219    /// No server configuration was set up
1220    #[error("no server config")]
1221    NoServerConfig,
1222
1223    //SCTP errors
1224    /// Raw is too small for a SCTP chunk.
1225    #[error("raw is too small for a SCTP chunk")]
1226    ErrChunkHeaderTooSmall,
1227    /// Not enough data left in SCTP packet to satisfy requested length.
1228    #[error("not enough data left in SCTP packet to satisfy requested length")]
1229    ErrChunkHeaderNotEnoughSpace,
1230    /// Chunk PADDING is non-zero at offset.
1231    #[error("chunk PADDING is non-zero at offset")]
1232    ErrChunkHeaderPaddingNonZero,
1233    /// Chunk has invalid length.
1234    #[error("chunk has invalid length")]
1235    ErrChunkHeaderInvalidLength,
1236
1237    /// ChunkType is not of type ABORT.
1238    #[error("ChunkType is not of type ABORT")]
1239    ErrChunkTypeNotAbort,
1240    /// Failed build Abort Chunk.
1241    #[error("failed build Abort Chunk")]
1242    ErrBuildAbortChunkFailed,
1243    /// ChunkType is not of type COOKIEACK.
1244    #[error("ChunkType is not of type COOKIEACK")]
1245    ErrChunkTypeNotCookieAck,
1246    /// ChunkType is not of type COOKIEECHO.
1247    #[error("ChunkType is not of type COOKIEECHO")]
1248    ErrChunkTypeNotCookieEcho,
1249    /// ChunkType is not of type ctError.
1250    #[error("ChunkType is not of type ctError")]
1251    ErrChunkTypeNotCt,
1252    /// Failed build Error Chunk.
1253    #[error("failed build Error Chunk")]
1254    ErrBuildErrorChunkFailed,
1255    /// Failed to marshal stream.
1256    #[error("failed to marshal stream")]
1257    ErrMarshalStreamFailed,
1258    /// Chunk too short.
1259    #[error("chunk too short")]
1260    ErrChunkTooShort,
1261    /// ChunkType is not of type ForwardTsn.
1262    #[error("ChunkType is not of type ForwardTsn")]
1263    ErrChunkTypeNotForwardTsn,
1264    /// ChunkType is not of type HEARTBEAT.
1265    #[error("ChunkType is not of type HEARTBEAT")]
1266    ErrChunkTypeNotHeartbeat,
1267    /// ChunkType is not of type HEARTBEATACK.
1268    #[error("ChunkType is not of type HEARTBEATACK")]
1269    ErrChunkTypeNotHeartbeatAck,
1270    /// Heartbeat is not long enough to contain Heartbeat Info.
1271    #[error("heartbeat is not long enough to contain Heartbeat Info")]
1272    ErrHeartbeatNotLongEnoughInfo,
1273    /// Failed to parse param type.
1274    #[error("failed to parse param type")]
1275    ErrParseParamTypeFailed,
1276    /// Heartbeat should only have HEARTBEAT param.
1277    #[error("heartbeat should only have HEARTBEAT param")]
1278    ErrHeartbeatParam,
1279    /// Failed unmarshalling param in Heartbeat Chunk.
1280    #[error("failed unmarshalling param in Heartbeat Chunk")]
1281    ErrHeartbeatChunkUnmarshal,
1282    /// Unimplemented.
1283    #[error("unimplemented")]
1284    ErrUnimplemented,
1285    /// Heartbeat Ack must have one param.
1286    #[error("heartbeat Ack must have one param")]
1287    ErrHeartbeatAckParams,
1288    /// Heartbeat Ack must have one param, and it should be a HeartbeatInfo.
1289    #[error("heartbeat Ack must have one param, and it should be a HeartbeatInfo")]
1290    ErrHeartbeatAckNotHeartbeatInfo,
1291    /// Unable to marshal parameter for Heartbeat Ack.
1292    #[error("unable to marshal parameter for Heartbeat Ack")]
1293    ErrHeartbeatAckMarshalParam,
1294
1295    /// Raw is too small for error cause.
1296    #[error("raw is too small for error cause")]
1297    ErrErrorCauseTooSmall,
1298
1299    /// Unhandled ParamType.
1300    #[error("unhandled ParamType: {typ}")]
1301    ErrParamTypeUnhandled {
1302        /// The raw parameter type that was not recognised.
1303        typ: u16,
1304    },
1305
1306    /// Unexpected ParamType.
1307    #[error("unexpected ParamType")]
1308    ErrParamTypeUnexpected,
1309
1310    /// Param header too short.
1311    #[error("param header too short")]
1312    ErrParamHeaderTooShort,
1313    /// Param self reported length is shorter than header length.
1314    #[error("param self reported length is shorter than header length")]
1315    ErrParamHeaderSelfReportedLengthShorter,
1316    /// Param self reported length is longer than header length.
1317    #[error("param self reported length is longer than header length")]
1318    ErrParamHeaderSelfReportedLengthLonger,
1319    /// Failed to parse param type.
1320    #[error("failed to parse param type")]
1321    ErrParamHeaderParseFailed,
1322
1323    /// Packet to short.
1324    #[error("packet to short")]
1325    ErrParamPacketTooShort,
1326    /// Outgoing SSN reset request parameter too short.
1327    #[error("outgoing SSN reset request parameter too short")]
1328    ErrSsnResetRequestParamTooShort,
1329    /// Failed unmarshalling SSN reset request parameter in RE-CONFIG chunk.
1330    #[error("failed unmarshalling SSN reset request parameter in RE-CONFIG chunk")]
1331    ErrUnmarshalSsnResetRequestParam,
1332    /// Reconfig response parameter too short.
1333    #[error("reconfig response parameter too short")]
1334    ErrReconfigRespParamTooShort,
1335    /// Failed unmarshalling re-configuration response parameter in RE-CONFIG chunk.
1336    #[error("failed unmarshalling re-configuration response parameter in RE-CONFIG chunk")]
1337    ErrUnmarshalReconfigRespParam,
1338    /// Invalid algorithm type.
1339    #[error("invalid algorithm type")]
1340    ErrInvalidAlgorithmType,
1341
1342    /// Failed to parse param type.
1343    #[error("failed to parse param type")]
1344    ErrInitChunkParseParamTypeFailed,
1345    /// Failed unmarshalling param in Init Chunk.
1346    #[error("failed unmarshalling param in Init Chunk")]
1347    ErrInitChunkUnmarshalParam,
1348    /// Unable to marshal parameter for INIT/INITACK.
1349    #[error("unable to marshal parameter for INIT/INITACK")]
1350    ErrInitAckMarshalParam,
1351
1352    /// ChunkType is not of type INIT.
1353    #[error("ChunkType is not of type INIT")]
1354    ErrChunkTypeNotTypeInit,
1355    /// Chunk Value isn't long enough for mandatory parameters exp.
1356    #[error("chunk Value isn't long enough for mandatory parameters exp")]
1357    ErrChunkValueNotLongEnough,
1358    /// ChunkType of type INIT flags must be all 0.
1359    #[error("ChunkType of type INIT flags must be all 0")]
1360    ErrChunkTypeInitFlagZero,
1361    /// Failed to unmarshal INIT body.
1362    #[error("failed to unmarshal INIT body")]
1363    ErrChunkTypeInitUnmarshalFailed,
1364    /// Failed marshaling INIT common data.
1365    #[error("failed marshaling INIT common data")]
1366    ErrChunkTypeInitMarshalFailed,
1367    /// ChunkType of type INIT ACK InitiateTag must not be 0.
1368    #[error("ChunkType of type INIT ACK InitiateTag must not be 0")]
1369    ErrChunkTypeInitInitiateTagZero,
1370    /// INIT ACK inbound stream request must be > 0.
1371    #[error("INIT ACK inbound stream request must be > 0")]
1372    ErrInitInboundStreamRequestZero,
1373    /// INIT ACK outbound stream request must be > 0.
1374    #[error("INIT ACK outbound stream request must be > 0")]
1375    ErrInitOutboundStreamRequestZero,
1376    /// INIT ACK Advertised Receiver Window Credit (a_rwnd) must be >= 1500.
1377    #[error("INIT ACK Advertised Receiver Window Credit (a_rwnd) must be >= 1500")]
1378    ErrInitAdvertisedReceiver1500,
1379
1380    /// Packet is smaller than the header size.
1381    #[error("packet is smaller than the header size")]
1382    ErrChunkPayloadSmall,
1383    /// ChunkType is not of type PayloadData.
1384    #[error("ChunkType is not of type PayloadData")]
1385    ErrChunkTypeNotPayloadData,
1386    /// Failed unmarshalling payload data chunk.
1387    #[error("failed unmarshalling payload data chunk")]
1388    ErrChunkUnmarshalPayloadData,
1389    /// ChunkType is not of type Reconfig.
1390    #[error("ChunkType is not of type Reconfig")]
1391    ErrChunkTypeNotReconfig,
1392    /// ChunkReconfig has invalid ParamA.
1393    #[error("ChunkReconfig has invalid ParamA")]
1394    ErrChunkReconfigInvalidParamA,
1395
1396    /// Failed to parse param type.
1397    #[error("failed to parse param type")]
1398    ErrChunkParseParamTypeFailed,
1399    /// Unable to marshal parameter A for reconfig.
1400    #[error("unable to marshal parameter A for reconfig")]
1401    ErrChunkMarshalParamAReconfigFailed,
1402    /// Unable to marshal parameter B for reconfig.
1403    #[error("unable to marshal parameter B for reconfig")]
1404    ErrChunkMarshalParamBReconfigFailed,
1405
1406    /// ChunkType is not of type SACK.
1407    #[error("ChunkType is not of type SACK")]
1408    ErrChunkTypeNotSack,
1409    /// SACK Chunk size is not large enough to contain header.
1410    #[error("SACK Chunk size is not large enough to contain header")]
1411    ErrSackSizeNotLargeEnoughInfo,
1412    /// Failed unmarshalling SACK chunk.
1413    #[error("failed unmarshalling SACK chunk")]
1414    ErrChunkUnmarshalSack,
1415
1416    /// Invalid chunk size.
1417    #[error("invalid chunk size")]
1418    ErrInvalidChunkSize,
1419    /// ChunkType is not of type SHUTDOWN.
1420    #[error("ChunkType is not of type SHUTDOWN")]
1421    ErrChunkTypeNotShutdown,
1422    /// Failed unmarshalling shutdown chunk.
1423    #[error("failed unmarshalling shutdown chunk")]
1424    ErrChunkUnmarshalShutdown,
1425
1426    /// ChunkType is not of type SHUTDOWN-ACK.
1427    #[error("ChunkType is not of type SHUTDOWN-ACK")]
1428    ErrChunkTypeNotShutdownAck,
1429    /// ChunkType is not of type SHUTDOWN-COMPLETE.
1430    #[error("ChunkType is not of type SHUTDOWN-COMPLETE")]
1431    ErrChunkTypeNotShutdownComplete,
1432
1433    /// Raw is smaller than the minimum length for a SCTP packet.
1434    #[error("raw is smaller than the minimum length for a SCTP packet")]
1435    ErrPacketRawTooSmall,
1436    /// Unable to parse SCTP chunk, not enough data for complete header.
1437    #[error("unable to parse SCTP chunk, not enough data for complete header")]
1438    ErrParseSctpChunkNotEnoughData,
1439    /// Failed to unmarshal, contains unknown chunk type.
1440    #[error("failed to unmarshal, contains unknown chunk type")]
1441    ErrUnmarshalUnknownChunkType,
1442    /// Checksum mismatch theirs.
1443    #[error("checksum mismatch theirs")]
1444    ErrChecksumMismatch,
1445
1446    /// Unexpected chunk popped (unordered).
1447    #[error("unexpected chunk popped (unordered)")]
1448    ErrUnexpectedChuckPoppedUnordered,
1449    /// Unexpected chunk popped (ordered).
1450    #[error("unexpected chunk popped (ordered)")]
1451    ErrUnexpectedChuckPoppedOrdered,
1452    /// Unexpected q state (should've been selected).
1453    #[error("unexpected q state (should've been selected)")]
1454    ErrUnexpectedQState,
1455    /// Try again.
1456    #[error("try again")]
1457    ErrTryAgain,
1458
1459    /// Abort chunk, with following errors.
1460    #[error("abort chunk, with following errors: {0}")]
1461    ErrAbortChunk(String),
1462    /// Shutdown called in non-Established state.
1463    #[error("shutdown called in non-Established state")]
1464    ErrShutdownNonEstablished,
1465    /// Association closed before connecting.
1466    #[error("association closed before connecting")]
1467    ErrAssociationClosedBeforeConn,
1468    /// Association init failed.
1469    #[error("association init failed")]
1470    ErrAssociationInitFailed,
1471    /// Association handshake closed.
1472    #[error("association handshake closed")]
1473    ErrAssociationHandshakeClosed,
1474    /// Silently discard.
1475    #[error("silently discard")]
1476    ErrSilentlyDiscard,
1477    /// The init not stored to send.
1478    #[error("the init not stored to send")]
1479    ErrInitNotStoredToSend,
1480    /// CookieEcho not stored to send.
1481    #[error("cookieEcho not stored to send")]
1482    ErrCookieEchoNotStoredToSend,
1483    /// SCTP packet must not have a source port of 0.
1484    #[error("sctp packet must not have a source port of 0")]
1485    ErrSctpPacketSourcePortZero,
1486    /// SCTP packet must not have a destination port of 0.
1487    #[error("sctp packet must not have a destination port of 0")]
1488    ErrSctpPacketDestinationPortZero,
1489    /// Init chunk must not be bundled with any other chunk.
1490    #[error("init chunk must not be bundled with any other chunk")]
1491    ErrInitChunkBundled,
1492    /// Init chunk expects a verification tag of 0 on the packet when out-of-the-blue.
1493    #[error("init chunk expects a verification tag of 0 on the packet when out-of-the-blue")]
1494    ErrInitChunkVerifyTagNotZero,
1495    /// Todo: handle Init when in state.
1496    #[error("todo: handle Init when in state")]
1497    ErrHandleInitState,
1498    /// No cookie in InitAck.
1499    #[error("no cookie in InitAck")]
1500    ErrInitAckNoCookie,
1501    /// There already exists a stream with identifier.
1502    #[error("there already exists a stream with identifier")]
1503    ErrStreamAlreadyExist,
1504    /// Failed to create a stream with identifier.
1505    #[error("Failed to create a stream with identifier")]
1506    ErrStreamCreateFailed,
1507    /// Unable to be popped from inflight queue TSN.
1508    #[error("unable to be popped from inflight queue TSN")]
1509    ErrInflightQueueTsnPop,
1510    /// Requested non-existent TSN.
1511    #[error("requested non-existent TSN")]
1512    ErrTsnRequestNotExist,
1513    /// Sending reset packet in non-Established state.
1514    #[error("sending reset packet in non-Established state")]
1515    ErrResetPacketInStateNotExist,
1516    /// Unexpected parameter type.
1517    #[error("unexpected parameter type")]
1518    ErrParameterType,
1519    /// Sending payload data in non-Established state.
1520    #[error("sending payload data in non-Established state")]
1521    ErrPayloadDataStateNotExist,
1522    /// Unhandled chunk type.
1523    #[error("unhandled chunk type")]
1524    ErrChunkTypeUnhandled,
1525    /// Handshake failed (INIT ACK).
1526    #[error("handshake failed (INIT ACK)")]
1527    ErrHandshakeInitAck,
1528    /// Handshake failed (COOKIE ECHO).
1529    #[error("handshake failed (COOKIE ECHO)")]
1530    ErrHandshakeCookieEcho,
1531
1532    /// Outbound packet larger than maximum message size.
1533    #[error("outbound packet larger than maximum message size")]
1534    ErrOutboundPacketTooLarge,
1535    /// Stream closed.
1536    #[error("Stream closed")]
1537    ErrStreamClosed,
1538    /// Stream not existed.
1539    #[error("Stream not existed")]
1540    ErrStreamNotExisted,
1541    /// Association not existed.
1542    #[error("Association not existed")]
1543    ErrAssociationNotExisted,
1544    /// Transport not existed.
1545    #[error("Transport not existed")]
1546    ErrTransportNoExisted,
1547    /// Io EOF.
1548    #[error("Io EOF")]
1549    ErrEof,
1550    /// Invalid SystemTime.
1551    #[error("Invalid SystemTime")]
1552    ErrInvalidSystemTime,
1553    /// Net Conn read error.
1554    #[error("Net Conn read error")]
1555    ErrNetConnRead,
1556    /// Max Data Channel ID.
1557    #[error("Max Data Channel ID")]
1558    ErrMaxDataChannelID,
1559
1560    //Data Channel
1561    /// DataChannel message is not long enough to determine type: (expected: , actual: ).
1562    #[error(
1563        "DataChannel message is not long enough to determine type: (expected: {expected}, actual: {actual})"
1564    )]
1565    UnexpectedEndOfBuffer {
1566        /// The number of bytes the parser required.
1567        expected: usize,
1568        /// The number of bytes actually available.
1569        actual: usize,
1570    },
1571    /// Unknown MessageType.
1572    #[error("Unknown MessageType {0}")]
1573    InvalidMessageType(u8),
1574    /// Unknown ChannelType.
1575    #[error("Unknown ChannelType {0}")]
1576    InvalidChannelType(u8),
1577    /// Unknown PayloadProtocolIdentifier.
1578    #[error("Unknown PayloadProtocolIdentifier {0}")]
1579    InvalidPayloadProtocolIdentifier(u8),
1580    /// Unknow Protocol.
1581    #[error("Unknow Protocol")]
1582    UnknownProtocol,
1583
1584    //Media
1585    /// Stream is nil.
1586    #[error("stream is nil")]
1587    ErrNilStream,
1588    /// Incomplete frame header.
1589    #[error("incomplete frame header")]
1590    ErrIncompleteFrameHeader,
1591    /// Incomplete frame data.
1592    #[error("incomplete frame data")]
1593    ErrIncompleteFrameData,
1594    /// Incomplete file header.
1595    #[error("incomplete file header")]
1596    ErrIncompleteFileHeader,
1597    /// IVF signature mismatch.
1598    #[error("IVF signature mismatch")]
1599    ErrSignatureMismatch,
1600    /// IVF version unknown, parser may not parse correctly.
1601    #[error("IVF version unknown, parser may not parse correctly")]
1602    ErrUnknownIVFVersion,
1603
1604    /// File not opened.
1605    #[error("file not opened")]
1606    ErrFileNotOpened,
1607    /// Invalid nil packet.
1608    #[error("invalid nil packet")]
1609    ErrInvalidNilPacket,
1610
1611    /// Bad header signature.
1612    #[error("bad header signature")]
1613    ErrBadIDPageSignature,
1614    /// Wrong header, expected beginning of stream.
1615    #[error("wrong header, expected beginning of stream")]
1616    ErrBadIDPageType,
1617    /// Payload for id page must be 19 bytes.
1618    #[error("payload for id page must be 19 bytes")]
1619    ErrBadIDPageLength,
1620    /// Bad payload signature.
1621    #[error("bad payload signature")]
1622    ErrBadIDPagePayloadSignature,
1623    /// Not enough data for payload header.
1624    #[error("not enough data for payload header")]
1625    ErrShortPageHeader,
1626    /// Bad OpusTags signature.
1627    #[error("bad OpusTags signature")]
1628    ErrBadOpusTagsSignature,
1629    /// Unsupported channel mapping family.
1630    #[error("unsupported channel mapping family")]
1631    ErrUnsupportedChannelMappingFamily,
1632
1633    /// Data is not a H264 bitstream.
1634    #[error("data is not a H264 bitstream")]
1635    ErrDataIsNotH264Stream,
1636    /// Data is not a H265 bitstream.
1637    #[error("data is not a H265 bitstream")]
1638    ErrDataIsNotH265Stream,
1639    /// Io EOF.
1640    #[error("Io EOF")]
1641    ErrIoEOF,
1642
1643    // mDNS
1644    /// MDNS: port not support, only 5353 is supported.
1645    #[error("mDNS: port not support, only 5353 is supported")]
1646    ErrMDNSPortNotSupported,
1647    /// MDNS: connection is closed.
1648    #[error("mDNS: connection is closed")]
1649    ErrMDNSConnectionClosed,
1650    /// MDNS: query not found.
1651    #[error("mDNS: query not found")]
1652    ErrMDNSQueryNotFound,
1653    /// MDNS: parsing/packing of this type isn't available yet.
1654    #[error("mDNS: parsing/packing of this type isn't available yet")]
1655    ErrNotStarted,
1656    /// MDNS: parsing/packing of this section has completed.
1657    #[error("mDNS: parsing/packing of this section has completed")]
1658    ErrSectionDone,
1659    /// MDNS: parsing/packing of this section is header.
1660    #[error("mDNS: parsing/packing of this section is header")]
1661    ErrSectionHeader,
1662    /// MDNS: insufficient data for base length type.
1663    #[error("mDNS: insufficient data for base length type")]
1664    ErrBaseLen,
1665    /// MDNS: insufficient data for calculated length type.
1666    #[error("mDNS: insufficient data for calculated length type")]
1667    ErrCalcLen,
1668    /// MDNS: segment prefix is reserved.
1669    #[error("mDNS: segment prefix is reserved")]
1670    ErrReserved,
1671    /// MDNS: too many pointers (>10).
1672    #[error("mDNS: too many pointers (>10)")]
1673    ErrTooManyPtr,
1674    /// MDNS: invalid pointer.
1675    #[error("mDNS: invalid pointer")]
1676    ErrInvalidPtr,
1677    /// MDNS: nil resource body.
1678    #[error("mDNS: nil resource body")]
1679    ErrNilResourceBody,
1680    /// MDNS: insufficient data for resource body length.
1681    #[error("mDNS: insufficient data for resource body length")]
1682    ErrResourceLen,
1683    /// MDNS: segment length too long.
1684    #[error("mDNS: segment length too long")]
1685    ErrSegTooLong,
1686    /// MDNS: zero length segment.
1687    #[error("mDNS: zero length segment")]
1688    ErrZeroSegLen,
1689    /// MDNS: resource length too long.
1690    #[error("mDNS: resource length too long")]
1691    ErrResTooLong,
1692    /// MDNS: too many Questions to pack (>65535).
1693    #[error("mDNS: too many Questions to pack (>65535)")]
1694    ErrTooManyQuestions,
1695    /// MDNS: too many Answers to pack (>65535).
1696    #[error("mDNS: too many Answers to pack (>65535)")]
1697    ErrTooManyAnswers,
1698    /// MDNS: too many Authorities to pack (>65535).
1699    #[error("mDNS: too many Authorities to pack (>65535)")]
1700    ErrTooManyAuthorities,
1701    /// MDNS: too many Additionals to pack (>65535).
1702    #[error("mDNS: too many Additionals to pack (>65535)")]
1703    ErrTooManyAdditionals,
1704    /// MDNS: name is not in canonical format (it must end with a .).
1705    #[error("mDNS: name is not in canonical format (it must end with a .)")]
1706    ErrNonCanonicalName,
1707    /// MDNS: character string exceeds maximum length (255).
1708    #[error("mDNS: character string exceeds maximum length (255)")]
1709    ErrStringTooLong,
1710    /// MDNS: compressed name in SRV resource data.
1711    #[error("mDNS: compressed name in SRV resource data")]
1712    ErrCompressedSrv,
1713    /// MDNS: empty builder msg.
1714    #[error("mDNS: empty builder msg")]
1715    ErrEmptyBuilderMsg,
1716
1717    //RTC
1718    /// ErrConnectionClosed indicates an operation executed after connection
1719    /// has already been closed.
1720    #[error("connection closed")]
1721    ErrConnectionClosed,
1722
1723    /// ErrDataChannelClosed indicates an operation executed when the data
1724    /// channel is not (yet) open or closed.
1725    #[error("data channel closed")]
1726    ErrDataChannelClosed,
1727
1728    /// ErrDataChannelNotOpen indicates a send was attempted on a data channel
1729    /// whose underlying SCTP stream has not been established yet — its
1730    /// `ready_state` is still `connecting`. Wait for the channel to open.
1731    #[error("data channel is not open yet")]
1732    ErrDataChannelNotOpen,
1733
1734    /// ErrDataChannelStreamIdNotAssigned indicates an operation that needs the channel's SCTP
1735    /// stream identifier ran before one was assigned.
1736    ///
1737    /// A data channel announced in-band has no stream identifier until the SCTP connected
1738    /// procedure assigns one, because RFC 8832 section 6 ties its parity to the DTLS role:
1739    /// even for the client, odd for the server. Until that role is resolved there is no
1740    /// correct identifier to pick, so the channel carries none rather than a guess.
1741    #[error("data channel stream identifier has not been assigned yet")]
1742    ErrDataChannelStreamIdNotAssigned,
1743
1744    /// ErrDataChannelNonExist indicates an operation executed when the data
1745    /// channel not existed.
1746    #[error("data channel not existed")]
1747    ErrDataChannelNotExisted,
1748
1749    /// ErrSendBufferFull indicates that a data-channel send was rejected because
1750    /// the channel's outstanding send buffer exceeded the configured hard ceiling
1751    /// (back-pressure). Retry after the buffer drains (e.g. on OnBufferedAmountLow).
1752    #[error("data channel send buffer full")]
1753    ErrSendBufferFull,
1754
1755    /// ErrCertificateExpired indicates that an x509 certificate has expired.
1756    #[error("x509Cert expired")]
1757    ErrCertificateExpired,
1758
1759    /// ErrNoTurnCredentials indicates that a TURN server URL was provided
1760    /// without required credentials.
1761    #[error("turn server credentials required")]
1762    ErrNoTurnCredentials,
1763
1764    /// ErrTurnCredentials indicates that provided TURN credentials are partial
1765    /// or malformed.
1766    #[error("invalid turn server credentials")]
1767    ErrTurnCredentials,
1768
1769    /// ErrExistingTrack indicates that a track already exists.
1770    #[error("track already exists")]
1771    ErrExistingTrack,
1772
1773    /// ErrExistingTrack indicates that a track already exists.
1774    #[error("track not existed")]
1775    ErrTrackNotExisted,
1776
1777    /// ErrPrivateKeyType indicates that a particular private key encryption
1778    /// chosen to generate a certificate is not supported.
1779    #[error("private key type not supported")]
1780    ErrPrivateKeyType,
1781
1782    /// ErrModifyingPeerIdentity indicates that an attempt to modify
1783    /// PeerIdentity was made after PeerConnection has been initialized.
1784    #[error("peerIdentity cannot be modified")]
1785    ErrModifyingPeerIdentity,
1786
1787    /// ErrModifyingCertificates indicates that an attempt to modify
1788    /// Certificates was made after PeerConnection has been initialized.
1789    #[error("certificates cannot be modified")]
1790    ErrModifyingCertificates,
1791
1792    /// ErrNonCertificate indicates that there is no certificate
1793    #[error("no certificate")]
1794    ErrNonCertificate,
1795
1796    /// ErrModifyingBundlePolicy indicates that an attempt to modify
1797    /// BundlePolicy was made after PeerConnection has been initialized.
1798    #[error("bundle policy cannot be modified")]
1799    ErrModifyingBundlePolicy,
1800
1801    /// ErrModifyingRTCPMuxPolicy indicates that an attempt to modify
1802    /// RTCPMuxPolicy was made after PeerConnection has been initialized.
1803    #[error("rtcp mux policy cannot be modified")]
1804    ErrModifyingRTCPMuxPolicy,
1805
1806    /// ErrModifyingICECandidatePoolSize indicates that an attempt to modify
1807    /// ICECandidatePoolSize was made after PeerConnection has been initialized.
1808    #[error("ice candidate pool size cannot be modified")]
1809    ErrModifyingICECandidatePoolSize,
1810
1811    /// ErrStringSizeLimit indicates that the character size limit of string is
1812    /// exceeded. The limit is hardcoded to 65535 according to specifications.
1813    #[error("data channel label exceeds size limit")]
1814    ErrStringSizeLimit,
1815
1816    /// ErrNegotiatedWithoutID indicates that an attempt to create a data channel
1817    /// was made while setting the negotiated option to true without providing
1818    /// the negotiated channel ID.
1819    #[error("negotiated set without channel id")]
1820    ErrNegotiatedWithoutID,
1821
1822    /// ErrRetransmitsOrPacketLifeTime indicates that an attempt to create a data
1823    /// channel was made with both options max_packet_life_time and max_retransmits
1824    /// set together. Such configuration is not supported by the specification
1825    /// and is mutually exclusive.
1826    #[error("both max_packet_life_time and max_retransmits was set")]
1827    ErrRetransmitsOrPacketLifeTime,
1828
1829    /// ErrCodecNotFound is returned when a codec search to the Media Engine fails
1830    #[error("codec not found")]
1831    ErrCodecNotFound,
1832
1833    /// ErrNoRemoteDescription indicates that an operation was rejected because
1834    /// the remote description is not set
1835    #[error("remote description is not set")]
1836    ErrNoRemoteDescription,
1837
1838    /// ErrIncorrectSDPSemantics indicates that the PeerConnection was configured to
1839    /// generate SDP Answers with different SDP Semantics than the received Offer
1840    #[error("offer SDP semantics does not match configuration")]
1841    ErrIncorrectSDPSemantics,
1842
1843    /// ErrIncorrectSignalingState indicates that the signaling state of PeerConnection is not correct
1844    #[error("operation can not be run in current signaling state")]
1845    ErrIncorrectSignalingState,
1846
1847    /// ErrProtocolTooLarge indicates that value given for a DataChannelInit protocol is
1848    /// longer then 65535 bytes
1849    #[error("protocol is larger then 65535 bytes")]
1850    ErrProtocolTooLarge,
1851
1852    /// ErrSenderNotCreatedByConnection indicates remove_track was called with a RtpSender not created
1853    /// by this PeerConnection
1854    #[error("RtpSender not created by this PeerConnection")]
1855    ErrSenderNotCreatedByConnection,
1856
1857    /// ErrSenderInitialTrackIdAlreadySet indicates a second call to
1858    /// RtpSender::set_initial_track_id which is not allowed.
1859    #[error("RtpSender's initial_track_id has already been set")]
1860    ErrSenderInitialTrackIdAlreadySet,
1861
1862    /// ErrSessionDescriptionNoFingerprint indicates set_remote_description was called with a SessionDescription that has no
1863    /// fingerprint
1864    #[error("set_remote_description called with no fingerprint")]
1865    ErrSessionDescriptionNoFingerprint,
1866
1867    /// ErrSessionDescriptionInvalidFingerprint indicates set_remote_description was called with a SessionDescription that
1868    /// has an invalid fingerprint
1869    #[error("set_remote_description called with an invalid fingerprint")]
1870    ErrSessionDescriptionInvalidFingerprint,
1871
1872    /// ErrSessionDescriptionConflictingFingerprints indicates set_remote_description was called with a SessionDescription that
1873    /// has an conflicting fingerprints
1874    #[error("set_remote_description called with multiple conflicting fingerprint")]
1875    ErrSessionDescriptionConflictingFingerprints,
1876
1877    /// ErrSessionDescriptionMissingIceUfrag indicates set_remote_description was called with a SessionDescription that
1878    /// is missing an ice-ufrag value
1879    #[error("set_remote_description called with no ice-ufrag")]
1880    ErrSessionDescriptionMissingIceUfrag,
1881
1882    /// ErrSessionDescriptionMissingIcePwd indicates set_remote_description was called with a SessionDescription that
1883    /// is missing an ice-pwd value
1884    #[error("set_remote_description called with no ice-pwd")]
1885    ErrSessionDescriptionMissingIcePwd,
1886
1887    /// ErrSessionDescriptionConflictingIceUfrag  indicates set_remote_description was called with a SessionDescription that
1888    /// contains multiple conflicting ice-ufrag values
1889    #[error("set_remote_description called with multiple conflicting ice-ufrag values")]
1890    ErrSessionDescriptionConflictingIceUfrag,
1891
1892    /// ErrSessionDescriptionConflictingIcePwd indicates set_remote_description was called with a SessionDescription that
1893    /// contains multiple conflicting ice-pwd values
1894    #[error("set_remote_description called with multiple conflicting ice-pwd values")]
1895    ErrSessionDescriptionConflictingIcePwd,
1896
1897    /// ErrNoSRTPProtectionProfile indicates that the DTLS handshake completed and no SRTP Protection Profile was chosen
1898    #[error("DTLS Handshake completed and no SRTP Protection Profile was chosen")]
1899    ErrNoSRTPProtectionProfile,
1900
1901    /// ErrFailedToGenerateCertificateFingerprint indicates that we failed to generate the fingerprint used for comparing certificates
1902    #[error("failed to generate certificate fingerprint")]
1903    ErrFailedToGenerateCertificateFingerprint,
1904
1905    /// ErrNoCodecsAvailable indicates that operation isn't possible because the MediaEngine has no codecs available
1906    #[error("operation failed no codecs are available")]
1907    ErrNoCodecsAvailable,
1908
1909    /// ErrUnsupportedCodec indicates the remote peer doesn't support the requested codec
1910    #[error("unable to start track, codec is not supported by remote")]
1911    ErrUnsupportedCodec,
1912
1913    /// Invalid state error.
1914    #[error("Invalid state error")]
1915    InvalidStateError,
1916
1917    /// Invalid modification error.
1918    #[error("Invalid modification error")]
1919    InvalidModificationError,
1920
1921    /// Range error.
1922    #[error("Range error {0}")]
1923    RangeError(String),
1924
1925    /// ErrSenderWithNoCodecs indicates that a RTPSender was created without any codecs. To send media the MediaEngine needs at
1926    /// least one configured codec.
1927    #[error("unable to populate media section, RTPSender created with no codecs")]
1928    ErrSenderWithNoCodecs,
1929
1930    /// ErrSenderWithNoSSRCs indicates that a RTPSender was created without any SSRRs. To send media the Sender needs at
1931    /// least one configured ssrc.
1932    #[error("unable to populate media section, RTPSender created with no ssrcs")]
1933    ErrSenderWithNoSSRCs,
1934
1935    /// ErrRTPSenderNewTrackHasIncorrectKind indicates that the new track is of a different kind than the previous/original
1936    #[error("new track must be of the same kind as previous")]
1937    ErrRTPSenderNewTrackHasIncorrectKind,
1938
1939    /// New track has incorrect envelope.
1940    #[error("new track has incorrect envelope")]
1941    ErrRTPSenderNewTrackHasIncorrectEnvelope,
1942
1943    /// ErrRTPSenderDataSent indicates that the sequence number transformer tries to be enabled after the data sending began
1944    #[error("Sequence number transformer must be enabled before sending data")]
1945    ErrRTPSenderDataSent,
1946
1947    /// ErrRTPSenderSeqTransEnabled indicates that the sequence number transformer has been already enabled
1948    #[error("Sequence number transformer has been already enabled")]
1949    ErrRTPSenderSeqTransEnabled,
1950
1951    /// ErrUnbindFailed indicates that a TrackLocal was not able to be unbind
1952    #[error("failed to unbind TrackLocal from PeerConnection")]
1953    ErrUnbindFailed,
1954
1955    /// ErrNoPayloaderForCodec indicates that the requested codec does not have a payloader
1956    #[error("the requested codec does not have a payloader")]
1957    ErrNoPayloaderForCodec,
1958
1959    /// ErrRegisterHeaderExtensionInvalidDirection indicates that a extension was registered with different
1960    /// directions for two different calls.
1961    #[error("a header extension must be registered with the same direction each time")]
1962    ErrRegisterHeaderExtensionInvalidDirection,
1963
1964    /// Invalid direction.
1965    #[error("invalid direction")]
1966    ErrInvalidDirection,
1967
1968    /// ErrRegisterHeaderExtensionNoFreeID indicates that there was no extension ID available which
1969    /// in turn means that all 15 available id(1 through 14) have been used.
1970    #[error(
1971        "no header extension ID was free to use(this means the maximum of 15 extensions have been registered)"
1972    )]
1973    ErrRegisterHeaderExtensionNoFreeID,
1974
1975    /// ErrSimulcastProbeOverflow indicates that too many Simulcast probe streams are in flight and the requested SSRC was ignored
1976    #[error("simulcast probe limit has been reached, new SSRC has been discarded")]
1977    ErrSimulcastProbeOverflow,
1978
1979    /// Enable detaching by calling webrtc.DetachDataChannels.
1980    #[error("enable detaching by calling webrtc.DetachDataChannels()")]
1981    ErrDetachNotEnabled,
1982    /// Datachannel not opened yet, try calling Detach from OnOpen.
1983    #[error("datachannel not opened yet, try calling Detach from OnOpen")]
1984    ErrDetachBeforeOpened,
1985    /// The DTLS transport has not started yet.
1986    #[error("the DTLS transport has not started yet")]
1987    ErrDtlsTransportNotStarted,
1988    /// Failed extracting keys from DTLS for SRTP.
1989    #[error("failed extracting keys from DTLS for SRTP")]
1990    ErrDtlsKeyExtractionFailed,
1991    /// Failed to start SRTP.
1992    #[error("failed to start SRTP")]
1993    ErrFailedToStartSRTP,
1994    /// Failed to start SRTCP.
1995    #[error("failed to start SRTCP")]
1996    ErrFailedToStartSRTCP,
1997    /// Attempted to start DTLSTransport that is not in new state.
1998    #[error("attempted to start DTLSTransport that is not in new state")]
1999    ErrInvalidDTLSStart,
2000    /// Peer didn't provide certificate via DTLS.
2001    #[error("peer didn't provide certificate via DTLS")]
2002    ErrNoRemoteCertificate,
2003    /// Identity provider is not implemented.
2004    #[error("identity provider is not implemented")]
2005    ErrIdentityProviderNotImplemented,
2006    /// Remote certificate does not match any fingerprint.
2007    #[error("remote certificate does not match any fingerprint")]
2008    ErrNoMatchingCertificateFingerprint,
2009    /// Unsupported fingerprint algorithm.
2010    #[error("unsupported fingerprint algorithm")]
2011    ErrUnsupportedFingerprintAlgorithm,
2012    /// ICE connection not started.
2013    #[error("ICE connection not started")]
2014    ErrICEConnectionNotStarted,
2015    /// Unknown candidate type.
2016    #[error("unknown candidate type")]
2017    ErrICECandidateTypeUnknown,
2018    /// Cannot convert ICE.CandidateType into webrtc.ICECandidateType, invalid type.
2019    #[error("cannot convert ice.CandidateType into webrtc.ICECandidateType, invalid type")]
2020    ErrICEInvalidConvertCandidateType,
2021    /// ICEAgent does not exist.
2022    #[error("ICEAgent does not exist")]
2023    ErrICEAgentNotExist,
2024    /// Unable to convert ICE candidates to ICECandidates.
2025    #[error("unable to convert ICE candidates to ICECandidates")]
2026    ErrICECandidatesConversionFailed,
2027    /// Unknown ICE Role.
2028    #[error("unknown ICE Role")]
2029    ErrICERoleUnknown,
2030    /// Unknown protocol.
2031    #[error("unknown protocol")]
2032    ErrICEProtocolUnknown,
2033    /// Gatherer not started.
2034    #[error("gatherer not started")]
2035    ErrICEGathererNotStarted,
2036    /// Unknown network type.
2037    #[error("unknown network type")]
2038    ErrNetworkTypeUnknown,
2039    /// New SDP does not match previous offer.
2040    #[error("new sdp does not match previous offer")]
2041    ErrSDPDoesNotMatchOffer,
2042    /// New SDP does not match previous answer.
2043    #[error("new sdp does not match previous answer")]
2044    ErrSDPDoesNotMatchAnswer,
2045    /// Provided value is not a valid enum value of type SDPType.
2046    #[error("provided value is not a valid enum value of type SDPType")]
2047    ErrPeerConnSDPTypeInvalidValue,
2048    /// Invalid state change op.
2049    #[error("invalid state change op")]
2050    ErrPeerConnStateChangeInvalid,
2051    /// Unhandled state change op.
2052    #[error("unhandled state change op")]
2053    ErrPeerConnStateChangeUnhandled,
2054    /// Invalid SDP type supplied to SetLocalDescription.
2055    #[error("invalid SDP type supplied to SetLocalDescription()")]
2056    ErrPeerConnSDPTypeInvalidValueSetLocalDescription,
2057    /// RemoteDescription contained media section without mid value.
2058    #[error("remoteDescription contained media section without mid value")]
2059    ErrPeerConnRemoteDescriptionWithoutMidValue,
2060    /// LocalDescription contained media section without mid value.
2061    #[error("localDescription contained media section without mid value")]
2062    ErrPeerConnLocalDescriptionWithoutMidValue,
2063    /// RemoteDescription has not been set yet.
2064    #[error("remoteDescription has not been set yet")]
2065    ErrPeerConnRemoteDescriptionNil,
2066    /// LocalDescription has not been set yet.
2067    #[error("localDescription has not been set yet")]
2068    ErrPeerConnLocalDescriptionNil,
2069    /// Single media section has an explicit SSRC.
2070    #[error("single media section has an explicit SSRC")]
2071    ErrPeerConnSingleMediaSectionHasExplicitSSRC,
2072    /// Could not add transceiver for remote SSRC.
2073    #[error("could not add transceiver for remote SSRC")]
2074    ErrPeerConnRemoteSSRCAddTransceiver,
2075    /// Mid RTP Extensions required for Simulcast.
2076    #[error("mid RTP Extensions required for Simulcast")]
2077    ErrPeerConnSimulcastMidRTPExtensionRequired,
2078    /// Stream id RTP Extensions required for Simulcast.
2079    #[error("stream id RTP Extensions required for Simulcast")]
2080    ErrPeerConnSimulcastStreamIDRTPExtensionRequired,
2081    /// Incoming SSRC failed Simulcast probing.
2082    #[error("incoming SSRC failed Simulcast probing")]
2083    ErrPeerConnSimulcastIncomingSSRCFailed,
2084    /// Failed collecting stats.
2085    #[error("failed collecting stats")]
2086    ErrPeerConnStatsCollectionFailed,
2087    /// Add_transceiver_from_kind only accepts one RTPTransceiverInit.
2088    #[error("add_transceiver_from_kind only accepts one RTPTransceiverInit")]
2089    ErrPeerConnAddTransceiverFromKindOnlyAcceptsOne,
2090    /// Add_transceiver_from_track only accepts one RTPTransceiverInit.
2091    #[error("add_transceiver_from_track only accepts one RTPTransceiverInit")]
2092    ErrPeerConnAddTransceiverFromTrackOnlyAcceptsOne,
2093    /// Add_transceiver_from_kind currently only supports recvonly.
2094    #[error("add_transceiver_from_kind currently only supports recvonly")]
2095    ErrPeerConnAddTransceiverFromKindSupport,
2096    /// Add_transceiver_from_track currently only supports sendonly and sendrecv.
2097    #[error("add_transceiver_from_track currently only supports sendonly and sendrecv")]
2098    ErrPeerConnAddTransceiverFromTrackSupport,
2099    /// TODO set_identity_provider.
2100    #[error("TODO set_identity_provider")]
2101    ErrPeerConnSetIdentityProviderNotImplemented,
2102    /// Write_RTCP failed to open write_stream.
2103    #[error("write_rtcp failed to open write_stream")]
2104    ErrPeerConnWriteRTCPOpenWriteStream,
2105    /// Cannot find transceiver with mid.
2106    #[error("cannot find transceiver with mid")]
2107    ErrPeerConnTransceiverMidNil,
2108    /// DTLSTransport must not be nil.
2109    #[error("DTLSTransport must not be nil")]
2110    ErrRTPReceiverDTLSTransportNil,
2111    /// Receive has already been called.
2112    #[error("Receive has already been called")]
2113    ErrRTPReceiverReceiveAlreadyCalled,
2114    /// Unable to find stream for Track with SSRC.
2115    #[error("unable to find stream for Track with SSRC")]
2116    ErrRTPReceiverWithSSRCTrackStreamNotFound,
2117    /// No trackStreams found for SSRC.
2118    #[error("no trackStreams found for SSRC")]
2119    ErrRTPReceiverForSSRCTrackStreamNotFound,
2120    /// No trackStreams found for RID.
2121    #[error("no trackStreams found for RID")]
2122    ErrRTPReceiverForRIDTrackStreamNotFound,
2123    /// Invalid RTP Receiver transition.
2124    #[error("invalid RTP Receiver transition")]
2125    ErrRTPReceiverStateChangeInvalid,
2126    /// Track must not be nil.
2127    #[error("Track must not be nil")]
2128    ErrRTPSenderTrackNil,
2129    /// RTPSender not existed.
2130    #[error("RTPSender not existed")]
2131    ErrRTPSenderNotExisted,
2132    /// Sender Track has been removed or replaced to nil.
2133    #[error("Sender Track has been removed or replaced to nil")]
2134    ErrRTPSenderTrackRemoved,
2135    /// Sender cannot add encoding as rid is empty.
2136    #[error("Sender cannot add encoding as rid is empty")]
2137    ErrRTPSenderRidNil,
2138    /// Sender cannot add encoding as there is no base track.
2139    #[error("Sender cannot add encoding as there is no base track")]
2140    ErrRTPSenderNoBaseEncoding,
2141    /// Sender cannot add encoding as provided track does not match base track.
2142    #[error("Sender cannot add encoding as provided track does not match base track")]
2143    ErrRTPSenderBaseEncodingMismatch,
2144    /// Sender cannot encoding due to RID collision.
2145    #[error("Sender cannot encoding due to RID collision")]
2146    ErrRTPSenderRIDCollision,
2147    /// Sender does not have track for RID.
2148    #[error("Sender does not have track for RID")]
2149    ErrRTPSenderNoTrackForRID,
2150    /// RTPReceiver not existed.
2151    #[error("RTPReceiver not existed")]
2152    ErrRTPReceiverNotExisted,
2153    /// DTLSTransport must not be nil.
2154    #[error("DTLSTransport must not be nil")]
2155    ErrRTPSenderDTLSTransportNil,
2156    /// Send has already been called.
2157    #[error("Send has already been called")]
2158    ErrRTPSenderSendAlreadyCalled,
2159    /// RTPTransceiver not existed.
2160    #[error("RTPTransceiver not existed")]
2161    ErrRTPTransceiverNotExisted,
2162    /// SCTPTransport not existed.
2163    #[error("SCTPTransport not existed")]
2164    ErrSCTPTransportNotExisted,
2165    /// DTLSTransport not existed.
2166    #[error("DTLSTransport not existed")]
2167    ErrDTLSTransportNotExisted,
2168    /// ErrRTPSenderTrackNil.
2169    #[error("errRTPSenderTrackNil")]
2170    ErrRTPTransceiverCannotChangeMid,
2171    /// Invalid state change in RTPTransceiver.setSending.
2172    #[error("invalid state change in RTPTransceiver.setSending")]
2173    ErrRTPTransceiverSetSendingInvalidState,
2174    /// Unsupported codec type by this transceiver.
2175    #[error("unsupported codec type by this transceiver")]
2176    ErrRTPTransceiverCodecUnsupported,
2177    /// DTLS not established.
2178    #[error("DTLS not established")]
2179    ErrSCTPTransportDTLS,
2180    /// Add_transceiver_SDP called with 0 transceivers.
2181    #[error("add_transceiver_sdp() called with 0 transceivers")]
2182    ErrSDPZeroTransceivers,
2183    /// Invalid Media Section. Media + DataChannel both enabled.
2184    #[error("invalid Media Section. Media + DataChannel both enabled")]
2185    ErrSDPMediaSectionMediaDataChanInvalid,
2186    /// Invalid Media Section Track Index.
2187    #[error("invalid Media Section Track Index")]
2188    ErrSDPMediaSectionTrackInvalid,
2189    /// Can't rollback from stable state.
2190    #[error("can't rollback from stable state")]
2191    ErrSignalingStateCannotRollback,
2192    /// Invalid proposed signaling state transition.
2193    #[error("invalid proposed signaling state transition: {0}")]
2194    ErrSignalingStateProposedTransitionInvalid(String),
2195    /// Cannot convert to StatsICECandidatePairStateSucceeded invalid ICE candidate state.
2196    #[error("cannot convert to StatsICECandidatePairStateSucceeded invalid ice candidate state")]
2197    ErrStatsICECandidateStateInvalid,
2198    /// ICETransport can only be called in ICETransportStateNew.
2199    #[error("ICETransport can only be called in ICETransportStateNew")]
2200    ErrICETransportNotInNew,
2201    /// Bad Certificate PEM format.
2202    #[error("bad Certificate PEM format")]
2203    ErrCertificatePEMFormatError,
2204    /// SCTP is not established.
2205    #[error("SCTP is not established")]
2206    ErrSCTPNotEstablished,
2207
2208    /// DataChannel is not opened.
2209    #[error("DataChannel is not opened")]
2210    ErrClosedPipe,
2211    /// Interceptor is not bind.
2212    #[error("Interceptor is not bind")]
2213    ErrInterceptorNotBind,
2214    /// Excessive retries in CreateOffer.
2215    #[error("excessive retries in CreateOffer")]
2216    ErrExcessiveRetries,
2217
2218    /// Not long enough to be a RTP Packet.
2219    #[error("not long enough to be a RTP Packet")]
2220    ErrRTPTooShort,
2221
2222    /// SyntaxIdDirSplit indicates rid-syntax could not be parsed.
2223    #[error("RFC8851 mandates rid-syntax        = %s\"a=rid:\" rid-id SP rid-dir")]
2224    SimulcastRidParseErrorSyntaxIdDirSplit,
2225    /// UnknownDirection indicates rid-dir was not parsed. Should be "send" or "recv".
2226    #[error("RFC8851 mandates rid-dir           = %s\"send\" / %s\"recv\"")]
2227    SimulcastRidParseErrorUnknownDirection,
2228
2229    //SDP
2230    /// Codec not found.
2231    #[error("codec not found")]
2232    CodecNotFound,
2233    /// Missing whitespace.
2234    #[error("missing whitespace")]
2235    MissingWhitespace,
2236    /// Missing colon.
2237    #[error("missing colon")]
2238    MissingColon,
2239    /// Payload type not found.
2240    #[error("payload type not found")]
2241    PayloadTypeNotFound,
2242    /// SdpInvalidSyntax.
2243    #[error("SdpInvalidSyntax: {0}")]
2244    SdpInvalidSyntax(String),
2245    /// SdpInvalidValue.
2246    #[error("SdpInvalidValue: {0}")]
2247    SdpInvalidValue(String),
2248    /// SDP: empty time_descriptions.
2249    #[error("sdp: empty time_descriptions")]
2250    SdpEmptyTimeDescription,
2251    /// Parse extmap.
2252    #[error("parse extmap: {0}")]
2253    ParseExtMap(String),
2254    /// A syntax error at a known offset in the input, rendered with the offending character marked.
2255    #[error("{} --> {} <-- {}", .s.substring(0,*.p), .s.substring(*.p, *.p+1), .s.substring(*.p+1, .s.len())
2256    )]
2257    SyntaxError {
2258        /// The input being parsed.
2259        s: String,
2260        /// The byte offset of the offending character in `s`.
2261        p: usize,
2262    },
2263
2264    //Third Party Error
2265    /// Invalid PEM.
2266    #[error("invalid PEM: {0}")]
2267    InvalidPEM(String),
2268    /// Parse ip.
2269    #[error("parse ip: {0}")]
2270    ParseIp(#[from] net::AddrParseError),
2271    /// Parse int.
2272    #[error("parse int: {0}")]
2273    ParseInt(#[from] ParseIntError),
2274    /// An underlying I/O error.
2275    #[error("{0}")]
2276    Io(#[source] IoError),
2277    /// URL parse.
2278    #[error("url parse: {0}")]
2279    Url(#[from] url::ParseError),
2280    /// UTF-8.
2281    #[error("utf8: {0}")]
2282    Utf8(#[from] FromUtf8Error),
2283    /// An error from the standard library or another boxed source.
2284    #[error("{0}")]
2285    Std(#[source] StdError),
2286    //Other Errors
2287    /// Other RTCP Err.
2288    #[error("Other RTCP Err: {0}")]
2289    OtherRtcpErr(String),
2290    /// Other RTP Err.
2291    #[error("Other RTP Err: {0}")]
2292    OtherRtpErr(String),
2293    /// Other SRTP Err.
2294    #[error("Other SRTP Err: {0}")]
2295    OtherSrtpErr(String),
2296    /// Other STUN Err.
2297    #[error("Other STUN Err: {0}")]
2298    OtherStunErr(String),
2299    /// Other TURN Err.
2300    #[error("Other TURN Err: {0}")]
2301    OtherTurnErr(String),
2302    /// Other ICE Err.
2303    #[error("Other ICE Err: {0}")]
2304    OtherIceErr(String),
2305    /// Other DTLS Err.
2306    #[error("Other DTLS Err: {0}")]
2307    OtherDtlsErr(String),
2308    /// Other SCTP Err.
2309    #[error("Other SCTP Err: {0}")]
2310    OtherSctpErr(String),
2311    /// Other DataChannel Err.
2312    #[error("Other DataChannel Err: {0}")]
2313    OtherDataChannelErr(String),
2314    /// Other Interceptor Err.
2315    #[error("Other Interceptor Err: {0}")]
2316    OtherInterceptorErr(String),
2317    /// Other Media Err.
2318    #[error("Other Media Err: {0}")]
2319    OtherMediaErr(String),
2320    /// Other mDNS Err.
2321    #[error("Other mDNS Err: {0}")]
2322    OtherMdnsErr(String),
2323    /// Other SDP Err.
2324    #[error("Other SDP Err: {0}")]
2325    OtherSdpErr(String),
2326    /// Other PeerConnection Err.
2327    #[error("Other PeerConnection Err: {0}")]
2328    OtherPeerConnectionErr(String),
2329    /// A provider-neutral cryptographic operation failed.
2330    #[error("crypto: {0}")]
2331    Crypto(String),
2332    #[error("{0}")]
2333    /// An error that does not fit any other variant, carrying a description.
2334    Other(String),
2335}
2336
2337impl Error {
2338    /// Wraps any `std::error::Error` implementation as [`Error::Std`],
2339    /// preserving the original error and its stack trace.
2340    pub fn from_std<T>(error: T) -> Self
2341    where
2342        T: std::error::Error + Send + Sync + 'static,
2343    {
2344        Error::Std(StdError(Box::new(error)))
2345    }
2346
2347    /// Attempts to downcast an [`Error::Std`] variant to a concrete error type.
2348    ///
2349    /// Returns `None` if this error is not `Error::Std` or if the inner error
2350    /// is not of type `T`.
2351    pub fn downcast_ref<T: std::error::Error + 'static>(&self) -> Option<&T> {
2352        if let Error::Std(s) = self {
2353            return s.0.downcast_ref();
2354        }
2355
2356        None
2357    }
2358}
2359
2360/// Wrapper around [`std::io::Error`] that implements [`PartialEq`].
2361///
2362/// `io::Error` does not implement `PartialEq`, which is required by the
2363/// top-level [`enum@Error`] enum. This newtype delegates equality to
2364/// [`io::ErrorKind`], so two `IoError` values are equal when their kinds match.
2365#[derive(Debug, Error)]
2366#[error("io error: {0}")]
2367pub struct IoError(#[from] pub io::Error);
2368
2369// Workaround for wanting PartialEq for io::Error.
2370impl PartialEq for IoError {
2371    fn eq(&self, other: &Self) -> bool {
2372        self.0.kind() == other.0.kind()
2373    }
2374}
2375
2376impl From<io::Error> for Error {
2377    fn from(e: io::Error) -> Self {
2378        Error::Io(IoError(e))
2379    }
2380}
2381
2382/// An escape hatch to preserve stack traces for errors whose concrete type is unknown.
2383///
2384/// Some traits exported by this crate (e.g. `Conn`, `Listener`) return `Error`.
2385/// When those traits are used in higher-level crates that have their own error
2386/// types, callers are forced to handle foreign errors. `StdError` boxes any
2387/// `std::error::Error` implementation and wraps it in `Error::Std`, preserving
2388/// the original error's message and — where supported — its stack trace.
2389///
2390/// Use [`Error::from_std`] to construct this variant.
2391#[derive(Debug, Error)]
2392#[error("{0}")]
2393pub struct StdError(pub Box<dyn std::error::Error + Send + Sync>);
2394
2395impl PartialEq for StdError {
2396    fn eq(&self, _: &Self) -> bool {
2397        false
2398    }
2399}
2400
2401impl<T> From<std::sync::PoisonError<T>> for Error {
2402    fn from(e: std::sync::PoisonError<T>) -> Self {
2403        Error::PoisonError(e.to_string())
2404    }
2405}
2406
2407impl From<SystemTimeError> for Error {
2408    fn from(e: SystemTimeError) -> Self {
2409        Error::Other(e.to_string())
2410    }
2411}
2412
2413/// Flattens a list of errors into a single [`enum@Error`], joining their messages with newlines.
2414///
2415/// Returns `Ok(())` if `errs` is empty.
2416pub fn flatten_errs(errs: Vec<impl Into<Error>>) -> Result<()> {
2417    if errs.is_empty() {
2418        Ok(())
2419    } else {
2420        let errs_strs: Vec<String> = errs.into_iter().map(|e| e.into().to_string()).collect();
2421        Err(Error::Other(errs_strs.join("\n")))
2422    }
2423}