webrtc_ice/
error.rs

1use std::num::ParseIntError;
2use std::time::SystemTimeError;
3use std::{io, net};
4
5use thiserror::Error;
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, Error, PartialEq)]
10#[non_exhaustive]
11pub enum Error {
12    /// Indicates an error with Unknown info.
13    #[error("Unknown type")]
14    ErrUnknownType,
15
16    /// Indicates the scheme type could not be parsed.
17    #[error("unknown scheme type")]
18    ErrSchemeType,
19
20    /// Indicates query arguments are provided in a STUN URL.
21    #[error("queries not supported in stun address")]
22    ErrStunQuery,
23
24    /// Indicates an malformed query is provided.
25    #[error("invalid query")]
26    ErrInvalidQuery,
27
28    /// Indicates malformed hostname is provided.
29    #[error("invalid hostname")]
30    ErrHost,
31
32    /// Indicates malformed port is provided.
33    #[error("invalid port number")]
34    ErrPort,
35
36    /// Indicates local username fragment insufficient bits are provided.
37    /// Have to be at least 24 bits long.
38    #[error("local username fragment is less than 24 bits long")]
39    ErrLocalUfragInsufficientBits,
40
41    /// Indicates local passoword insufficient bits are provided.
42    /// Have to be at least 128 bits long.
43    #[error("local password is less than 128 bits long")]
44    ErrLocalPwdInsufficientBits,
45
46    /// Indicates an unsupported transport type was provided.
47    #[error("invalid transport protocol type")]
48    ErrProtoType,
49
50    /// Indicates the agent is closed.
51    #[error("the agent is closed")]
52    ErrClosed,
53
54    /// Indicates agent does not have a valid candidate pair.
55    #[error("no candidate pairs available")]
56    ErrNoCandidatePairs,
57
58    /// Indicates agent connection was canceled by the caller.
59    #[error("connecting canceled by caller")]
60    ErrCanceledByCaller,
61
62    /// Indicates agent was started twice.
63    #[error("attempted to start agent twice")]
64    ErrMultipleStart,
65
66    /// Indicates agent was started with an empty remote ufrag.
67    #[error("remote ufrag is empty")]
68    ErrRemoteUfragEmpty,
69
70    /// Indicates agent was started with an empty remote pwd.
71    #[error("remote pwd is empty")]
72    ErrRemotePwdEmpty,
73
74    /// Indicates agent was started without on_candidate.
75    #[error("no on_candidate provided")]
76    ErrNoOnCandidateHandler,
77
78    /// Indicates GatherCandidates has been called multiple times.
79    #[error("attempting to gather candidates during gathering state")]
80    ErrMultipleGatherAttempted,
81
82    /// Indicates agent was give TURN URL with an empty Username.
83    #[error("username is empty")]
84    ErrUsernameEmpty,
85
86    /// Indicates agent was give TURN URL with an empty Password.
87    #[error("password is empty")]
88    ErrPasswordEmpty,
89
90    /// Indicates we were unable to parse a candidate address.
91    #[error("failed to parse address")]
92    ErrAddressParseFailed,
93
94    /// Indicates that non host candidates were selected for a lite agent.
95    #[error("lite agents must only use host candidates")]
96    ErrLiteUsingNonHostCandidates,
97
98    /// Indicates that one or more URL was provided to the agent but no host candidate required them.
99    #[error("agent does not need URL with selected candidate types")]
100    ErrUselessUrlsProvided,
101
102    /// Indicates that the specified NAT1To1IPCandidateType is unsupported.
103    #[error("unsupported 1:1 NAT IP candidate type")]
104    ErrUnsupportedNat1to1IpCandidateType,
105
106    /// Indicates that the given 1:1 NAT IP mapping is invalid.
107    #[error("invalid 1:1 NAT IP mapping")]
108    ErrInvalidNat1to1IpMapping,
109
110    /// IPNotFound in NAT1To1IPMapping.
111    #[error("external mapped IP not found")]
112    ErrExternalMappedIpNotFound,
113
114    /// Indicates that the mDNS gathering cannot be used along with 1:1 NAT IP mapping for host
115    /// candidate.
116    #[error("mDNS gathering cannot be used with 1:1 NAT IP mapping for host candidate")]
117    ErrMulticastDnsWithNat1to1IpMapping,
118
119    /// Indicates that 1:1 NAT IP mapping for host candidate is requested, but the host candidate
120    /// type is disabled.
121    #[error("1:1 NAT IP mapping for host candidate ineffective")]
122    ErrIneffectiveNat1to1IpMappingHost,
123
124    /// Indicates that 1:1 NAT IP mapping for srflx candidate is requested, but the srflx candidate
125    /// type is disabled.
126    #[error("1:1 NAT IP mapping for srflx candidate ineffective")]
127    ErrIneffectiveNat1to1IpMappingSrflx,
128
129    /// Indicates an invalid MulticastDNSHostName.
130    #[error("invalid mDNS HostName, must end with .local and can only contain a single '.'")]
131    ErrInvalidMulticastDnshostName,
132
133    /// Indicates Restart was called when Agent is in GatheringStateGathering.
134    #[error("ICE Agent can not be restarted when gathering")]
135    ErrRestartWhenGathering,
136
137    /// Indicates a run operation was canceled by its individual done.
138    #[error("run was canceled by done")]
139    ErrRunCanceled,
140
141    /// Initialized Indicates TCPMux is not initialized and that invalidTCPMux is used.
142    #[error("TCPMux is not initialized")]
143    ErrTcpMuxNotInitialized,
144
145    /// Indicates we already have the connection with same remote addr.
146    #[error("conn with same remote addr already exists")]
147    ErrTcpRemoteAddrAlreadyExists,
148
149    #[error("failed to send packet")]
150    ErrSendPacket,
151    #[error("attribute not long enough to be ICE candidate")]
152    ErrAttributeTooShortIceCandidate,
153    #[error("could not parse component")]
154    ErrParseComponent,
155    #[error("could not parse priority")]
156    ErrParsePriority,
157    #[error("could not parse port")]
158    ErrParsePort,
159    #[error("could not parse related addresses")]
160    ErrParseRelatedAddr,
161    #[error("could not parse type")]
162    ErrParseType,
163    #[error("unknown candidate type")]
164    ErrUnknownCandidateType,
165    #[error("failed to get XOR-MAPPED-ADDRESS response")]
166    ErrGetXorMappedAddrResponse,
167    #[error("connection with same remote address already exists")]
168    ErrConnectionAddrAlreadyExist,
169    #[error("error reading streaming packet")]
170    ErrReadingStreamingPacket,
171    #[error("error writing to")]
172    ErrWriting,
173    #[error("error closing connection")]
174    ErrClosingConnection,
175    #[error("unable to determine networkType")]
176    ErrDetermineNetworkType,
177    #[error("missing protocol scheme")]
178    ErrMissingProtocolScheme,
179    #[error("too many colons in address")]
180    ErrTooManyColonsAddr,
181    #[error("unexpected error trying to read")]
182    ErrRead,
183    #[error("unknown role")]
184    ErrUnknownRole,
185    #[error("username mismatch")]
186    ErrMismatchUsername,
187    #[error("the ICE conn can't write STUN messages")]
188    ErrIceWriteStunMessage,
189    #[error("invalid url")]
190    ErrInvalidUrl,
191    #[error("relative URL without a base")]
192    ErrUrlParse,
193    #[error("Candidate IP could not be found")]
194    ErrCandidateIpNotFound,
195
196    #[error("parse int: {0}")]
197    ParseInt(#[from] ParseIntError),
198    #[error("parse addr: {0}")]
199    ParseIp(#[from] net::AddrParseError),
200    #[error("{0}")]
201    Io(#[source] IoError),
202    #[error("{0}")]
203    Util(#[from] util::Error),
204    #[error("{0}")]
205    Stun(#[from] stun::Error),
206    #[error("{0}")]
207    ParseUrl(#[from] url::ParseError),
208    #[error("{0}")]
209    Mdns(#[from] mdns::Error),
210    #[error("{0}")]
211    Turn(#[from] turn::Error),
212
213    #[error("{0}")]
214    Other(String),
215}
216
217#[derive(Debug, Error)]
218#[error("io error: {0}")]
219pub struct IoError(#[from] pub io::Error);
220
221// Workaround for wanting PartialEq for io::Error.
222impl PartialEq for IoError {
223    fn eq(&self, other: &Self) -> bool {
224        self.0.kind() == other.0.kind()
225    }
226}
227
228impl From<io::Error> for Error {
229    fn from(e: io::Error) -> Self {
230        Error::Io(IoError(e))
231    }
232}
233
234impl From<SystemTimeError> for Error {
235    fn from(e: SystemTimeError) -> Self {
236        Error::Other(e.to_string())
237    }
238}