@desklink/host 0.5.3 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -19
- package/dist/bridge.js +3 -3
- package/dist/bridge.js.map +1 -1
- package/dist/engineProcess.d.ts +5 -0
- package/dist/engineProcess.d.ts.map +1 -1
- package/dist/engineProcess.js +6 -3
- package/dist/engineProcess.js.map +1 -1
- package/dist/protocol.d.ts +39 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js.map +1 -1
- package/docs/BOUNDARY.md +4 -2
- package/docs/PROTOCOL.md +70 -7
- package/engine/Cargo.lock +6 -8
- package/engine/Cargo.toml +13 -1
- package/engine/src/audio.rs +398 -0
- package/engine/src/clipboard.rs +0 -34
- package/engine/src/convert.rs +0 -170
- package/engine/src/cursor.rs +0 -23
- package/engine/src/input.rs +0 -65
- package/engine/src/input_mac.rs +0 -11
- package/engine/src/keeper.rs +0 -137
- package/engine/src/keymap.rs +0 -107
- package/engine/src/keymap_mac.rs +0 -25
- package/engine/src/mac.rs +1 -28
- package/engine/src/main.rs +22 -0
- package/engine/src/peer.rs +297 -0
- package/engine/src/portal.rs +0 -18
- package/engine/src/protocol.rs +22 -162
- package/engine/src/session.rs +176 -3
- package/engine/src/win.rs +1 -0
- package/engine/src/x11.rs +0 -13
- package/engine/vendor/rtc-ice/Cargo.toml +137 -0
- package/engine/vendor/rtc-ice/DESKLINK-PATCH.md +111 -0
- package/engine/vendor/rtc-ice/LICENSE-APACHE +201 -0
- package/engine/vendor/rtc-ice/LICENSE-MIT +21 -0
- package/engine/vendor/rtc-ice/README.md +30 -0
- package/engine/vendor/rtc-ice/examples/ping_pong.rs +376 -0
- package/engine/vendor/rtc-ice/src/agent/agent_config.rs +126 -0
- package/engine/vendor/rtc-ice/src/agent/agent_proto.rs +172 -0
- package/engine/vendor/rtc-ice/src/agent/agent_selector.rs +647 -0
- package/engine/vendor/rtc-ice/src/agent/agent_stats.rs +292 -0
- package/engine/vendor/rtc-ice/src/agent/agent_test.rs +3594 -0
- package/engine/vendor/rtc-ice/src/agent/mod.rs +1753 -0
- package/engine/vendor/rtc-ice/src/attributes/control/control_test.rs +168 -0
- package/engine/vendor/rtc-ice/src/attributes/control/mod.rs +142 -0
- package/engine/vendor/rtc-ice/src/attributes/mod.rs +6 -0
- package/engine/vendor/rtc-ice/src/attributes/priority/mod.rs +37 -0
- package/engine/vendor/rtc-ice/src/attributes/priority/priority_test.rs +39 -0
- package/engine/vendor/rtc-ice/src/attributes/use_candidate/mod.rs +33 -0
- package/engine/vendor/rtc-ice/src/attributes/use_candidate/use_candidate_test.rs +19 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_host.rs +53 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_pair.rs +215 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_pair_test.rs +201 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_peer_reflexive.rs +49 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_relay.rs +53 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_relay_test.rs +114 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_server_reflexive.rs +53 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_server_reflexive_test.rs +91 -0
- package/engine/vendor/rtc-ice/src/candidate/candidate_test.rs +540 -0
- package/engine/vendor/rtc-ice/src/candidate/mod.rs +679 -0
- package/engine/vendor/rtc-ice/src/dl_trace.rs +49 -0
- package/engine/vendor/rtc-ice/src/lib.rs +88 -0
- package/engine/vendor/rtc-ice/src/mdns/mdns_test.rs +150 -0
- package/engine/vendor/rtc-ice/src/mdns/mod.rs +69 -0
- package/engine/vendor/rtc-ice/src/network_type/mod.rs +162 -0
- package/engine/vendor/rtc-ice/src/network_type/network_type_test.rs +95 -0
- package/engine/vendor/rtc-ice/src/rand/mod.rs +91 -0
- package/engine/vendor/rtc-ice/src/rand/rand_test.rs +115 -0
- package/engine/vendor/rtc-ice/src/state/mod.rs +106 -0
- package/engine/vendor/rtc-ice/src/state/state_test.rs +46 -0
- package/engine/vendor/rtc-ice/src/stats/mod.rs +166 -0
- package/engine/vendor/rtc-ice/src/tcp_type/mod.rs +47 -0
- package/engine/vendor/rtc-ice/src/tcp_type/tcp_type_test.rs +18 -0
- package/engine/vendor/rtc-ice/src/url/mod.rs +266 -0
- package/engine/vendor/rtc-ice/src/url/url_test.rs +142 -0
- package/package.json +8 -3
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
use std::net::IpAddr;
|
|
2
|
+
use std::time::Duration;
|
|
3
|
+
|
|
4
|
+
use super::*;
|
|
5
|
+
use crate::mdns::*;
|
|
6
|
+
use crate::network_type::NetworkType;
|
|
7
|
+
use crate::url::*;
|
|
8
|
+
|
|
9
|
+
/// The interval at which the agent performs candidate checks in the connecting phase.
|
|
10
|
+
pub(crate) const DEFAULT_CHECK_INTERVAL: Duration = Duration::from_millis(200);
|
|
11
|
+
|
|
12
|
+
/// The interval used to keep candidates alive.
|
|
13
|
+
pub(crate) const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(2);
|
|
14
|
+
|
|
15
|
+
/// The default time till an Agent transitions disconnected.
|
|
16
|
+
pub(crate) const DEFAULT_DISCONNECTED_TIMEOUT: Duration = Duration::from_secs(5);
|
|
17
|
+
|
|
18
|
+
/// The default time till an Agent transitions to failed after disconnected.
|
|
19
|
+
pub(crate) const DEFAULT_FAILED_TIMEOUT: Duration = Duration::from_secs(25);
|
|
20
|
+
|
|
21
|
+
/// Wait time before nominating a host candidate.
|
|
22
|
+
pub(crate) const DEFAULT_HOST_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_secs(0);
|
|
23
|
+
|
|
24
|
+
/// Wait time before nominating a srflx candidate.
|
|
25
|
+
pub(crate) const DEFAULT_SRFLX_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(500);
|
|
26
|
+
|
|
27
|
+
/// Wait time before nominating a prflx candidate.
|
|
28
|
+
pub(crate) const DEFAULT_PRFLX_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(1000);
|
|
29
|
+
|
|
30
|
+
/// Wait time before nominating a relay candidate.
|
|
31
|
+
pub(crate) const DEFAULT_RELAY_ACCEPTANCE_MIN_WAIT: Duration = Duration::from_millis(2000);
|
|
32
|
+
|
|
33
|
+
/// Max binding request before considering a pair failed.
|
|
34
|
+
pub(crate) const DEFAULT_MAX_BINDING_REQUESTS: u16 = 7;
|
|
35
|
+
|
|
36
|
+
/// The number of bytes that can be buffered before we start to error.
|
|
37
|
+
pub(crate) const MAX_BUFFER_SIZE: usize = 1000 * 1000; // 1MB
|
|
38
|
+
|
|
39
|
+
/// Wait time before binding requests can be deleted.
|
|
40
|
+
pub(crate) const MAX_BINDING_REQUEST_TIMEOUT: Duration = Duration::from_millis(4000);
|
|
41
|
+
|
|
42
|
+
pub(crate) fn default_candidate_types() -> Vec<CandidateType> {
|
|
43
|
+
vec![
|
|
44
|
+
CandidateType::Host,
|
|
45
|
+
CandidateType::ServerReflexive,
|
|
46
|
+
CandidateType::Relay,
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Collects the arguments to `ice::Agent` construction into a single structure, for
|
|
51
|
+
/// future-proofness of the interface.
|
|
52
|
+
#[derive(Default)]
|
|
53
|
+
pub struct AgentConfig {
|
|
54
|
+
/// The STUN and TURN servers to gather reflexive and relay candidates from.
|
|
55
|
+
pub urls: Vec<Url>,
|
|
56
|
+
|
|
57
|
+
/// It is used to perform connectivity checks. The values MUST be unguessable, with at least
|
|
58
|
+
/// 128 bits of random number generator output used to generate the password, and at least 24
|
|
59
|
+
/// bits of output to generate the username fragment.
|
|
60
|
+
pub local_ufrag: String,
|
|
61
|
+
/// It is used to perform connectivity checks. The values MUST be unguessable, with at least
|
|
62
|
+
/// 128 bits of random number generator output used to generate the password, and at least 24
|
|
63
|
+
/// bits of output to generate the username fragment.
|
|
64
|
+
pub local_pwd: String,
|
|
65
|
+
|
|
66
|
+
/// Controls mDNS query timeout
|
|
67
|
+
/// If the duration is 0, we will never go to failed.
|
|
68
|
+
pub multicast_dns_query_timeout: Option<Duration>,
|
|
69
|
+
|
|
70
|
+
/// Controls mDNS behavior for the ICE agent.
|
|
71
|
+
pub multicast_dns_mode: MulticastDnsMode,
|
|
72
|
+
|
|
73
|
+
/// Controls the local name for this agent. If none is specified a random one will be generated.
|
|
74
|
+
pub multicast_dns_local_name: String,
|
|
75
|
+
|
|
76
|
+
/// Control mDNS local IP address
|
|
77
|
+
pub multicast_dns_local_ip: Option<IpAddr>,
|
|
78
|
+
|
|
79
|
+
/// Defaults to 5 seconds when this property is nil.
|
|
80
|
+
/// If the duration is 0, the ICE Agent will never go to disconnected.
|
|
81
|
+
pub disconnected_timeout: Option<Duration>,
|
|
82
|
+
|
|
83
|
+
/// Defaults to 25 seconds when this property is nil.
|
|
84
|
+
/// If the duration is 0, we will never go to failed.
|
|
85
|
+
pub failed_timeout: Option<Duration>,
|
|
86
|
+
|
|
87
|
+
/// Determines how often should we send ICE keepalives (should be less than connection timeout
|
|
88
|
+
/// above) when this is nil, it defaults to 10 seconds.
|
|
89
|
+
/// A keepalive interval of 0 means we never send keepalive packets
|
|
90
|
+
pub keepalive_interval: Option<Duration>,
|
|
91
|
+
|
|
92
|
+
/// An optional configuration for disabling or enabling support for specific candidate types.
|
|
93
|
+
pub candidate_types: Vec<CandidateType>,
|
|
94
|
+
|
|
95
|
+
/// An optional configuration for disabling or enabling support for specific network types.
|
|
96
|
+
/// If empty, all network types are supported.
|
|
97
|
+
pub network_types: Vec<NetworkType>,
|
|
98
|
+
|
|
99
|
+
/// Controls how often our internal task loop runs when in the connecting state.
|
|
100
|
+
/// Only useful for testing.
|
|
101
|
+
pub check_interval: Duration,
|
|
102
|
+
|
|
103
|
+
/// The max amount of binding requests the agent will send over a candidate pair for validation
|
|
104
|
+
/// or nomination, if after max_binding_requests the candidate is yet to answer a binding
|
|
105
|
+
/// request or a nomination we set the pair as failed.
|
|
106
|
+
pub max_binding_requests: Option<u16>,
|
|
107
|
+
|
|
108
|
+
/// Whether this agent takes the controlling role.
|
|
109
|
+
pub is_controlling: bool,
|
|
110
|
+
|
|
111
|
+
/// lite agents do not perform connectivity check and only provide host candidates.
|
|
112
|
+
pub lite: bool,
|
|
113
|
+
|
|
114
|
+
/// Specify a minimum wait time before selecting host candidates.
|
|
115
|
+
pub host_acceptance_min_wait: Option<Duration>,
|
|
116
|
+
/// Specify a minimum wait time before selecting srflx candidates.
|
|
117
|
+
pub srflx_acceptance_min_wait: Option<Duration>,
|
|
118
|
+
/// Specify a minimum wait time before selecting prflx candidates.
|
|
119
|
+
pub prflx_acceptance_min_wait: Option<Duration>,
|
|
120
|
+
/// Specify a minimum wait time before selecting relay candidates.
|
|
121
|
+
pub relay_acceptance_min_wait: Option<Duration>,
|
|
122
|
+
|
|
123
|
+
/// Controls if self-signed certificates are accepted when connecting to TURN servers via TLS or
|
|
124
|
+
/// DTLS.
|
|
125
|
+
pub insecure_skip_verify: bool,
|
|
126
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
use super::*;
|
|
2
|
+
use mdns::{MDNS_PORT, MdnsEvent};
|
|
3
|
+
|
|
4
|
+
impl sansio::Protocol<TaggedBytesMut, (), ()> for Agent {
|
|
5
|
+
type Rout = TaggedBytesMut;
|
|
6
|
+
type Wout = TaggedBytesMut;
|
|
7
|
+
type Eout = TaggedEvent;
|
|
8
|
+
type Error = Error;
|
|
9
|
+
type Time = Instant;
|
|
10
|
+
|
|
11
|
+
fn handle_read(&mut self, msg: TaggedBytesMut) -> Result<()> {
|
|
12
|
+
// demuxing mDNS packet from STUN packet whether peer addr port is MDNS_PORT
|
|
13
|
+
if msg.transport.peer_addr.port() == MDNS_PORT {
|
|
14
|
+
let remote_candidates = if let Some(mdns_conn) = &mut self.mdns {
|
|
15
|
+
mdns_conn.handle_read(msg)?;
|
|
16
|
+
|
|
17
|
+
let mut remote_candidates = vec![];
|
|
18
|
+
// After mdns handle_read, check any query result
|
|
19
|
+
while let Some(event) = mdns_conn.poll_event() {
|
|
20
|
+
match event {
|
|
21
|
+
MdnsEvent::QueryAnswered(id, addr) => {
|
|
22
|
+
if let Some(mut c) = self.mdns_queries.remove(&id)
|
|
23
|
+
&& c.set_ip(&addr).is_ok()
|
|
24
|
+
{
|
|
25
|
+
debug!(
|
|
26
|
+
"mDNS query id {} answered Candidate {} with resolved_addr {} is added into remote candidates",
|
|
27
|
+
id,
|
|
28
|
+
c,
|
|
29
|
+
c.addr()
|
|
30
|
+
);
|
|
31
|
+
remote_candidates.push(c);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
MdnsEvent::QueryTimeout(id) => {
|
|
35
|
+
if let Some(c) = self.mdns_queries.remove(&id) {
|
|
36
|
+
error!("mDNS Query {} timed out for {}", id, c.address());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_ => {}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
remote_candidates
|
|
43
|
+
} else {
|
|
44
|
+
vec![]
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
self.trigger_request_connectivity_check(remote_candidates);
|
|
48
|
+
|
|
49
|
+
Ok(())
|
|
50
|
+
} else if let Some(local_index) =
|
|
51
|
+
self.find_local_candidate(msg.transport.local_addr, msg.transport.transport_protocol)
|
|
52
|
+
{
|
|
53
|
+
self.handle_inbound_candidate_msg(local_index, msg)
|
|
54
|
+
} else {
|
|
55
|
+
warn!(
|
|
56
|
+
"[{}]: Discarded message, not a valid local candidate from {:?}:{}",
|
|
57
|
+
self.get_name(),
|
|
58
|
+
msg.transport.transport_protocol,
|
|
59
|
+
msg.transport.local_addr,
|
|
60
|
+
);
|
|
61
|
+
Err(Error::ErrUnhandledStunpacket)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fn poll_read(&mut self) -> Option<Self::Rout> {
|
|
66
|
+
None
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fn handle_write(&mut self, _msg: ()) -> std::result::Result<(), Self::Error> {
|
|
70
|
+
Ok(())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
fn poll_write(&mut self) -> Option<Self::Wout> {
|
|
74
|
+
if let Some(mdns_conn) = &mut self.mdns {
|
|
75
|
+
while let Some(msg) = mdns_conn.poll_write() {
|
|
76
|
+
self.write_outs.push_back(msg);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
self.write_outs.pop_front()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fn handle_event(&mut self, _evt: ()) -> std::result::Result<(), Self::Error> {
|
|
84
|
+
Ok(())
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn poll_event(&mut self) -> Option<Self::Eout> {
|
|
88
|
+
self.event_outs.pop_front()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fn handle_timeout(&mut self, now: Self::Time) -> std::result::Result<(), Self::Error> {
|
|
92
|
+
let remote_candidates = if let Some(mdns_conn) = &mut self.mdns {
|
|
93
|
+
let _ = mdns_conn.handle_timeout(now);
|
|
94
|
+
|
|
95
|
+
let mut remote_candidates = vec![];
|
|
96
|
+
// After mdns handle_timeout, check any query result
|
|
97
|
+
while let Some(event) = mdns_conn.poll_event() {
|
|
98
|
+
match event {
|
|
99
|
+
MdnsEvent::QueryAnswered(id, addr) => {
|
|
100
|
+
if let Some(mut c) = self.mdns_queries.remove(&id)
|
|
101
|
+
&& c.set_ip(&addr).is_ok()
|
|
102
|
+
{
|
|
103
|
+
debug!(
|
|
104
|
+
"mDNS query id {} answered Candidate {} with resolved_addr {} is added into remote candidates",
|
|
105
|
+
id,
|
|
106
|
+
c,
|
|
107
|
+
c.addr()
|
|
108
|
+
);
|
|
109
|
+
remote_candidates.push(c);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
MdnsEvent::QueryTimeout(id) => {
|
|
113
|
+
if let Some(c) = self.mdns_queries.remove(&id) {
|
|
114
|
+
error!("mDNS Query {} timed out for {}", id, c.address());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_ => {}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
remote_candidates
|
|
121
|
+
} else {
|
|
122
|
+
vec![]
|
|
123
|
+
};
|
|
124
|
+
self.trigger_request_connectivity_check(remote_candidates);
|
|
125
|
+
|
|
126
|
+
if self.ufrag_pwd.remote_credentials.is_some()
|
|
127
|
+
&& (self.force_candidate_contact
|
|
128
|
+
|| self.last_checking_time + self.get_timeout_interval() <= now)
|
|
129
|
+
{
|
|
130
|
+
self.contact(now);
|
|
131
|
+
}
|
|
132
|
+
Ok(())
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fn poll_timeout(&mut self) -> Option<Self::Time> {
|
|
136
|
+
let mdns_timeout = if let Some(mdns_conn) = &mut self.mdns {
|
|
137
|
+
mdns_conn.poll_timeout()
|
|
138
|
+
} else {
|
|
139
|
+
None
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
let ice_timeout = if self.ufrag_pwd.remote_credentials.is_some()
|
|
143
|
+
&& !matches!(
|
|
144
|
+
self.connection_state,
|
|
145
|
+
ConnectionState::Failed | ConnectionState::Closed
|
|
146
|
+
) {
|
|
147
|
+
if self.force_candidate_contact {
|
|
148
|
+
// A connectivity check was requested; ask the driver to call
|
|
149
|
+
// `handle_timeout` as soon as possible. `last_checking_time` is in the
|
|
150
|
+
// past, so the resulting deadline is immediate.
|
|
151
|
+
Some(self.last_checking_time)
|
|
152
|
+
} else {
|
|
153
|
+
Some(self.last_checking_time + self.get_timeout_interval())
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
None
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// This treats the two options as a collection and picks the minimum
|
|
160
|
+
[mdns_timeout, ice_timeout].into_iter().flatten().min()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
fn close(&mut self) -> std::result::Result<(), Self::Error> {
|
|
164
|
+
self.set_selected_pair(None, None);
|
|
165
|
+
self.delete_all_candidates(false);
|
|
166
|
+
self.update_connection_state(None, ConnectionState::Closed);
|
|
167
|
+
if let Some(mdns_conn) = &mut self.mdns {
|
|
168
|
+
mdns_conn.close()?;
|
|
169
|
+
}
|
|
170
|
+
Ok(())
|
|
171
|
+
}
|
|
172
|
+
}
|