Skip to content

Commit

Permalink
disable pdnsd log.
Browse files Browse the repository at this point in the history
  • Loading branch information
KagayamaKaede committed Nov 22, 2015
1 parent cad2c4e commit 683ec38
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 162 deletions.
7 changes: 7 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
##1.1.2 Beta

+ Improve network operate speed.
+ Reduce RAM usage.
+ Add NAT mode, but can not use yet.
+ ```May be contains many bug```.

##1.1.1 Test

+ Improve crypt operating speed.
Expand Down
1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/release" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ apply plugin: 'com.google.osdetector'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.2"

//noinspection GroovyAssignabilityCheck
defaultConfig {
applicationId "com.proxy.shadowsocksr"
minSdkVersion 14
targetSdkVersion 23
versionCode 12
versionName "1.1.1 Test"
versionCode 13
versionName "1.1.2 Beta"
}
//noinspection GroovyAssignabilityCheck
buildTypes {
Expand Down
Binary file modified app/libs/armeabi-v7a/pdnsd
Binary file not shown.
Binary file modified app/libs/x86/pdnsd
Binary file not shown.
Binary file modified app/src/main/assets/armeabi-v7a/pdnsd
Binary file not shown.
Binary file modified app/src/main/assets/x86/pdnsd
Binary file not shown.
156 changes: 48 additions & 108 deletions app/src/main/java/com/proxy/shadowsocksr/SSRNatService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,18 @@ class SSRNatService : Service()
val myUid = android.os.Process.myUid()

var redsocksPID: Int = 0
var redsocksProcess: Process? = null
var pdnsdProcess: Process? = null
var pdnsdPID: Int = 0

private val dnsAddressCache = SparseArray<String>()

override fun onBind(intent: Intent?): IBinder?
{
return binder
}
override fun onBind(intent: Intent?): IBinder? = binder

internal inner class SSRService : ISSRService.Stub()
{
@Throws(RemoteException::class)
override fun status(): Boolean
{
return isNATConnected
}
override fun status(): Boolean = isNATConnected

@Throws(RemoteException::class)
override fun registerISSRServiceCallBack(cb: ISSRServiceCallback)
Expand Down Expand Up @@ -120,17 +116,16 @@ class SSRNatService : Service()
{
if (!f.canRead() || !f.canExecute())
{
ShellUtil().runCmd("chmod 755 " + f.absolutePath)
ShellUtil().runCmd("chmod 755 ${f.absolutePath}")
}
}
else
{
if (copyDaemonBin(fn, f))
if (!copyDaemonBin(fn, f))
{
ShellUtil().runCmd("chmod 755 " + f.absolutePath)
return true
return false
}
return false
ShellUtil().runCmd("chmod 755 ${f.absolutePath}")
}
}
return true
Expand All @@ -143,84 +138,28 @@ class SSRNatService : Service()
1024 * 32)//most tf card have 16k or 32k logic unit size, may be 32k buffer is better
try
{
if (!out.createNewFile())
{
return false
}
val fis = assets.open(abi + File.separator + file)
val fos = FileOutputStream(out)
var length: Int = fis.read(buf)
while (length > 0)
if (out.createNewFile())
{
fos.write(buf, 0, length)
length = fis.read(buf)
val fis = assets.open(abi + File.separator + file)
val fos = FileOutputStream(out)
var length: Int = fis.read(buf)
while (length > 0)
{
fos.write(buf, 0, length)
length = fis.read(buf)
}
fos.flush()
fos.close()
fis.close()
return true
}
fos.flush()
fos.close()
fis.close()
return true
}
catch (ignored: IOException)
{
}
return false
}

// private fun getNetId(network: Network): Int = network.javaClass
// .getDeclaredField("netId").get(network) as Int
//
// private fun restoreDnsForAllNetwork()
// {
// val manager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
// val networks = manager.allNetworks ?: return
//
// val cmdBuf: MutableList<String> = arrayListOf()
// networks.forEach { network ->
// val netId = getNetId(network)
// val oldDns = dnsAddressCache.get(netId)
// if (oldDns != null)
// {
// cmdBuf.add("ndc resolver setnetdns $netId \"\" $oldDns")
// dnsAddressCache.remove(netId)
// }
// }
// if (cmdBuf.isNotEmpty())
// {
// ShellUtil().runRootCmd(cmdBuf.toTypedArray())
// }
// }
//
// private fun setDnsForAllNetwork(dns: String)
// {
// val manager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
// val networks = manager.allNetworks ?: return
//
// val cmdBuf: MutableList<String> = arrayListOf()
// networks.forEach({ network ->
// val networkInfo = manager.getNetworkInfo(network)
// networkInfo ?: return
// if (networkInfo.isConnected)
// {
// val netId = getNetId(network)
// val curDnsList = manager.getLinkProperties(network).dnsServers
// if (curDnsList != null)
// {
// val curDns = curDnsList.map({ ip -> ip.hostAddress })
// .joinToString(separator = " ")
// if (curDns != dns)
// {
// dnsAddressCache.put(netId, curDns)
// cmdBuf.add("ndc resolver setnetdns $netId \"\" $dns")
// }
// }
// }
// })
// if (cmdBuf.isNotEmpty())
// {
// ShellUtil().runRootCmd(cmdBuf.toTypedArray())
// }
// }

