Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat connect to peer on another server #6206

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions flutter/lib/desktop/pages/connection_page.dart
Expand Up @@ -147,6 +147,34 @@ class _ConnectionPageState extends State<ConnectionPage>
/// Connects to the selected peer.
void onConnect({bool isFileTransfer = false}) {
var id = _idController.id;
if (id.contains('@')) {
var input = id;
id = id.split('@')[0];

// Ex: 143242314@164.432.413:21116?key=32432432Efdsf34 or 143242314@public
RegExp regex = RegExp(r'(\d+)@([^:]+)(?::(\d+))?(?:\?key=(.+))?');
Match? match = regex.firstMatch(input);

if (match != null) {
// String id = match.group(1)!;
String host = match.group(2)!;
String? port = match.group(3);
String? key = match.group(4);

if (host == "public"){
host = "rs-ny.rustdesk.com";
port = "21116";
}
var sValue = host + ":" + port!;
debugPrint('text_field_rendezvous_server: $sValue key: $key');
bind.mainSetOption(key: "text_field_rendezvous_server", value: sValue);
if (key != null) {
bind.mainSetOption(key: "text_field_rendezvous_server_key", value: key);
}
} else {
debugPrint('regex match failed');
}
}
connect(context, id, isFileTransfer: isFileTransfer);
}

Expand Down
7 changes: 6 additions & 1 deletion src/client.rs
Expand Up @@ -221,7 +221,12 @@ impl Client {
) -> ResultType<(Stream, bool, Option<Vec<u8>>)> {
interface.update_direct(None);
interface.update_received(false);
match Self::_start(peer, key, token, conn_type, interface).await {
let mut _key = key;
let tf_key = Config::get_option("text_field_rendezvous_server_key");
if !tf_key.is_empty() {
_key = tf_key.as_str();
}
match Self::_start(peer, _key, token, conn_type, interface).await {
Err(err) => {
let err_str = err.to_string();
if err_str.starts_with("Failed") {
Expand Down
14 changes: 12 additions & 2 deletions src/ipc.rs
Expand Up @@ -19,7 +19,7 @@ pub use clipboard::ClipboardFile;
use hbb_common::{
allow_err, bail, bytes,
bytes_codec::BytesCodec,
config::{self, Config, Config2},
config::{self, Config, Config2, RENDEZVOUS_SERVERS, RENDEZVOUS_PORT},
futures::StreamExt as _,
futures_util::sink::SinkExt,
log, password_security as password, timeout, tokio,
Expand Down Expand Up @@ -764,7 +764,17 @@ pub fn get_id() -> String {
}

pub async fn get_rendezvous_server(ms_timeout: u64) -> (String, Vec<String>) {
if let Ok(Some(v)) = get_config_async("rendezvous_server", ms_timeout).await {
let mut v = Config::get_option("text_field_rendezvous_server");
if !v.is_empty() {
if v == "public"{
v = RENDEZVOUS_SERVERS[0].to_string() +":"+ RENDEZVOUS_PORT.to_string().as_str();
}
let mut urls = v.split(",");
let a = urls.next().unwrap_or_default().to_owned();
let b: Vec<String> = urls.map(|x| x.to_owned()).collect();
Config::set_option("text_field_rendezvous_server".to_string(),"".to_string());
(a, b)
} else if let Ok(Some(v)) = get_config_async("rendezvous_server", ms_timeout).await {
let mut urls = v.split(",");
let a = urls.next().unwrap_or_default().to_owned();
let b: Vec<String> = urls.map(|x| x.to_owned()).collect();
Expand Down