Skip to content

Commit

Permalink
support andoird
Browse files Browse the repository at this point in the history
  • Loading branch information
TenderIronHanhan committed Nov 3, 2022
1 parent 2af7766 commit af82fc6
Show file tree
Hide file tree
Showing 90 changed files with 1,674 additions and 334 deletions.
14 changes: 11 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
__debug_bin
__debug_bin.exe
# .vscode
openp2p
test/
openp2p.exe*
*.log
*.log*
go.sum
*.tar.gz
*.zip
*.exe
*.exe
config.json
libs/
*/app/.idea/
*/app/release/
openp2p.app.jks
openp2p.aar
openp2p-sources.jar
build.gradle
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build:
export GOPROXY=https://goproxy.io,direct
go mod tidy
go build cmd/openp2p.go
.PHONY: build

.DEFAULT_GOAL := build
5 changes: 2 additions & 3 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ P2P直连可以让你的设备跑满带宽。不论你的设备在任何网络
## 快速入门
仅需简单4步就能用起来。
下面是一个远程办公例子:在家里连入办公室Windows电脑。
(另外一个快速入门视频 https://www.bilibili.com/video/BV1Et4y1P7bF/)
### 1.注册
前往<https://console.openp2p.cn> 注册新用户,暂无需任何认证

Expand Down Expand Up @@ -98,9 +99,7 @@ Windows默认会阻止没有花钱买它家证书签名过的程序,选择“
go version go1.18.1+
cd到代码根目录,执行
```
export GOPROXY=https://goproxy.io,direct
go mod tidy
go build
make
```

## RoadMap
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Your applicaiton can call OpenP2P with a few code to make any internal networks
## Get Started
Just 4 simple steps to use.
Here's an example of remote work: connecting to an office Windows computer at home.
(Another quick started vedio https://www.bilibili.com/video/BV1Et4y1P7bF/)
### 1.Register
Go to <https://console.openp2p.cn> register a new user

Expand Down Expand Up @@ -106,9 +106,7 @@ The server side has a scheduling model, which calculate bandwith, ping value,st
go version go1.18.1+
cd root directory of the socure code and execute
```
export GOPROXY=https://goproxy.io,direct
go mod tidy
go build
make
```

## RoadMap
Expand Down
15 changes: 15 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions app/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions app/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions app/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions app/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
21 changes: 21 additions & 0 deletions app/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
24 changes: 24 additions & 0 deletions app/app/src/androidTest/java/cn/openp2p/ExampleInstrumentedTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.openp2p

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("cn.openp2p", appContext.packageName)
}
}
39 changes: 39 additions & 0 deletions app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.openp2p">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OpenP2P">
<service
android:name=".OpenP2PService"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_VPN_SERVICE">
<intent-filter>
<action android:name="android.net.VpnService"/>
</intent-filter>
</service>

<activity
android:name=".ui.login.LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
59 changes: 59 additions & 0 deletions app/app/src/main/java/cn/openp2p/OpenP2PService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cn.openp2p

import android.app.Service
import android.content.Intent
import android.net.VpnService
import android.os.Binder
import android.os.IBinder
import openp2p.Openp2p
import android.util.Log
import cn.openp2p.ui.login.LoginActivity
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

class OpenP2PService : VpnService() {
companion object {
private val LOG_TAG = OpenP2PService::class.simpleName
}

inner class LocalBinder : Binder() {
fun getService(): OpenP2PService = this@OpenP2PService
}

private val binder = LocalBinder()
private lateinit var network: openp2p.P2PNetwork
override fun onCreate() {
Log.i("xiao","onCreate - Thread ID = " + Thread.currentThread().id)
super.onCreate()

}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.i("xiao", "onStartCommand - startId = " + startId + ", Thread ID = " + Thread.currentThread().id)
return super.onStartCommand(intent, flags, startId)
}

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

override fun onDestroy() {
Log.i("xiao", "onDestroy - Thread ID = " + Thread.currentThread().id)
super.onDestroy()
}
fun onStart(token:String){
GlobalScope.launch {
do {
network =Openp2p.runAsModule(getExternalFilesDir(null).toString(), token, 0)
val isConnect = network.connect(30000) // ms
Log.i(OpenP2PService.LOG_TAG, "login result: " + isConnect.toString());
} while(!network?.connect(10000))

}
}
fun isConnected(): Boolean{
if (!::network.isInitialized) return false
return network?.connect(1000)
}

}
24 changes: 24 additions & 0 deletions app/app/src/main/java/cn/openp2p/data/LoginDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.openp2p.data

import cn.openp2p.data.model.LoggedInUser
import java.io.IOException

/**
* Class that handles authentication w/ login credentials and retrieves user information.
*/
class LoginDataSource {

fun login(username: String, password: String): Result<LoggedInUser> {
try {
// TODO: handle loggedInUser authentication
val fakeUser = LoggedInUser(java.util.UUID.randomUUID().toString(), "Jane Doe")
return Result.Success(fakeUser)
} catch (e: Throwable) {
return Result.Error(IOException("Error logging in", e))
}
}

fun logout() {
// TODO: revoke authentication
}
}
Loading

0 comments on commit af82fc6

Please sign in to comment.