-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to local UDP DNS resolver (#2635)
* Switch to the local UDP DNS resolver * Update shadowsocks-rust * Revert the rustup commands * Fix #2642
- Loading branch information
Showing
9 changed files
with
150 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/java/com/github/shadowsocks/net/ConcurrentUdpSocketListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************* | ||
* * | ||
* Copyright (C) 2019 by Max Lv <max.c.lv@gmail.com> * | ||
* Copyright (C) 2019 by Mygod Studio <contact-shadowsocks-android@mygod.be> * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
*******************************************************************************/ | ||
|
||
package com.github.shadowsocks.net | ||
|
||
import kotlinx.coroutines.* | ||
import timber.log.Timber | ||
|
||
abstract class ConcurrentUdpSocketListener(name: String, port: Int) : UdpSocketListener(name, port), | ||
CoroutineScope { | ||
override val coroutineContext = Dispatchers.IO + SupervisorJob() + CoroutineExceptionHandler { _, t -> Timber.w(t) } | ||
|
||
override fun shutdown(scope: CoroutineScope) { | ||
running = false | ||
cancel() | ||
super.shutdown(scope) | ||
coroutineContext[Job]!!.also { job -> scope.launch { job.join() } } | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
core/src/main/java/com/github/shadowsocks/net/UdpSocketListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* * | ||
* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> * | ||
* Copyright (C) 2017 by Mygod Studio <contact-shadowsocks-android@mygod.be> * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
*******************************************************************************/ | ||
|
||
package com.github.shadowsocks.net | ||
|
||
import android.annotation.SuppressLint | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.channels.sendBlocking | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import java.io.IOException | ||
import java.net.InetSocketAddress | ||
import java.net.SocketAddress | ||
import java.nio.ByteBuffer | ||
import java.nio.channels.DatagramChannel | ||
|
||
abstract class UdpSocketListener(name: String, val port: Int) : Thread(name) { | ||
|
||
private val udpChannel = DatagramChannel.open() | ||
private val closeChannel = Channel<Unit>(1) | ||
|
||
@Volatile | ||
protected var running = true | ||
|
||
/** | ||
* Inherited class do not need to close input/output streams as they will be closed automatically. | ||
*/ | ||
protected abstract fun handle(channel: DatagramChannel, sender: SocketAddress, query: ByteBuffer) | ||
|
||
final override fun run() { | ||
udpChannel.socket().bind(InetSocketAddress(port)) | ||
udpChannel.configureBlocking(true) | ||
udpChannel.use { | ||
while (running) { | ||
try { | ||
val query = ByteBuffer.allocate(1024) | ||
query.clear() | ||
udpChannel.receive(query)?.let { handle(udpChannel, it, query) } | ||
} catch (e: IOException) { | ||
if (running) Timber.w(e) | ||
continue | ||
} | ||
} | ||
} | ||
closeChannel.sendBlocking(Unit) | ||
} | ||
|
||
@SuppressLint("NewApi") | ||
open fun shutdown(scope: CoroutineScope) { | ||
running = false | ||
udpChannel.close() | ||
scope.launch { closeChannel.receive() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule shadowsocks-rust
updated
58 files
2 comments
on commit 700f4d2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commits introduces a java.nio.BufferOverflowException
at LocalDnsWorker.kt:47.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mygod Yes, I should allocate r.size
bytes here.
These should be already installed? https://github.com/shadowsocks/android-ndk-go/blob/1eb80fa0401423d6dcf21495f7d1755a90ba7d1e/Dockerfile#L49