Commit 2798edda authored by Mygod's avatar Mygod

Remove KCP from project

parent 044f6f1f
classes
bin
gen
target target
local.properties local.properties
.classpath
.project
.settings
tests/bin
tests/gen
tests/local.properties
NUL
gen_*
*.class
*.o
local.sbt local.sbt
.deps
/proguard-sbt.txt /proguard-sbt.txt
#Intellij IDEA #Intellij IDEA
*.iml
*.ipr
*.iws
.idea/ .idea/
out/
.d .d
#NDK
src/main/obj
src/main/libs
jni/Application.mk
...@@ -12,7 +12,6 @@ A [shadowsocks](http://shadowsocks.org) client for Android, written in Scala. ...@@ -12,7 +12,6 @@ A [shadowsocks](http://shadowsocks.org) client for Android, written in Scala.
* JDK 1.8 * JDK 1.8
* SBT 0.13.0+ * SBT 0.13.0+
* Go 1.4+
* Android SDK * Android SDK
- Build Tools 25+ - Build Tools 25+
- Android Support Repository and Google Repository (see `build.sbt` for version) - Android Support Repository and Google Repository (see `build.sbt` for version)
...@@ -53,7 +52,6 @@ Translators can go to [POEditor](https://poeditor.com/join/project/u5VHO9vhSf) t ...@@ -53,7 +52,6 @@ Translators can go to [POEditor](https://poeditor.com/join/project/u5VHO9vhSf) t
<li>shadowsocks-libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/LICENSE">GPLv3</a></li> <li>shadowsocks-libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/LICENSE">GPLv3</a></li>
<li>pdnsd: <a href="https://github.com/shadowsocks/shadowsocks-android/blob/master/src/main/jni/pdnsd/COPYING">GPLv3</a></li> <li>pdnsd: <a href="https://github.com/shadowsocks/shadowsocks-android/blob/master/src/main/jni/pdnsd/COPYING">GPLv3</a></li>
<li>libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/libev/LICENSE">GPLv2</a></li> <li>libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/libev/LICENSE">GPLv2</a></li>
<li>kcptun: <a href="https://github.com/xtaci/kcptun/commits/master/LICENSE.md">MIT</a></li>
<li>libsodium: <a href="https://github.com/jedisct1/libsodium/blob/master/LICENSE">ISC</a></li> <li>libsodium: <a href="https://github.com/jedisct1/libsodium/blob/master/LICENSE">ISC</a></li>
</ul> </ul>
......
...@@ -298,7 +298,6 @@ along with this program. If not, see <a href="http://www.gnu.org/licenses/">http ...@@ -298,7 +298,6 @@ along with this program. If not, see <a href="http://www.gnu.org/licenses/">http
<li>shadowsocks-libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/LICENSE">GPLv3</a></li> <li>shadowsocks-libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/LICENSE">GPLv3</a></li>
<li>pdnsd: <a href="https://github.com/shadowsocks/shadowsocks-android/blob/master/src/main/jni/pdnsd/COPYING">GPLv3</a></li> <li>pdnsd: <a href="https://github.com/shadowsocks/shadowsocks-android/blob/master/src/main/jni/pdnsd/COPYING">GPLv3</a></li>
<li>libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/libev/LICENSE">GPLv2</a></li> <li>libev: <a href="https://github.com/shadowsocks/shadowsocks-libev/blob/master/libev/LICENSE">GPLv2</a></li>
<li>kcptun: <a href="https://github.com/xtaci/kcptun/commits/master/LICENSE.md">MIT</a></li>
<li>libsodium: <a href="https://github.com/jedisct1/libsodium/blob/master/LICENSE">ISC</a></li> <li>libsodium: <a href="https://github.com/jedisct1/libsodium/blob/master/LICENSE">ISC</a></li>
</ul> </ul>
......
...@@ -135,12 +135,6 @@ ...@@ -135,12 +135,6 @@
<string name="nat_connected">Connected</string> <string name="nat_connected">Connected</string>
<string name="not_connected">Not connected</string> <string name="not_connected">Not connected</string>
<!-- kcp -->
<string name="kcp_summary">Enable Shadowsocks over KCP</string>
<string name="kcp_port">KCP Port</string>
<string name="kcp_port_summary">%d (port number of the remote KCPTUN server)</string>
<string name="kcpcli">KCP Parameters (CLI)</string>
<!-- acl --> <!-- acl -->
<string name="custom_rules">Custom rules</string> <string name="custom_rules">Custom rules</string>
<string name="action_selection">Selection…</string> <string name="action_selection">Selection…</string>
......
...@@ -71,26 +71,4 @@ ...@@ -71,26 +71,4 @@
</be.mygod.preference.PreferenceCategory> </be.mygod.preference.PreferenceCategory>
<be.mygod.preference.PreferenceCategory
android:title="KCP">
<SwitchPreference
android:key="kcp"
android:summary="@string/kcp_summary"
android:title="KCP"/>
<be.mygod.preference.NumberPickerPreference
app:min="1"
app:max="65535"
android:key="kcpPort"
android:summary="@string/kcp_port_summary"
android:title="@string/kcp_port"/>
<be.mygod.preference.EditTextPreference
android:key="kcpcli"
android:summary="%s"
android:title="@string/kcpcli"/>
</be.mygod.preference.PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>
...@@ -28,7 +28,6 @@ import java.util.{Timer, TimerTask} ...@@ -28,7 +28,6 @@ import java.util.{Timer, TimerTask}
import android.app.Service import android.app.Service
import android.content.{BroadcastReceiver, Context, Intent, IntentFilter} import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import android.net.ConnectivityManager
import android.os.{Handler, IBinder, RemoteCallbackList} import android.os.{Handler, IBinder, RemoteCallbackList}
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
...@@ -49,7 +48,6 @@ trait BaseService extends Service { ...@@ -49,7 +48,6 @@ trait BaseService extends Service {
@volatile protected var profile: Profile = _ @volatile protected var profile: Profile = _
case class NameNotResolvedException() extends IOException case class NameNotResolvedException() extends IOException
case class KcpcliParseException(cause: Throwable) extends Exception(cause)
case class NullConnectionException() extends NullPointerException case class NullConnectionException() extends NullPointerException
var timer: Timer = _ var timer: Timer = _
...@@ -67,19 +65,6 @@ trait BaseService extends Service { ...@@ -67,19 +65,6 @@ trait BaseService extends Service {
} }
var closeReceiverRegistered: Boolean = _ var closeReceiverRegistered: Boolean = _
var kcptunProcess: GuardedProcess = _
private val networkReceiver: BroadcastReceiver = (context: Context, _: Intent) => {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE).asInstanceOf[ConnectivityManager]
val activeNetwork = cm.getActiveNetworkInfo
val isConnected = activeNetwork != null && activeNetwork.isConnected
if (isConnected && profile.kcp && kcptunProcess != null) {
restartHanlder.removeCallbacks(null)
restartHanlder.postDelayed(() => if (kcptunProcess != null) kcptunProcess.restart(), 2000)
}
}
var networkReceiverRegistered: Boolean = _
val binder = new IShadowsocksService.Stub { val binder = new IShadowsocksService.Stub {
override def getState: Int = { override def getState: Int = {
state state
...@@ -185,14 +170,6 @@ trait BaseService extends Service { ...@@ -185,14 +170,6 @@ trait BaseService extends Service {
closeReceiverRegistered = true closeReceiverRegistered = true
} }
if (profile.kcp && !networkReceiverRegistered) {
// register network change receiver
val filter = new IntentFilter()
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkReceiver, filter)
networkReceiverRegistered = true
}
app.track(getClass.getSimpleName, "start") app.track(getClass.getSimpleName, "start")
changeState(State.CONNECTING) changeState(State.CONNECTING)
...@@ -202,8 +179,6 @@ trait BaseService extends Service { ...@@ -202,8 +179,6 @@ trait BaseService extends Service {
Utils.ThrowableFuture(try connect() catch { Utils.ThrowableFuture(try connect() catch {
case _: NameNotResolvedException => stopRunner(stopService = true, getString(R.string.invalid_server)) case _: NameNotResolvedException => stopRunner(stopService = true, getString(R.string.invalid_server))
case exc: KcpcliParseException =>
stopRunner(stopService = true, getString(R.string.service_failed) + ": " + exc.cause.getMessage)
case _: NullConnectionException => stopRunner(stopService = true, getString(R.string.reboot_required)) case _: NullConnectionException => stopRunner(stopService = true, getString(R.string.reboot_required))
case exc: Throwable => case exc: Throwable =>
stopRunner(stopService = true, getString(R.string.service_failed) + ": " + exc.getMessage) stopRunner(stopService = true, getString(R.string.service_failed) + ": " + exc.getMessage)
...@@ -218,10 +193,6 @@ trait BaseService extends Service { ...@@ -218,10 +193,6 @@ trait BaseService extends Service {
unregisterReceiver(closeReceiver) unregisterReceiver(closeReceiver)
closeReceiverRegistered = false closeReceiverRegistered = false
} }
if (networkReceiverRegistered) {
unregisterReceiver(networkReceiver)
networkReceiverRegistered = false
}
// Make sure update total traffic when stopping the runner // Make sure update total traffic when stopping the runner
updateTrafficTotal(TrafficMonitor.txTotal, TrafficMonitor.rxTotal) updateTrafficTotal(TrafficMonitor.txTotal, TrafficMonitor.rxTotal)
......
...@@ -25,13 +25,11 @@ import android.content.{DialogInterface, Intent, SharedPreferences} ...@@ -25,13 +25,11 @@ import android.content.{DialogInterface, Intent, SharedPreferences}
import android.os.{Build, Bundle, UserManager} import android.os.{Build, Bundle, UserManager}
import android.support.v14.preference.SwitchPreference import android.support.v14.preference.SwitchPreference
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.preference.Preference
import android.support.v7.widget.Toolbar.OnMenuItemClickListener import android.support.v7.widget.Toolbar.OnMenuItemClickListener
import android.view.MenuItem import android.view.MenuItem
import be.mygod.preference.PreferenceFragment import be.mygod.preference.PreferenceFragment
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.preferences.KcpCliPreferenceDialogFragment
import com.github.shadowsocks.utils.{Action, Key, Utils} import com.github.shadowsocks.utils.{Action, Key, Utils}
class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListener class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListener
...@@ -75,11 +73,6 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe ...@@ -75,11 +73,6 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
isProxyApps.setChecked(app.settings.getBoolean(Key.proxyApps, false)) // fetch proxyApps updated by AppManager isProxyApps.setChecked(app.settings.getBoolean(Key.proxyApps, false)) // fetch proxyApps updated by AppManager
} }
override def onDisplayPreferenceDialog(preference: Preference): Unit = preference.getKey match {
case Key.kcpcli => displayPreferenceDialog(Key.kcpcli, new KcpCliPreferenceDialogFragment())
case _ => super.onDisplayPreferenceDialog(preference)
}
override def onMenuItemClick(item: MenuItem): Boolean = item.getItemId match { override def onMenuItemClick(item: MenuItem): Boolean = item.getItemId match {
case R.id.action_delete => case R.id.action_delete =>
new AlertDialog.Builder(getActivity) new AlertDialog.Builder(getActivity)
......
...@@ -53,15 +53,10 @@ class ShadowsocksNatService extends BaseService { ...@@ -53,15 +53,10 @@ class ShadowsocksNatService extends BaseService {
var su: Shell.Interactive = _ var su: Shell.Interactive = _
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
val conf = if (profile.kcp) { val conf =
ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90, profile.localPort,
profile.password, profile.method, 600)
} else {
ConfigUtils ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort, .SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort,
profile.password, profile.method, 600) profile.password, profile.method, 600)
}
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-nat.conf"))(p => { Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-nat.conf"))(p => {
p.println(conf) p.println(conf)
}) })
...@@ -85,27 +80,6 @@ class ShadowsocksNatService extends BaseService { ...@@ -85,27 +80,6 @@ class ShadowsocksNatService extends BaseService {
sslocalProcess = new GuardedProcess(cmd).start() sslocalProcess = new GuardedProcess(cmd).start()
} }
def startKcptunDaemon() {
if (profile.kcpcli == null) profile.kcpcli = ""
val host = if (profile.host.contains(":")) {
"[" + profile.host + "]"
} else {
profile.host
}
val cmd = ArrayBuffer[String](getApplicationInfo.nativeLibraryDir + "/libkcptun.so"
, "-r", host + ":" + profile.kcpPort
, "-l", "127.0.0.1:" + (profile.localPort + 90))
try cmd ++= Utils.translateCommandline(profile.kcpcli) catch {
case exc: Exception => throw KcpcliParseException(exc)
}
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
kcptunProcess = new GuardedProcess(cmd).start()
}
def startDNSTunnel() { def startDNSTunnel() {
if (profile.udpdns) { if (profile.udpdns) {
val conf = ConfigUtils val conf = ConfigUtils
...@@ -130,15 +104,10 @@ class ShadowsocksNatService extends BaseService { ...@@ -130,15 +104,10 @@ class ShadowsocksNatService extends BaseService {
sstunnelProcess = new GuardedProcess(cmd).start() sstunnelProcess = new GuardedProcess(cmd).start()
} else { } else {
val conf = if (profile.kcp) { val conf =
ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90,
profile.localPort + 63, profile.password, profile.method, 10)
} else {
ConfigUtils ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + 63, .SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + 63,
profile.password, profile.method, 10) profile.password, profile.method, 10)
}
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-tunnel-nat.conf"))(p => { Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-tunnel-nat.conf"))(p => {
p.println(conf) p.println(conf)
}) })
...@@ -205,7 +174,6 @@ class ShadowsocksNatService extends BaseService { ...@@ -205,7 +174,6 @@ class ShadowsocksNatService extends BaseService {
startShadowsocksDaemon() startShadowsocksDaemon()
if (!profile.udpdns) startDnsDaemon() if (!profile.udpdns) startDnsDaemon()
if (profile.kcp) startKcptunDaemon()
setupIptables() setupIptables()
...@@ -221,10 +189,6 @@ class ShadowsocksNatService extends BaseService { ...@@ -221,10 +189,6 @@ class ShadowsocksNatService extends BaseService {
} }
def killProcesses() { def killProcesses() {
if (kcptunProcess != null) {
kcptunProcess.destroy()
kcptunProcess = null
}
if (sslocalProcess != null) { if (sslocalProcess != null) {
sslocalProcess.destroy() sslocalProcess.destroy()
sslocalProcess = null sslocalProcess = null
......
...@@ -91,10 +91,6 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -91,10 +91,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
} }
def killProcesses() { def killProcesses() {
if (kcptunProcess != null) {
kcptunProcess.destroy()
kcptunProcess = null
}
if (sslocalProcess != null) { if (sslocalProcess != null) {
sslocalProcess.destroy() sslocalProcess.destroy()
sslocalProcess = null sslocalProcess = null
...@@ -157,76 +153,19 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -157,76 +153,19 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val fd = startVpn() val fd = startVpn()
if (!sendFd(fd)) throw new Exception("sendFd failed") if (!sendFd(fd)) throw new Exception("sendFd failed")
if (profile.kcp) {
startKcptunDaemon()
}
startShadowsocksDaemon() startShadowsocksDaemon()
if (profile.udpdns && profile.kcp) {
startShadowsocksUDPDaemon()
}
if (!profile.udpdns) { if (!profile.udpdns) {
startDnsDaemon() startDnsDaemon()
startDnsTunnel() startDnsTunnel()
} }
} }
def startKcptunDaemon() {
if (profile.kcpcli == null) profile.kcpcli = ""
val host = if (profile.host.contains(":")) {
"[" + profile.host + "]"
} else {
profile.host
}
val cmd = ArrayBuffer(getApplicationInfo.nativeLibraryDir + "/libkcptun.so"
, "-r", host + ":" + profile.kcpPort
, "-l", "127.0.0.1:" + (profile.localPort + 90)
, "--path", protectPath)
try cmd ++= Utils.translateCommandline(profile.kcpcli) catch {
case exc: Exception => throw KcpcliParseException(exc)
}
if (BuildConfig.DEBUG)
Log.d(TAG, cmd.mkString(" "))
kcptunProcess = new GuardedProcess(cmd).start()
}
def startShadowsocksUDPDaemon() {
val conf = ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort,
profile.password, profile.method, 600)
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-udp-vpn.conf"))(p => {
p.println(conf)
})
val cmd = ArrayBuffer[String](getApplicationInfo.nativeLibraryDir + "/libss-local.so", "-V", "-U"
, "-b", "127.0.0.1"
, "-t", "600"
, "-P", getApplicationInfo.dataDir
, "-c", getApplicationInfo.dataDir + "/ss-local-udp-vpn.conf")
if (profile.auth) cmd += "-A"
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
sstunnelProcess = new GuardedProcess(cmd).start()
}
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
val conf = if (profile.kcp) { val conf =
ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90, profile.localPort,
profile.password, profile.method, 600)
} else {
ConfigUtils ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort, .SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort,
profile.password, profile.method, 600) profile.password, profile.method, 600)
}
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-vpn.conf"))(p => { Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-local-vpn.conf"))(p => {
p.println(conf) p.println(conf)
}) })
...@@ -239,7 +178,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -239,7 +178,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (profile.auth) cmd += "-A" if (profile.auth) cmd += "-A"
if (profile.udpdns && !profile.kcp) cmd += "-u" if (profile.udpdns) cmd += "-u"
if (profile.route != Acl.ALL) { if (profile.route != Acl.ALL) {
cmd += "--acl" cmd += "--acl"
...@@ -254,15 +193,10 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -254,15 +193,10 @@ class ShadowsocksVpnService extends VpnService with BaseService {
} }
def startDnsTunnel() { def startDnsTunnel() {
val conf = if (profile.kcp) { val conf =
ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, "127.0.0.1", profile.localPort + 90, profile.localPort + 63,
profile.password, profile.method, 10)
} else {
ConfigUtils ConfigUtils
.SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + 63, .SHADOWSOCKS.formatLocal(Locale.ENGLISH, profile.host, profile.remotePort, profile.localPort + 63,
profile.password, profile.method, 10) profile.password, profile.method, 10)
}
Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-tunnel-vpn.conf"))(p => { Utils.printToFile(new File(getApplicationInfo.dataDir + "/ss-tunnel-vpn.conf"))(p => {
p.println(conf) p.println(conf)
}) })
......
...@@ -46,7 +46,7 @@ object DBHelper { ...@@ -46,7 +46,7 @@ object DBHelper {
} }
class DBHelper(val context: Context) class DBHelper(val context: Context)
extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 21) { extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 22) {
import DBHelper._ import DBHelper._
lazy val profileDao: Dao[Profile, Int] = getDao(classOf[Profile]) lazy val profileDao: Dao[Profile, Int] = getDao(classOf[Profile])
...@@ -115,24 +115,26 @@ class DBHelper(val context: Context) ...@@ -115,24 +115,26 @@ class DBHelper(val context: Context)
profileDao.executeRawNoArgs("UPDATE `profile` SET route = 'bypass-lan-china' WHERE route = 'bypass-china'") profileDao.executeRawNoArgs("UPDATE `profile` SET route = 'bypass-lan-china' WHERE route = 'bypass-china'")
} }
if (oldVersion < 17) {
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN kcp SMALLINT;")
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN kcpcli VARCHAR DEFAULT " +
"'--crypt none --mode normal --mtu 1200 --nocomp --dscp 46 --parityshard 0';")
} else if (oldVersion < 20) {
profileDao.executeRawNoArgs("UPDATE `profile` SET kcpcli = '--crypt none --mode normal --mtu 1200 --nocomp " +
"--dscp 46 --parityshard 0' WHERE kcpcli IS NULL;")
}
if (oldVersion < 18) {
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN kcpPort INTEGER DEFAULT 8399;")
} else if (oldVersion < 19) {
profileDao.executeRawNoArgs("UPDATE `profile` SET kcpPort = 8399 WHERE kcpPort = 0;")
}
if (oldVersion < 21) { if (oldVersion < 21) {
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';") profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';")
} }
if (oldVersion < 17) {
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN plugin VARCHAR;")
} else if (oldVersion < 22) {
// upgrade kcptun to SIP003 plugin
profileDao.executeRawNoArgs("BEGIN TRANSACTION;")
profileDao.executeRawNoArgs("ALTER TABLE `profile` RENAME TO `tmp`;")
TableUtils.createTable(connectionSource, classOf[Profile])
profileDao.executeRawNoArgs(
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route, proxyApps, bypass," +
" udpdns, auth, ipv6, individual, tx, rx, date, userOrder, plugin) " +
"SELECT id, name, host, localPort, CASE WHEN kcp = 1 THEN kcpPort ELSE remotePort END, password, method, " +
"route, proxyApps, bypass, udpdns, auth, ipv6, individual, tx, rx, date, userOrder, " +
"CASE WHEN kcp = 1 THEN 'kcptun ' || kcpcli ELSE NULL END FROM `tmp`;")
profileDao.executeRawNoArgs("DROP TABLE `tmp`;")
profileDao.executeRawNoArgs("COMMIT;")
}
} catch { } catch {
case ex: Exception => case ex: Exception =>
app.track(ex) app.track(ex)
......
...@@ -90,13 +90,7 @@ class Profile { ...@@ -90,13 +90,7 @@ class Profile {
var userOrder: Long = _ var userOrder: Long = _
@DatabaseField @DatabaseField
var kcp: Boolean = _ var plugin: String = _
@DatabaseField
var kcpPort: Int = 8399
@DatabaseField
var kcpcli: String = "--crypt none --mode normal --mtu 1200 --nocomp --dscp 46 --parityshard 0"
def formattedAddress: String = (if (host.contains(":")) "[%s]:%d" else "%s:%d").format(host, remotePort) def formattedAddress: String = (if (host.contains(":")) "[%s]:%d" else "%s:%d").format(host, remotePort)
def nameIsEmpty: Boolean = name == null || name.isEmpty def nameIsEmpty: Boolean = name == null || name.isEmpty
...@@ -123,9 +117,7 @@ class Profile { ...@@ -123,9 +117,7 @@ class Profile {
.putBoolean(Key.auth, auth) .putBoolean(Key.auth, auth)
.putBoolean(Key.ipv6, ipv6) .putBoolean(Key.ipv6, ipv6)
.putString(Key.individual, individual) .putString(Key.individual, individual)
.putBoolean(Key.kcp, kcp) .putString(Key.plugin, plugin)
.putInt(Key.kcpPort, kcpPort)
.putString(Key.kcpcli, kcpcli)
.remove(Key.dirty) .remove(Key.dirty)
def deserialize(pref: SharedPreferences) { def deserialize(pref: SharedPreferences) {
// It's assumed that default values are never used, so 0/false/null is always used even if that isn't the case // It's assumed that default values are never used, so 0/false/null is always used even if that isn't the case
...@@ -143,8 +135,6 @@ class Profile { ...@@ -143,8 +135,6 @@ class Profile {
auth = pref.getBoolean(Key.auth, false) auth = pref.getBoolean(Key.auth, false)
ipv6 = pref.getBoolean(Key.ipv6, false) ipv6 = pref.getBoolean(Key.ipv6, false)
individual = pref.getString(Key.individual, null) individual = pref.getString(Key.individual, null)
kcp = pref.getBoolean(Key.kcp, false) plugin = pref.getString(Key.plugin, null)
kcpPort = pref.getInt(Key.kcpPort, 0)
kcpcli = pref.getString(Key.kcpcli, null)
} }
} }
/*******************************************************************************/
/* */
/* 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.preferences
import android.app.AlertDialog
import android.content.DialogInterface
import eu.chainfire.libsuperuser.Shell
import be.mygod.preference.EditTextPreferenceDialogFragment
import scala.collection.JavaConverters._
/**
* @author Mygod
*/
class KcpCliPreferenceDialogFragment extends EditTextPreferenceDialogFragment {
override def onPrepareDialogBuilder(builder: AlertDialog.Builder) {
super.onPrepareDialogBuilder(builder)
builder.setNeutralButton("?", ((_, _) => new AlertDialog.Builder(builder.getContext)
.setTitle("?")
.setMessage(Shell.SH.run(builder.getContext.getApplicationInfo.nativeLibraryDir + "/libkcptun.so --help")
.asScala
.dropWhile(line => line != "GLOBAL OPTIONS:")
.drop(1)
.takeWhile(line => line.length() > 3)
.filter(line =>
!line.startsWith(" --localaddr ") &&
!line.startsWith(" --remoteaddr ") &&
!line.startsWith(" --path ") &&
!line.startsWith(" --help,") &&
!line.startsWith(" --version,"))
.mkString("\n")
.replaceAll(" {2,}", "\n")
.substring(1)) // remove 1st \n
.show()): DialogInterface.OnClickListener)
}
}
...@@ -26,9 +26,8 @@ object Executable { ...@@ -26,9 +26,8 @@ object Executable {
val SS_LOCAL = "ss-local" val SS_LOCAL = "ss-local"
val SS_TUNNEL = "ss-tunnel" val SS_TUNNEL = "ss-tunnel"
val TUN2SOCKS = "tun2socks" val TUN2SOCKS = "tun2socks"
val KCPTUN = "kcptun"
val EXECUTABLES = Array(SS_LOCAL, SS_TUNNEL, PDNSD, REDSOCKS, TUN2SOCKS, KCPTUN) val EXECUTABLES = Array(SS_LOCAL, SS_TUNNEL, PDNSD, REDSOCKS, TUN2SOCKS)
} }
object ConfigUtils { object ConfigUtils {
...@@ -153,9 +152,7 @@ object Key { ...@@ -153,9 +152,7 @@ object Key {
val localPort = "localPortNum" val localPort = "localPortNum"
val remoteDns = "remoteDns" val remoteDns = "remoteDns"
val kcp = "kcp" val plugin = "plugin"
val kcpPort = "kcpPort"
val kcpcli = "kcpcli"
val dirty = "profileDirty" val dirty = "profileDirty"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment