mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-09 12:01:01 +00:00
1. fixed Yggdrasil().Stop() crash
2. Minor GUI changes
This commit is contained in:
parent
3db311c4d2
commit
38fb87b08d
@ -8,8 +8,8 @@ android {
|
||||
applicationId "io.github.chronosx88.yggdrasil"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 2
|
||||
versionName "1.1"
|
||||
versionCode 3
|
||||
versionName "1.2"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
project.ext.set("archivesBaseName", project.getParent().name+"-"+versionName)
|
||||
}
|
||||
@ -38,17 +38,6 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
task ndkBuild(type: Exec) {
|
||||
def rootDir = project.rootDir
|
||||
workingDir = new File(rootDir,"yggdrasil")
|
||||
commandLine 'make'
|
||||
}
|
||||
|
||||
gradle.projectsEvaluated {
|
||||
tasks.compileDebugKotlin.dependsOn(ndkBuild)
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation project(path: ':yggdrasil')
|
||||
|
@ -92,7 +92,7 @@ class DNSListActivity : AppCompatActivity() {
|
||||
val result = Intent(this, MainActivity::class.java)
|
||||
var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter
|
||||
val selectedDNS = adapter.getSelectedDNS()
|
||||
if(selectedDNS.size>0) {
|
||||
if(selectedDNS.isNotEmpty()) {
|
||||
result.putExtra(MainActivity.DNS_LIST, MainActivity.serializeDNSInfoSet2StringList(selectedDNS))
|
||||
setResult(Activity.RESULT_OK, result)
|
||||
finish()
|
||||
|
@ -163,8 +163,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun startVpn(){
|
||||
Log.d(TAG,"Start")
|
||||
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
|
||||
ipLayout.visibility = View.VISIBLE
|
||||
val intent= VpnService.prepare(this)
|
||||
if (intent!=null){
|
||||
startActivityForResult(intent, VPN_REQUEST_CODE)
|
||||
@ -253,13 +251,16 @@ class MainActivity : AppCompatActivity() {
|
||||
when (resultCode) {
|
||||
STATUS_START -> print("service started")
|
||||
STATUS_FINISH -> {
|
||||
isStarted = true
|
||||
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
|
||||
ipLayout.visibility = View.VISIBLE
|
||||
val result: String = data!!.getStringExtra(IPv6)
|
||||
findViewById<TextView>(R.id.ip).text = result
|
||||
isStarted = true
|
||||
}
|
||||
STATUS_STOP -> {
|
||||
isStarted = false
|
||||
finish()
|
||||
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
|
||||
ipLayout.visibility = View.GONE
|
||||
}
|
||||
else -> { // Note the block
|
||||
|
||||
|
@ -5,13 +5,12 @@ import android.content.Intent
|
||||
import android.net.VpnService
|
||||
import android.os.ParcelFileDescriptor
|
||||
import android.system.OsConstants
|
||||
import android.util.Log
|
||||
import com.google.gson.Gson
|
||||
import dummy.ConduitEndpoint
|
||||
import io.github.chronosx88.yggdrasil.models.DNSInfo
|
||||
import io.github.chronosx88.yggdrasil.models.PeerInfo
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.*
|
||||
import mobile.Mobile
|
||||
import mobile.Yggdrasil
|
||||
import java.io.*
|
||||
@ -40,11 +39,9 @@ class YggdrasilTunService : VpnService() {
|
||||
}
|
||||
}
|
||||
private var tunInterface: ParcelFileDescriptor? = null
|
||||
private lateinit var yggConduitEndpoint: ConduitEndpoint
|
||||
private var tunInputStream: InputStream? = null
|
||||
private var tunOutputStream: OutputStream? = null
|
||||
private lateinit var readCoroutine: CoroutineContext
|
||||
private lateinit var writeCoroutine: CoroutineContext
|
||||
private var scope: CoroutineScope? = null
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
|
||||
@ -75,37 +72,40 @@ class YggdrasilTunService : VpnService() {
|
||||
config = fixConfig(config, peers)
|
||||
configJson = gson.toJson(config).toByteArray()
|
||||
|
||||
yggConduitEndpoint = ygg.startJSON(configJson)
|
||||
var yggConduitEndpoint = ygg.startJSON(configJson)
|
||||
val address = ygg.addressString // hack for getting generic ipv6 string from NodeID
|
||||
|
||||
var builder = Builder()
|
||||
.addAddress(address, 7)
|
||||
.allowFamily(OsConstants.AF_INET)
|
||||
.setMtu(MAX_PACKET_SIZE)
|
||||
if(dns.size>0){
|
||||
for (d in dns){
|
||||
if (dns.size > 0) {
|
||||
for (d in dns) {
|
||||
builder.addDnsServer(d.address)
|
||||
}
|
||||
}
|
||||
tunInterface = builder.establish()
|
||||
tunInputStream = FileInputStream(tunInterface!!.fileDescriptor)
|
||||
tunOutputStream = FileOutputStream(tunInterface!!.fileDescriptor)
|
||||
readCoroutine = GlobalScope.launch {
|
||||
val job = SupervisorJob()
|
||||
scope = CoroutineScope(Dispatchers.Default + job)
|
||||
scope!!.launch {
|
||||
val buffer = ByteArray(2048)
|
||||
try{
|
||||
while (true) {
|
||||
readPacketsFromTun(buffer)
|
||||
try {
|
||||
while (!isClosed) {
|
||||
readPacketsFromTun(yggConduitEndpoint, buffer)
|
||||
}
|
||||
} catch (e: IOException){
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
tunInputStream!!.close()
|
||||
}
|
||||
}
|
||||
writeCoroutine = GlobalScope.launch {
|
||||
while (true) {
|
||||
writePacketsToTun()
|
||||
scope!!.launch {
|
||||
while (!isClosed) {
|
||||
writePacketsToTun(yggConduitEndpoint)
|
||||
}
|
||||
}
|
||||
|
||||
val intent: Intent = Intent().putExtra(MainActivity.IPv6, address)
|
||||
pi.send(this, MainActivity.STATUS_FINISH, intent)
|
||||
}
|
||||
@ -141,21 +141,19 @@ class YggdrasilTunService : VpnService() {
|
||||
return config
|
||||
}
|
||||
|
||||
private fun readPacketsFromTun(buffer: ByteArray) {
|
||||
if(!isClosed) {
|
||||
// Read the outgoing packet from the input stream.
|
||||
val length = tunInputStream!!.read(buffer)
|
||||
if (length > 0) {
|
||||
val byteBuffer = ByteBuffer.allocate(length)
|
||||
byteBuffer.put(buffer, 0, length)
|
||||
yggConduitEndpoint.send(byteBuffer.array())
|
||||
} else {
|
||||
Thread.sleep(10)
|
||||
}
|
||||
private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) {
|
||||
// Read the outgoing packet from the input stream.
|
||||
val length = tunInputStream!!.read(buffer)
|
||||
if (length > 0) {
|
||||
val byteBuffer = ByteBuffer.allocate(length)
|
||||
byteBuffer.put(buffer, 0, length)
|
||||
yggConduitEndpoint.send(byteBuffer.array())
|
||||
} else {
|
||||
Thread.sleep(10)
|
||||
}
|
||||
}
|
||||
|
||||
private fun writePacketsToTun() {
|
||||
private fun writePacketsToTun(yggConduitEndpoint: ConduitEndpoint) {
|
||||
if(tunOutputStream != null) {
|
||||
val buffer = yggConduitEndpoint.recv()
|
||||
if(buffer!=null) {
|
||||
@ -170,12 +168,12 @@ class YggdrasilTunService : VpnService() {
|
||||
|
||||
private fun stopVpn(pi: PendingIntent) {
|
||||
isClosed = true;
|
||||
readCoroutine.cancel()
|
||||
writeCoroutine.cancel()
|
||||
scope!!.coroutineContext.cancelChildren()
|
||||
tunInputStream!!.close()
|
||||
tunOutputStream!!.close()
|
||||
tunInterface!!.close()
|
||||
tunInterface = null
|
||||
Log.d(TAG,"Stop is running from service")
|
||||
ygg.stop()
|
||||
val intent: Intent = Intent()
|
||||
pi.send(this, MainActivity.STATUS_STOP, intent)
|
||||
|
@ -23,7 +23,7 @@ class SelectDNSInfoListAdapter(
|
||||
private var currentDNS: MutableSet<DNSInfo> = currentDNS
|
||||
|
||||
override fun getItem(position: Int): DNSInfo? {
|
||||
return allDNS.get(position)
|
||||
return allDNS[position]
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
@ -78,13 +78,6 @@ class SelectDNSInfoListAdapter(
|
||||
allDNS.add(peerInfo)
|
||||
}
|
||||
|
||||
fun addAll(index: Int, peerInfo: ArrayList<DNSInfo>){
|
||||
currentDNS.addAll(peerInfo)
|
||||
allDNS.removeAll(peerInfo)
|
||||
allDNS.addAll(index, peerInfo)
|
||||
this.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun sort(){
|
||||
allDNS = ArrayList(allDNS.sortedWith(compareBy { it.ping }))
|
||||
this.notifyDataSetChanged()
|
||||
|
@ -14,10 +14,11 @@
|
||||
android:layout_margin="20dp"
|
||||
android:background="@drawable/info_panel_rounded_corner"
|
||||
android:gravity="left"
|
||||
android:paddingLeft="20dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:visibility="gone"
|
||||
android:animateLayoutChanges="true">
|
||||
android:animateLayoutChanges="true"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ipLabel"
|
||||
@ -26,22 +27,35 @@
|
||||
android:background="@android:color/transparent"
|
||||
android:elevation="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="20dp"
|
||||
android:text="Your IP address:"
|
||||
android:text="IP address:"
|
||||
android:textColor="@color/dark_30" />
|
||||
<TextView
|
||||
android:id="@+id/ip"
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="30dp"
|
||||
android:background="@android:color/transparent"
|
||||
android:elevation="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text=""
|
||||
android:textColor="@color/white"
|
||||
app:layout_constraintBottom_toTopOf="@+id/connectRadioGroup"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
<TextView
|
||||
android:id="@+id/ip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="30dp"
|
||||
android:background="@android:color/transparent"
|
||||
android:elevation="8dp"
|
||||
android:gravity="center_vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/copyIp"
|
||||
android:text=""
|
||||
android:textColor="@color/white"/>
|
||||
<Button
|
||||
android:id="@+id/copyIp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:text="COPY"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -58,8 +72,7 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:orientation="horizontal">
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ipPeers"
|
||||
@ -80,8 +93,8 @@
|
||||
android:text="EDIT"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:background="@android:color/transparent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/peers"
|
||||
android:layout_width="match_parent"
|
||||
@ -106,8 +119,7 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:orientation="horizontal">
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dnsLabel"
|
||||
|
@ -4,7 +4,7 @@ all:
|
||||
-go get -u github.com/yggdrasil-network/yggdrasil-go;
|
||||
-cd $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go; \
|
||||
go get -v -d ./...; \
|
||||
go get -u github.com/yggdrasil-network/yggdrasil-extras; \
|
||||
go get -u github.com/vikulin/yggdrasil-extras@ab56805; \
|
||||
ANDROID=true ./build;
|
||||
mv $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil.aar yggdrasil.aar;
|
||||
mv $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil-sources.jar yggdrasil-sources.jar;
|
||||
mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil.aar yggdrasil.aar;
|
||||
mv -f $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil-sources.jar yggdrasil-sources.jar;
|
||||
|
Loading…
Reference in New Issue
Block a user