Skip to content

Commit

Permalink
Merge pull request #4 from shadowsocks/master
Browse files Browse the repository at this point in the history
Sync
  • Loading branch information
initrider authored Apr 5, 2018
2 parents 74dad98 + 0f9ca2c commit a95c86a
Show file tree
Hide file tree
Showing 57 changed files with 13,003 additions and 3,477 deletions.
1 change: 1 addition & 0 deletions .github/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The exclamation mark in the Wi-Fi/cellular icon appears because the system fails
* Fixes for Huawei: [#1091 (comment)](https://github.com/shadowsocks/shadowsocks-android/issues/1091#issuecomment-276949836)
* Related to Xposed: [#1414](https://github.com/shadowsocks/shadowsocks-android/issues/1414)
* Samsung and/or Brevent: [#1410](https://github.com/shadowsocks/shadowsocks-android/issues/1410)
* Another Samsung: [#1712](https://github.com/shadowsocks/shadowsocks-android/issues/1712)
* Don't install this app on SD card because of permission issues: [#1124 (comment)](https://github.com/shadowsocks/shadowsocks-android/issues/1124#issuecomment-307556453)

### How to pause Shadowsocks service?
Expand Down
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Please check the [FAQ](https://github.com/shadowsocks/shadowsocks-android/wiki/FAQ) before submitting new issues.
Please check [FAQ](.github/faq.md) before submitting new issues.

And just in case you don't know,
[don't ask questions on issues](https://medium.com/@methane/why-you-must-not-ask-questions-on-github-issues-51d741d83fde).
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ A [shadowsocks](http://shadowsocks.org) client for Android, written in Kotlin.

### BUILD

You can check whether the latest commit builds under UNIX environment by checking Travis status.
Building on Windows is also possible since [#1570](https://github.com/shadowsocks/shadowsocks-android/pull/1570),
but probably painful. Further contributions regarding building on Windows are also welcome.

* Set environment variable `ANDROID_HOME` to `/path/to/android-sdk`
* (optional) Set environment variable `ANDROID_NDK_HOME` to `/path/to/android-ndk` (default: `$ANDROID_HOME/ndk-bundle`)
* Set environment variable `GOROOT_BOOTSTRAP` to `/path/to/go`
* Fetch submodules using `$ git submodule update --init --recursive`
* Clone the repo using `git clone --recurse-submodules <repo>` or update submodules using `git submodule update --init --recursive`
* Build it using Android Studio or gradle script

### TRANSLATE
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ apply plugin: 'com.github.ben-manes.versions'

buildscript {
ext {
kotlinVersion = '1.2.30'
kotlinVersion = '1.2.31'
minSdkVersion = 21
sdkVersion = 27
buildToolsVersion = '27.0.3'
supportLibraryVersion = '27.1.0'
takisoftFixVersion = '27.1.0.0'
playServicesVersion = '11.8.0'
playServicesVersion = '12.0.1'
junitVersion = '4.12'
androidTestVersion = '1.0.1'
androidEspressoVersion = '3.0.1'
Expand All @@ -22,9 +22,9 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath 'com.google.gms:google-services:3.2.0'
classpath 'com.google.gms:google-services:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
task goBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
executable "cmd.exe"
args "/c", "src\\overture\\make.bat " + minSdkVersion
args "/c", file("src/overture/make.bat").absolutePath , minSdkVersion
} else {
executable "sh"
args "-c", "src/overture/make.bash " + minSdkVersion
Expand All @@ -48,7 +48,7 @@ task goBuild(type: Exec) {
task goClean(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
executable "cmd.exe"
args "/c", "src\\overture\\clean.bat"
args "/c", file("src/overture/clean.bat").absolutePath
} else {
executable "sh"
args "-c", "src/overture/clean.bash"
Expand Down
121 changes: 121 additions & 0 deletions core/gfwlist/parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import pkgutil
import urlparse
import socket
import logging
from argparse import ArgumentParser
from datetime import date

__all__ = ['main']


def parse_args():
parser = ArgumentParser()
parser.add_argument('-i', '--input', dest='input', required=True,
help='path to gfwlist', metavar='GFWLIST')
parser.add_argument('-f', '--file', dest='output', required=True,
help='path to output acl', metavar='ACL')
return parser.parse_args()


def decode_gfwlist(content):
# decode base64 if have to
try:
return content.decode('base64')
except:
return content


def get_hostname(something):
try:
# quite enough for GFW
if not something.startswith('http:'):
something = 'http://' + something
r = urlparse.urlparse(something)
return r.hostname
except Exception as e:
logging.error(e)
return None


def add_domain_to_set(s, something):
hostname = get_hostname(something)
if hostname is not None:
if hostname.startswith('.'):
hostname = hostname.lstrip('.')
if hostname.endswith('/'):
hostname = hostname.rstrip('/')
if hostname:
s.add(hostname)


def parse_gfwlist(content):
gfwlist = content.splitlines(False)
domains = set()
for line in gfwlist:
if line.find('.*') >= 0:
continue
elif line.find('*') >= 0:
line = line.replace('*', '/')
if line.startswith('!'):
continue
elif line.startswith('['):
continue
elif line.startswith('@'):
# ignore white list
continue
elif line.startswith('||'):
add_domain_to_set(domains, line.lstrip('||'))
elif line.startswith('|'):
add_domain_to_set(domains, line.lstrip('|'))
elif line.startswith('.'):
add_domain_to_set(domains, line.lstrip('.'))
else:
add_domain_to_set(domains, line)
# TODO: reduce ['www.google.com', 'google.com'] to ['google.com']
return domains


def generate_acl(domains):
header ="""#
# GFW list from https://github.com/gfwlist/gfwlist/blob/master/gfwlist.txt
# updated on DATE
#
[bypass_all]
[proxy_list]
"""
header = header.replace('DATE', str(date.today()))
proxy_content = ""
ip_content = ""

for domain in sorted(domains):
try:
socket.inet_aton(domain)
ip_content += (domain + "\n")
except socket.error:
domain = domain.replace('.', '\.')
proxy_content += ('(^|\.)' + domain + '$\n')

proxy_content = header + ip_content + proxy_content

return proxy_content


def main():
args = parse_args()
with open(args.input, 'rb') as f:
content = f.read()
content = decode_gfwlist(content)
domains = parse_gfwlist(content)
acl_content = generate_acl(domains)
with open(args.output, 'wb') as f:
f.write(acl_content)

if __name__ == '__main__':
main()

22 changes: 18 additions & 4 deletions core/src/overture/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,35 @@ MKDIR %TARGET%\armeabi-v7a>nul 2>nul
MKDIR %TARGET%\x86>nul 2>nul
MKDIR %TARGET%\arm64-v8a>nul 2>nul

SET CC=%ANDROID_ARM_TOOLCHAIN%\bin\arm-linux-androideabi-gcc.exe

REM Check environment availability
IF NOT EXIST %CC% (
ECHO "gcc not found"
EXIT 1
)

WHERE python.exe
IF "%ERRORLEVEL%" == 1 (
ECHO "python not found"
EXIT 1
)

IF NOT EXIST %ANDROID_ARM_CC% (
ECHO "Make standalone toolchain for ARM arch"
%ANDROID_NDK_HOME%\build\tools\make_standalone_toolchain.py --arch arm ^
python.exe %ANDROID_NDK_HOME%\build\tools\make_standalone_toolchain.py --arch arm ^
--api %MIN_API% --install-dir %ANDROID_ARM_TOOLCHAIN%
)

IF NOT EXIST %ANDROID_ARM64_CC% (
ECHO "Make standalone toolchain for ARM64 arch"
%ANDROID_NDK_HOME%\build\tools\make_standalone_toolchain.py --arch arm64 ^
python.exe %ANDROID_NDK_HOME%\build\tools\make_standalone_toolchain.py --arch arm64 ^
--api %MIN_API% --install-dir %ANDROID_ARM64_TOOLCHAIN%
)

IF NOT EXIST %ANDROID_X86_CC% (
ECHO "Make standalone toolchain for X86 arch"
%ANDROID_NDK_HOME%\build\tools\make_standalone_toolchain.py --arch x86 ^
python.exe %ANDROID_NDK_HOME%\build\tools\make_standalone_toolchain.py --arch x86 ^
--api %MIN_API% --install-dir %ANDROID_X86_TOOLCHAIN%
)

Expand Down Expand Up @@ -118,4 +132,4 @@ IF %BUILD% == 1 (
)

ECHO "Successfully build overture"
ENDLOCAL
ENDLOCAL
42 changes: 26 additions & 16 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https://github.com/arturbosch/detekt/blob/801994bd60cc759b181649356cea045b8125301b/detekt-cli/src/main/resources/default-detekt-config.yml
# https://github.com/arturbosch/detekt/blob/RC6-4/detekt-cli/src/main/resources/default-detekt-config.yml

comments:
active: false
Expand All @@ -7,14 +7,15 @@ complexity:
active: true
ComplexCondition:
active: true
threshold: 3
threshold: 4
ComplexInterface:
active: true
threshold: 10
includeStaticDeclarations: false
ComplexMethod:
active: true
threshold: 10
ignoreSingleWhenExpression: false
LabeledExpression:
active: true
LargeClass:
Expand All @@ -25,31 +26,32 @@ complexity:
threshold: 20
LongParameterList:
active: true
threshold: 5
threshold: 6
ignoreDefaultParameters: true
MethodOverloading:
active: false
NestedBlockDepth:
active: true
threshold: 3
threshold: 4
StringLiteralDuplication:
active: true
threshold: 2
threshold: 3
ignoreAnnotation: true
excludeStringsWithLessThan5Characters: true
ignoreStringsRegex: '$^'
TooManyFunctions:
active: true
thresholdInFiles: 10
thresholdInClasses: 10
thresholdInInterfaces: 10
thresholdInObjects: 10
thresholdInEnums: 10
thresholdInFiles: 11
thresholdInClasses: 11
thresholdInInterfaces: 11
thresholdInObjects: 11
thresholdInEnums: 11

empty-blocks:
active: true
EmptyCatchBlock:
active: false
active: true
allowedExceptionNameRegex: "^(_|ignore|expected).*"
EmptyClassBlock:
active: true
EmptyDefaultConstructor:
Expand All @@ -64,6 +66,7 @@ empty-blocks:
active: true
EmptyFunctionBlock:
active: true
ignoreOverriddenFunctions: false
EmptyIfBlock:
active: true
EmptyInitBlock:
Expand Down Expand Up @@ -105,7 +108,7 @@ exceptions:
active: true
TooGenericExceptionCaught:
active: true
exceptions:
exceptionNames:
- ArrayIndexOutOfBoundsException
- Error
- Exception
Expand All @@ -116,10 +119,9 @@ exceptions:
- Throwable
TooGenericExceptionThrown:
active: true
exceptions:
exceptionNames:
- Error
- Exception
- NullPointerException
- Throwable
- RuntimeException

Expand All @@ -143,6 +145,7 @@ naming:
FunctionNaming:
active: true
functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
excludeClassPattern: '$^'
MatchingDeclarationName:
active: true
MemberNameEqualsClassName:
Expand All @@ -167,6 +170,7 @@ naming:
active: true
variablePattern: '[a-z][A-Za-z0-9]*'
privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'

performance:
active: true
Expand Down Expand Up @@ -239,15 +243,17 @@ style:
maxLineLength: 120
excludePackageStatements: false
excludeImportStatements: false
MayBeConst:
active: true
ModifierOrder:
active: true
NestedClassesVisibility:
active: true
NewLineAtEndOfFile:
active: true
OptionalAbstractKeyword:
NoTabs:
active: true
OptionalReturnKeyword:
OptionalAbstractKeyword:
active: true
OptionalUnit:
active: true
Expand All @@ -268,6 +274,8 @@ style:
ThrowsCount:
active: true
max: 2
TrailingWhitespace:
active: true
UnnecessaryAbstractClass:
active: true
UnnecessaryInheritance:
Expand All @@ -278,6 +286,8 @@ style:
active: true
UnusedImports:
active: true
UnusedPrivateMember:
active: true
UseDataClass:
active: false
UtilityClassWithPublicConstructor:
Expand Down
Loading

0 comments on commit a95c86a

Please sign in to comment.