Compare commits

...
13 Commits
Author SHA1 Message Date
Max Lv c31a5c1951 use abstract namespace 2015-08-04 09:23:36 +08:00
Max Lv 6c47c361f7 update reject list 2015-08-03 14:00:59 +08:00
Max Lv ddd37a3219 update dns 2015-08-03 13:03:30 +08:00
Max Lv 01125d53b3 update shadowsocks-libev 2015-08-03 11:02:40 +08:00
Max Lv 9613d65303 fix a issue of progress dialog 2015-08-02 08:22:20 +08:00
Max Lv a510b11187 update shadowsocks-libev 2015-07-31 16:40:33 +08:00
Max Lv 051e600e59 bump version 2015-07-31 16:30:54 +08:00
Max Lv fea9a6f919 refine the binary update 2015-07-31 16:05:03 +08:00
Max Lv c2c7cabbaf refine dns resolve 2015-07-30 13:35:04 +08:00
Max Lv 092d880c7d refine binary install 2015-07-29 13:49:08 +08:00
Max Lv c208c4bf50 refine profile initilizing 2015-07-28 15:49:05 +08:00
Max Lv 34af6aeef5 refine the IPC to tun2socks 2015-07-28 14:48:21 +08:00
Max Lv d9af2f93e0 fix plugin 2015-07-27 11:09:52 +08:00
12 changed files with 119 additions and 79 deletions
+14 -12
View File
@@ -10,20 +10,22 @@ import IPy
def main(): def main():
china_list_set = IPy.IPSet() china_list_set = IPy.IPSet()
for line in sys.stdin: # for line in sys.stdin:
line_params = line.split("|") # line_params = line.split("|")
if len(line_params) < 5 or line_params[2] != "ipv4" or line_params[1] != "CN": # if len(line_params) < 5 or line_params[2] != "ipv4" or line_params[1] != "CN":
continue # continue
ip_addr = line_params[3] # ip_addr = line_params[3]
ip_length = float(line_params[4]) # ip_length = float(line_params[4])
ip_mask = 32 - int(math.ceil(math.log(ip_length, 2))) # ip_mask = 32 - int(math.ceil(math.log(ip_length, 2)))
china_list_set.add(IPy.IP("%s/%d" % (ip_addr, ip_mask))) # china_list_set.add(IPy.IP("%s/%d" % (ip_addr, ip_mask)))
# 添加内网地址 # 添加内网地址
internal_list = IPy.IPSet(map(IPy.IP, [ internal_list = IPy.IPSet(map(IPy.IP, [
"0.0.0.0/8", "0.0.0.0/8",
"10.0.0.0/8", "10.0.0.0/8",
"100.64.0.0/10", "100.64.0.0/10",
"112.124.47.0/24",
"114.114.114.0/24",
"127.0.0.0/8", "127.0.0.0/8",
"169.254.0.0/16", "169.254.0.0/16",
"172.16.0.0/12", "172.16.0.0/12",
@@ -45,10 +47,10 @@ def main():
for ip in china_list_set: for ip in china_list_set:
all.discard(ip) all.discard(ip)
filter = itertools.ifilter(lambda x: len(x) <= 65536, all) # filter = itertools.ifilter(lambda x: len(x) <= 65536, all)
for ip in filter: # for ip in filter:
all.discard(ip) # all.discard(ip)
all.add(IPy.IP(ip.strNormal(0)).make_net('255.255.0.0')) # all.add(IPy.IP(ip.strNormal(0)).make_net('255.255.0.0'))
# 输出结果 # 输出结果
for ip in all: for ip in all:
+3 -3
View File
@@ -1,7 +1,7 @@
resolvers += Resolver.url("scalasbt releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns) resolvers += Resolver.url("scalasbt releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots"))(Resolver.ivyStylePatterns)
addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.4.6") addSbtPlugin("com.hanhuy.sbt" % "android-sdk-plugin" % "1.4.8")
resolvers += Resolver.sbtPluginRepo("snapshots") resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.hanhuy.sbt" % "sbt-idea" % "1.7.0-SNAPSHOT") addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.7.0-SNAPSHOT")
+2 -2
View File
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.shadowsocks" package="com.github.shadowsocks"
android:versionCode="110" android:versionCode="113"
android:versionName="2.7.2"> android:versionName="2.7.5">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+2 -2
View File
@@ -502,11 +502,11 @@ int main (int argc, char **argv)
goto fail2; goto fail2;
} }
char *path = "/data/data/com.github.shadowsocks/sock_path"; char *path = "#shadowsocks_tunfd";
unlink(path);
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1); strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1);
addr.sun_path[0] = 0;
if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) { if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
BLog(BLOG_ERROR, "bind() failed: %s (sock = %d)\n", strerror(errno), sock); BLog(BLOG_ERROR, "bind() failed: %s (sock = %d)\n", strerror(errno), sock);
+2 -1
View File
@@ -58,7 +58,8 @@ jint Java_com_github_shadowsocks_system_sendfd(JNIEnv *env, jobject thiz, jint t
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, "/data/data/com.github.shadowsocks/sock_path", sizeof(addr.sun_path)-1); strncpy(addr.sun_path, "#shadowsocks_tunfd", sizeof(addr.sun_path)-1);
addr.sun_path[0] = 0;
if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
LOGE("connect() failed: %s (fd = %d)\n", strerror(errno), fd); LOGE("connect() failed: %s (fd = %d)\n", strerror(errno), fd);
+35 -1
View File
@@ -85,7 +85,41 @@
<item>101.0.0.0/8</item> <item>101.0.0.0/8</item>
<item>102.0.0.0/7</item> <item>102.0.0.0/7</item>
<item>104.0.0.0/5</item> <item>104.0.0.0/5</item>
<item>112.0.0.0/5</item> <item>112.0.0.0/10</item>
<item>112.64.0.0/11</item>
<item>112.96.0.0/12</item>
<item>112.112.0.0/13</item>
<item>112.120.0.0/14</item>
<item>112.124.0.0/19</item>
<item>112.124.32.0/21</item>
<item>112.124.40.0/22</item>
<item>112.124.44.0/23</item>
<item>112.124.46.0/24</item>
<item>112.124.48.0/20</item>
<item>112.124.64.0/18</item>
<item>112.124.128.0/17</item>
<item>112.125.0.0/16</item>
<item>112.126.0.0/15</item>
<item>112.128.0.0/9</item>
<item>113.0.0.0/8</item>
<item>114.0.0.0/10</item>
<item>114.64.0.0/11</item>
<item>114.96.0.0/12</item>
<item>114.112.0.0/15</item>
<item>114.114.0.0/18</item>
<item>114.114.64.0/19</item>
<item>114.114.96.0/20</item>
<item>114.114.112.0/23</item>
<item>114.114.115.0/24</item>
<item>114.114.116.0/22</item>
<item>114.114.120.0/21</item>
<item>114.114.128.0/17</item>
<item>114.115.0.0/16</item>
<item>114.116.0.0/14</item>
<item>114.120.0.0/13</item>
<item>114.128.0.0/9</item>
<item>115.0.0.0/8</item>
<item>116.0.0.0/6</item>
<item>120.0.0.0/6</item> <item>120.0.0.0/6</item>
<item>124.0.0.0/7</item> <item>124.0.0.0/7</item>
<item>126.0.0.0/8</item> <item>126.0.0.0/8</item>
File diff suppressed because one or more lines are too long
@@ -185,6 +185,7 @@ class Shadowsocks
// Variables // Variables
var switchButton: Switch = null var switchButton: Switch = null
var progressDialog: ProgressDialog = null var progressDialog: ProgressDialog = null
var progressTag = -1
var state = State.INIT var state = State.INIT
var prepared = false var prepared = false
var currentProfile = new Profile var currentProfile = new Profile
@@ -271,9 +272,10 @@ class Shadowsocks
switchButton.setOnCheckedChangeListener(this) switchButton.setOnCheckedChangeListener(this)
} }
private def showProgress(msg: String): Handler = { private def showProgress(msg: Int): Handler = {
clearDialog() clearDialog()
progressDialog = ProgressDialog.show(this, "", msg, true, false) progressDialog = ProgressDialog.show(this, "", getString(msg), true, false)
progressTag = msg
new Handler { new Handler {
override def handleMessage(msg: Message) { override def handleMessage(msg: Message) {
clearDialog() clearDialog()
@@ -397,8 +399,13 @@ class Shadowsocks
} }
def prepareStartService() { def prepareStartService() {
showProgress(getString(R.string.connecting)) showProgress(R.string.connecting)
spawn { spawn {
if (!status.getBoolean(getVersionName, false)) {
status.edit.putBoolean(getVersionName, true).commit()
install()
}
if (isVpnEnabled) { if (isVpnEnabled) {
val intent = VpnService.prepare(this) val intent = VpnService.prepare(this)
if (intent != null) { if (intent != null) {
@@ -474,22 +481,16 @@ class Shadowsocks
addPreferencesFromResource(R.xml.pref_all) addPreferencesFromResource(R.xml.pref_all)
// Update the profile
if (!status.getBoolean(getVersionName, false)) {
currentProfile = profileManager.create()
}
// Initialize the profile // Initialize the profile
currentProfile = { currentProfile = {
profileManager.getProfile(settings.getInt(Key.profileId, -1)) getOrElse currentProfile profileManager.getProfile(settings.getInt(Key.profileId, -1)) getOrElse currentProfile
} }
// Update the profile
if (!status.getBoolean(getVersionName, false)) {
val h = showProgress(getString(R.string.initializing))
status.edit.putBoolean(getVersionName, true).apply()
spawn {
reset()
currentProfile = profileManager.create()
h.sendEmptyMessage(0)
}
}
// Initialize drawer // Initialize drawer
menuAdapter.setActiveId(settings.getInt(Key.profileId, -1)) menuAdapter.setActiveId(settings.getInt(Key.profileId, -1))
menuAdapter.setListener(this) menuAdapter.setListener(this)
@@ -617,7 +618,7 @@ class Shadowsocks
which match { which match {
case 0 => case 0 =>
dialog.dismiss() dialog.dismiss()
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
h.postDelayed(new Runnable() { h.postDelayed(new Runnable() {
def run() { def run() {
val integrator = new IntentIntegrator(Shadowsocks.this) val integrator = new IntentIntegrator(Shadowsocks.this)
@@ -641,7 +642,7 @@ class Shadowsocks
def reloadProfile() { def reloadProfile() {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
@@ -660,7 +661,7 @@ class Shadowsocks
def addProfile(profile: Profile) { def addProfile(profile: Profile) {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
@@ -679,7 +680,7 @@ class Shadowsocks
def addProfile(id: Int) { def addProfile(id: Int) {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
@@ -697,7 +698,7 @@ class Shadowsocks
def updateProfile(id: Int) { def updateProfile(id: Int) {
drawer.closeMenu(true) drawer.closeMenu(true)
val h = showProgress(getString(R.string.loading)) val h = showProgress(R.string.loading)
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
@@ -916,10 +917,7 @@ class Shadowsocks
Console.runRootCommand(ab.toArray) Console.runRootCommand(ab.toArray)
} }
def reset() { def install() {
crashRecovery()
copyAssets(System.getABI) copyAssets(System.getABI)
val ab = new ArrayBuffer[String] val ab = new ArrayBuffer[String]
@@ -927,19 +925,21 @@ class Shadowsocks
ab.append("chmod 755 " + Path.BASE + executable) ab.append("chmod 755 " + Path.BASE + executable)
} }
Console.runCommand(ab.toArray) Console.runCommand(ab.toArray)
}
def reset() {
crashRecovery()
install()
} }
private def recovery() { private def recovery() {
val h = showProgress(getString(R.string.recovering)) serviceStop()
val h = showProgress(R.string.recovering)
spawn { spawn {
reset() reset()
handler.post(new Runnable { h.sendEmptyMessage(0)
override def run() {
serviceStop
h.sendEmptyMessage(0)
}
})
} }
} }
@@ -969,7 +969,7 @@ class Shadowsocks
} }
private def flushDnsCache() { private def flushDnsCache() {
val h = showProgress(getString(R.string.flushing)) val h = showProgress(R.string.flushing)
spawn { spawn {
Utils.toggleAirplaneMode(getBaseContext) Utils.toggleAirplaneMode(getBaseContext)
h.sendEmptyMessage(0) h.sendEmptyMessage(0)
@@ -1087,6 +1087,7 @@ class Shadowsocks
if (progressDialog != null) { if (progressDialog != null) {
progressDialog.dismiss() progressDialog.dismiss()
progressDialog = null progressDialog = null
progressTag = -1
} }
} }
@@ -1100,14 +1101,19 @@ class Shadowsocks
if (progressDialog == null) { if (progressDialog == null) {
progressDialog = ProgressDialog progressDialog = ProgressDialog
.show(Shadowsocks.this, "", getString(R.string.connecting), true, true) .show(Shadowsocks.this, "", getString(R.string.connecting), true, true)
progressTag = R.string.connecting
} }
setPreferenceEnabled(enabled = false) setPreferenceEnabled(enabled = false)
case State.CONNECTED => case State.CONNECTED =>
clearDialog() if (progressTag == R.string.connecting) {
clearDialog()
}
changeSwitch(checked = true) changeSwitch(checked = true)
setPreferenceEnabled(enabled = false) setPreferenceEnabled(enabled = false)
case State.STOPPED => case State.STOPPED =>
clearDialog() if (progressTag == R.string.stopping) {
clearDialog()
}
changeSwitch(checked = false) changeSwitch(checked = false)
if (m != null) { if (m != null) {
new SnackBar.Builder(Shadowsocks.this) new SnackBar.Builder(Shadowsocks.this)
@@ -1122,6 +1128,7 @@ class Shadowsocks
if (progressDialog == null) { if (progressDialog == null) {
progressDialog = ProgressDialog progressDialog = ProgressDialog
.show(Shadowsocks.this, "", getString(R.string.stopping), true, true) .show(Shadowsocks.this, "", getString(R.string.stopping), true, true)
progressTag = R.string.stopping
} }
} }
} }
@@ -63,7 +63,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication] private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]
val TAG = "ShadowsocksVpnService" val TAG = "ShadowsocksVpnService"
val VPN_MTU = 1500 val VPN_MTU = 1400
val PRIVATE_VLAN = "26.26.26.%s" val PRIVATE_VLAN = "26.26.26.%s"
var conn: ParcelFileDescriptor = null var conn: ParcelFileDescriptor = null
var notificationManager: NotificationManager = null var notificationManager: NotificationManager = null
@@ -266,17 +266,18 @@ class ShadowsocksVpnService extends VpnService with BaseService {
} }
val fd = startVpn() val fd = startVpn()
if (fd == -1) {
false if (fd != -1) {
} else { var tries = 1
Thread.sleep(1000) while (tries < 5) {
if (System.sendfd(fd) == -1) { Thread.sleep(1000 * tries)
false if (System.sendfd(fd) != -1) {
} else { return true
true }
tries += 1
} }
} }
false
} }
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
@@ -48,7 +48,7 @@ import android.util.Log
class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread { class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
val TAG = "ShadowsocksVpnService" val TAG = "ShadowsocksVpnService"
val PATH = "/data/data/com.github.shadowsocks/protect_path" val PATH = "shadowsocks_protect"
var isRunning: Boolean = true var isRunning: Boolean = true
var serverSocket: LocalServerSocket = null var serverSocket: LocalServerSocket = null
@@ -64,16 +64,11 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {
override def run(): Unit = { override def run(): Unit = {
try { try {
new File(PATH).delete() if (serverSocket != null) {
} catch { serverSocket.close()
case _: Exception => // ignore serverSocket = null
} }
serverSocket = new LocalServerSocket(PATH)
try {
val localSocket = new LocalSocket
localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM))
serverSocket = new LocalServerSocket(localSocket.getFileDescriptor)
} catch { } catch {
case e: IOException => case e: IOException =>
Log.e(TAG, "unable to bind", e) Log.e(TAG, "unable to bind", e)
@@ -159,8 +159,8 @@ object ConfigUtils {
| |
|server { |server {
| label = "china-servers"; | label = "china-servers";
| ip = 223.5.5.5, 114.114.114.114; | ip = 114.114.114.114, 112.124.47.27;
| timeout = 2; | timeout = 4;
| reject = %s; | reject = %s;
| reject_policy = fail; | reject_policy = fail;
| reject_recursively = on; | reject_recursively = on;