net: return error instead of panic on receiving unexpected target

This commit is contained in:
eric
2024-04-20 21:06:26 +08:00
parent 9e06f37eb0
commit e2541dc594
3 changed files with 9 additions and 4 deletions

View File

@@ -118,7 +118,7 @@ jobs:
run: |
export CFG_COMMIT_HASH=`git log --pretty=format:'%h' -n 1`
export CFG_COMMIT_DATE=`git log --format="%ci" -n 1`
cargo build --release --target ${{ matrix.target }} -p leaf-bin
cargo build --release --target ${{ matrix.target }} -p leaf-cli
- name: rename and compress artifacts
run: |

View File

@@ -91,7 +91,7 @@ jobs:
run: |
export CFG_COMMIT_HASH=`git log --pretty=format:'%h' -n 1`
export CFG_COMMIT_DATE=`git log --format="%ci" -n 1`
cargo build --release --target ${{ matrix.target }} -p leaf-bin
cargo build --release --target ${{ matrix.target }} -p leaf-cli
- name: rename and compress artifacts
run: |

View File

@@ -59,8 +59,13 @@ pub struct StdOutboundDatagramSendHalf(Arc<UdpSocket>);
#[async_trait]
impl OutboundDatagramSendHalf for StdOutboundDatagramSendHalf {
async fn send_to(&mut self, buf: &[u8], target: &SocksAddr) -> io::Result<usize> {
// The type does not accept domain name.
self.0.send_to(buf, target.must_ip()).await
match target {
SocksAddr::Ip(a) => self.0.send_to(buf, a).await,
SocksAddr::Domain(domain, port) => Err(io::Error::new(
io::ErrorKind::Other,
format!("unexpected domain address {}:{}", domain, port),
)),
}
}
async fn close(&mut self) -> io::Result<()> {