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

fixed udp fallback #100

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions clash_lib/src/app/dispatcher/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,23 @@ impl Dispatcher {
packet.dst_addr = sess.destination.clone();

let mode = mode.read().await;
debug!("dispatching {} with mode {}", sess, mode);
trace!("dispatching {} with mode {}", sess, mode);

let (outbound_name, rule) = match *mode {
RunMode::Global => (PROXY_GLOBAL, None),
RunMode::Rule => router.match_route(&sess).await,
RunMode::Direct => (PROXY_DIRECT, None),
};

let outbound_name = outbound_name.to_string();
debug!("dispatching {} to {}", sess, outbound_name);

let remote_receiver_w = remote_receiver_w.clone();

let handler = outbound_manager
.read()
.await
.get_outbound(&outbound_name)
.expect(format!("unknown rule: {}", outbound_name).as_str());
let mgr = outbound_manager.read().await;
let handler = mgr.get_outbound(&outbound_name).unwrap_or_else(|| {
debug!("unknown rule: {}, fallback to direct", outbound_name);
mgr.get_outbound(PROXY_DIRECT).unwrap()
});

match outbound_handle_guard
.get_outbound_sender_mut(
Expand All @@ -261,6 +262,7 @@ impl Dispatcher {
.await
{
None => {
debug!("building {} outbound datagram connecting", sess);
let outbound_datagram =
match handler.connect_datagram(&sess, resolver.clone()).await {
Ok(v) => v,
Expand Down Expand Up @@ -333,7 +335,9 @@ impl Dispatcher {
};
}
Some(handle) => match handle.send(packet).await {
Ok(_) => {}
Ok(_) => {
debug!("reusing {} sent to remote", sess);
}
Err(err) => {
error!("failed to send packet to remote: {}", err);
}
Expand Down