private fun flushDns()
{
if (CommonUtils.isLollipopOrAbove())
Expand Down Expand Up @@ -252,7 +191,7 @@ class SSRNatService : Service()
{
when (connProfile!!.route)
{
"bypass-lan" -> aclList = Arrays.asList(
"bypass-lan" -> aclList = Arrays.asList(
*resources.getStringArray(R.array.private_route))
"bypass-lan-and-list" -> aclList = Arrays.asList(
*resources.getStringArray(R.array.chn_route_full))
Expand All @@ -262,7 +201,7 @@ class SSRNatService : Service()
local = SSRLocal("127.0.0.1", connProfile!!.server, connProfile!!.remotePort,
connProfile!!.localPort, connProfile!!.passwd, connProfile!!.cryptMethod,
connProfile!!.tcpProtocol, connProfile!!.obfsMethod, connProfile!!.obfsParam,
false, aclList)
aclList)

local!!.start()
}
Expand All @@ -272,8 +211,7 @@ class SSRNatService : Service()
if (connProfile!!.dnsForward)
{
udprs = UDPRelayServer(connProfile!!.server, "127.0.0.1", connProfile!!.remotePort,
8153, true, false, connProfile!!.cryptMethod, connProfile!!.passwd, "8.8.8.8",
53)
8153, true, connProfile!!.cryptMethod, connProfile!!.passwd, "8.8.8.8", 53)
}
else
{
Expand All @@ -300,20 +238,23 @@ class SSRNatService : Service()
pdnsd = ConfFileUtil.PdNSdLocal.format("0.0.0.0", 8153, 8163, "")
}

ConfFileUtil.writeToFile(pdnsd, File(Consts.baseDir + "pdnsd-vpn.conf"))
ConfFileUtil.writeToFile(pdnsd, File(Consts.baseDir + "pdnsd-nat.conf"))

val cmd = Consts.baseDir + "pdnsd -c " + Consts.baseDir + "pdnsd-vpn.conf"
val cmd = Consts.baseDir + "pdnsd -c " + Consts.baseDir + "pdnsd-nat.conf"

pdnsdPID = Jni.exec(cmd)
pdnsdProcess = ProcessBuilder().command(cmd.split(" ").toList()).redirectErrorStream(
true).start()
//pdnsdPID = Jni.exec(cmd)
}

private fun startRedsocksDaemon()
{
val conf = ConfFileUtil.RedSocks.format(connProfile!!.localPort)
val cmd = "${Consts.baseDir}redsocks -c ${Consts.baseDir}redsocks-nat.conf"
ConfFileUtil.writeToFile(conf, File("${Consts.baseDir}redsocks-nat.conf"))
Log.e("EXC", cmd)
redsocksPID = Jni.exec(cmd)
redsocksProcess = ProcessBuilder()
.command(cmd.split(" ").toList())
.redirectErrorStream(true).start()
}

private fun killProcesses()
Expand All @@ -333,21 +274,16 @@ class SSRNatService : Service()
udprs!!.stopUDPRelayServer()
udprs = null
}
try
if (pdnsdProcess != null)
{
android.os.Process.killProcess(pdnsdPID)
pdnsdProcess!!.destroy()
pdnsdProcess = null
}
catch(ignored: Exception)
if (redsocksProcess != null)
{
redsocksProcess!!.destroy()
redsocksProcess = null
}
try
{
android.os.Process.killProcess(redsocksPID)
}
catch(ignored: Exception)
{
}

ShellUtil().runRootCmd("${CommonUtils.iptables} -t nat -F OUTPUT")
}

Expand Down Expand Up @@ -376,14 +312,11 @@ class SSRNatService : Service()
else
{
val pm = packageManager
val uidSet: MutableSet<Int> = hashSetOf()
connProfile!!.proxyApps.forEach({ app ->
try
{
val ai = pm.getApplicationInfo(app, PackageManager.GET_ACTIVITIES)
Log.e("EXC", "${ai.uid}")
uidSet.add(ai.uid)
http_sb.add((CommonUtils.iptables + CMD_IPTABLES_DNAT_ADD_SOCKS)
http_sb.add(("${CommonUtils.iptables}$CMD_IPTABLES_DNAT_ADD_SOCKS")
.replace("-t nat", "-t nat -m owner --uid-owner ${ai.uid}"))
}
catch(ignored: Exception)
Expand All @@ -392,6 +325,13 @@ class SSRNatService : Service()
})
}
//
init_sb.forEach {
Log.e("EXC", it)
}
http_sb.forEach {
Log.e("EXC", it)
}
//
ShellUtil().runRootCmd(init_sb.toTypedArray())
ShellUtil().runRootCmd(http_sb.toTypedArray())
}
Expand Down Expand Up @@ -424,13 +364,13 @@ class SSRNatService : Service()
connProfile!!.server = ip
}
//
startSSRLocal()
startTunnel()
if (!connProfile!!.dnsForward)
{
startDnsDaemon()
}
startRedsocksDaemon()
startSSRLocal()
setupIptables()
//
flushDns()
Expand All @@ -439,7 +379,7 @@ class SSRNatService : Service()
Intent(this@SSRNatService, MainActivity::class.java), 0)
val notificationBuilder = NotificationCompat.Builder(this@SSRNatService)
notificationBuilder
.setWhen(0)
.setWhen(0)//may be can set Long.MAX to shield notification icon display.
.setColor(ContextCompat.getColor(this@SSRNatService,
R.color.material_accent_500))
.setTicker("Nat service started")
Expand Down
Loading

0 comments on commit 683ec38

Please sign in to comment.