1. fixed Yggdrasil().Stop() crash

2. Minor GUI changes
This commit is contained in:
vadym 2020-06-27 08:54:10 -07:00
parent 3db311c4d2
commit 38fb87b08d
7 changed files with 74 additions and 81 deletions

View File

@ -8,8 +8,8 @@ android {
applicationId "io.github.chronosx88.yggdrasil" applicationId "io.github.chronosx88.yggdrasil"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 2 versionCode 3
versionName "1.1" versionName "1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
project.ext.set("archivesBaseName", project.getParent().name+"-"+versionName) 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 { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':yggdrasil') implementation project(path: ':yggdrasil')

View File

@ -92,7 +92,7 @@ class DNSListActivity : AppCompatActivity() {
val result = Intent(this, MainActivity::class.java) val result = Intent(this, MainActivity::class.java)
var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter var adapter = findViewById<ListView>(R.id.dnsList).adapter as SelectDNSInfoListAdapter
val selectedDNS = adapter.getSelectedDNS() val selectedDNS = adapter.getSelectedDNS()
if(selectedDNS.size>0) { if(selectedDNS.isNotEmpty()) {
result.putExtra(MainActivity.DNS_LIST, MainActivity.serializeDNSInfoSet2StringList(selectedDNS)) result.putExtra(MainActivity.DNS_LIST, MainActivity.serializeDNSInfoSet2StringList(selectedDNS))
setResult(Activity.RESULT_OK, result) setResult(Activity.RESULT_OK, result)
finish() finish()

View File

@ -163,8 +163,6 @@ class MainActivity : AppCompatActivity() {
private fun startVpn(){ private fun startVpn(){
Log.d(TAG,"Start") Log.d(TAG,"Start")
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
ipLayout.visibility = View.VISIBLE
val intent= VpnService.prepare(this) val intent= VpnService.prepare(this)
if (intent!=null){ if (intent!=null){
startActivityForResult(intent, VPN_REQUEST_CODE) startActivityForResult(intent, VPN_REQUEST_CODE)
@ -253,13 +251,16 @@ class MainActivity : AppCompatActivity() {
when (resultCode) { when (resultCode) {
STATUS_START -> print("service started") STATUS_START -> print("service started")
STATUS_FINISH -> { STATUS_FINISH -> {
isStarted = true
val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
ipLayout.visibility = View.VISIBLE
val result: String = data!!.getStringExtra(IPv6) val result: String = data!!.getStringExtra(IPv6)
findViewById<TextView>(R.id.ip).text = result findViewById<TextView>(R.id.ip).text = result
isStarted = true
} }
STATUS_STOP -> { STATUS_STOP -> {
isStarted = false isStarted = false
finish() val ipLayout = findViewById<LinearLayout>(R.id.ipLayout)
ipLayout.visibility = View.GONE
} }
else -> { // Note the block else -> { // Note the block

View File

@ -5,13 +5,12 @@ import android.content.Intent
import android.net.VpnService import android.net.VpnService
import android.os.ParcelFileDescriptor import android.os.ParcelFileDescriptor
import android.system.OsConstants import android.system.OsConstants
import android.util.Log
import com.google.gson.Gson import com.google.gson.Gson
import dummy.ConduitEndpoint import dummy.ConduitEndpoint
import io.github.chronosx88.yggdrasil.models.DNSInfo import io.github.chronosx88.yggdrasil.models.DNSInfo
import io.github.chronosx88.yggdrasil.models.PeerInfo import io.github.chronosx88.yggdrasil.models.PeerInfo
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.*
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import mobile.Mobile import mobile.Mobile
import mobile.Yggdrasil import mobile.Yggdrasil
import java.io.* import java.io.*
@ -40,11 +39,9 @@ class YggdrasilTunService : VpnService() {
} }
} }
private var tunInterface: ParcelFileDescriptor? = null private var tunInterface: ParcelFileDescriptor? = null
private lateinit var yggConduitEndpoint: ConduitEndpoint
private var tunInputStream: InputStream? = null private var tunInputStream: InputStream? = null
private var tunOutputStream: OutputStream? = null private var tunOutputStream: OutputStream? = null
private lateinit var readCoroutine: CoroutineContext private var scope: CoroutineScope? = null
private lateinit var writeCoroutine: CoroutineContext
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@ -75,37 +72,40 @@ class YggdrasilTunService : VpnService() {
config = fixConfig(config, peers) config = fixConfig(config, peers)
configJson = gson.toJson(config).toByteArray() 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 val address = ygg.addressString // hack for getting generic ipv6 string from NodeID
var builder = Builder() var builder = Builder()
.addAddress(address, 7) .addAddress(address, 7)
.allowFamily(OsConstants.AF_INET) .allowFamily(OsConstants.AF_INET)
.setMtu(MAX_PACKET_SIZE) .setMtu(MAX_PACKET_SIZE)
if(dns.size>0){ if (dns.size > 0) {
for (d in dns){ for (d in dns) {
builder.addDnsServer(d.address) builder.addDnsServer(d.address)
} }
} }
tunInterface = builder.establish() tunInterface = builder.establish()
tunInputStream = FileInputStream(tunInterface!!.fileDescriptor) tunInputStream = FileInputStream(tunInterface!!.fileDescriptor)
tunOutputStream = FileOutputStream(tunInterface!!.fileDescriptor) tunOutputStream = FileOutputStream(tunInterface!!.fileDescriptor)
readCoroutine = GlobalScope.launch { val job = SupervisorJob()
scope = CoroutineScope(Dispatchers.Default + job)
scope!!.launch {
val buffer = ByteArray(2048) val buffer = ByteArray(2048)
try{ try {
while (true) { while (!isClosed) {
readPacketsFromTun(buffer) readPacketsFromTun(yggConduitEndpoint, buffer)
} }
} catch (e: IOException){ } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
tunInputStream!!.close() tunInputStream!!.close()
} }
} }
writeCoroutine = GlobalScope.launch { scope!!.launch {
while (true) { while (!isClosed) {
writePacketsToTun() writePacketsToTun(yggConduitEndpoint)
} }
} }
val intent: Intent = Intent().putExtra(MainActivity.IPv6, address) val intent: Intent = Intent().putExtra(MainActivity.IPv6, address)
pi.send(this, MainActivity.STATUS_FINISH, intent) pi.send(this, MainActivity.STATUS_FINISH, intent)
} }
@ -141,21 +141,19 @@ class YggdrasilTunService : VpnService() {
return config return config
} }
private fun readPacketsFromTun(buffer: ByteArray) { private fun readPacketsFromTun(yggConduitEndpoint: ConduitEndpoint, buffer: ByteArray) {
if(!isClosed) { // Read the outgoing packet from the input stream.
// Read the outgoing packet from the input stream. val length = tunInputStream!!.read(buffer)
val length = tunInputStream!!.read(buffer) if (length > 0) {
if (length > 0) { val byteBuffer = ByteBuffer.allocate(length)
val byteBuffer = ByteBuffer.allocate(length) byteBuffer.put(buffer, 0, length)
byteBuffer.put(buffer, 0, length) yggConduitEndpoint.send(byteBuffer.array())
yggConduitEndpoint.send(byteBuffer.array()) } else {
} else { Thread.sleep(10)
Thread.sleep(10)
}
} }
} }
private fun writePacketsToTun() { private fun writePacketsToTun(yggConduitEndpoint: ConduitEndpoint) {
if(tunOutputStream != null) { if(tunOutputStream != null) {
val buffer = yggConduitEndpoint.recv() val buffer = yggConduitEndpoint.recv()
if(buffer!=null) { if(buffer!=null) {
@ -170,12 +168,12 @@ class YggdrasilTunService : VpnService() {
private fun stopVpn(pi: PendingIntent) { private fun stopVpn(pi: PendingIntent) {
isClosed = true; isClosed = true;
readCoroutine.cancel() scope!!.coroutineContext.cancelChildren()
writeCoroutine.cancel()
tunInputStream!!.close() tunInputStream!!.close()
tunOutputStream!!.close() tunOutputStream!!.close()
tunInterface!!.close() tunInterface!!.close()
tunInterface = null tunInterface = null
Log.d(TAG,"Stop is running from service")
ygg.stop() ygg.stop()
val intent: Intent = Intent() val intent: Intent = Intent()
pi.send(this, MainActivity.STATUS_STOP, intent) pi.send(this, MainActivity.STATUS_STOP, intent)

View File

@ -23,7 +23,7 @@ class SelectDNSInfoListAdapter(
private var currentDNS: MutableSet<DNSInfo> = currentDNS private var currentDNS: MutableSet<DNSInfo> = currentDNS
override fun getItem(position: Int): DNSInfo? { override fun getItem(position: Int): DNSInfo? {
return allDNS.get(position) return allDNS[position]
} }
override fun getCount(): Int { override fun getCount(): Int {
@ -78,13 +78,6 @@ class SelectDNSInfoListAdapter(
allDNS.add(peerInfo) allDNS.add(peerInfo)
} }
fun addAll(index: Int, peerInfo: ArrayList<DNSInfo>){
currentDNS.addAll(peerInfo)
allDNS.removeAll(peerInfo)
allDNS.addAll(index, peerInfo)
this.notifyDataSetChanged()
}
fun sort(){ fun sort(){
allDNS = ArrayList(allDNS.sortedWith(compareBy { it.ping })) allDNS = ArrayList(allDNS.sortedWith(compareBy { it.ping }))
this.notifyDataSetChanged() this.notifyDataSetChanged()

View File

@ -14,10 +14,11 @@
android:layout_margin="20dp" android:layout_margin="20dp"
android:background="@drawable/info_panel_rounded_corner" android:background="@drawable/info_panel_rounded_corner"
android:gravity="left" android:gravity="left"
android:paddingLeft="20dp"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
android:visibility="gone" android:animateLayoutChanges="true"
android:animateLayoutChanges="true"> android:visibility="gone">
<TextView <TextView
android:id="@+id/ipLabel" android:id="@+id/ipLabel"
@ -26,22 +27,35 @@
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:elevation="8dp" android:elevation="8dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingLeft="20dp" android:text="IP address:"
android:text="Your IP address:"
android:textColor="@color/dark_30" /> android:textColor="@color/dark_30" />
<TextView
android:id="@+id/ip" <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="30dp" android:layout_height="wrap_content"
android:background="@android:color/transparent" app:layout_constraintTop_toTopOf="parent">
android:elevation="8dp" <TextView
android:gravity="center_vertical" android:id="@+id/ip"
android:paddingLeft="20dp" android:layout_width="match_parent"
android:layout_marginBottom="10dp" android:layout_height="30dp"
android:text="" android:background="@android:color/transparent"
android:textColor="@color/white" android:elevation="8dp"
app:layout_constraintBottom_toTopOf="@+id/connectRadioGroup" android:gravity="center_vertical"
app:layout_constraintTop_toTopOf="parent" /> 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> </LinearLayout>
@ -58,8 +72,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent">
android:orientation="horizontal">
<TextView <TextView
android:id="@+id/ipPeers" android:id="@+id/ipPeers"
@ -80,8 +93,8 @@
android:text="EDIT" android:text="EDIT"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:background="@android:color/transparent"/> android:background="@android:color/transparent"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<ListView <ListView
android:id="@+id/peers" android:id="@+id/peers"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -106,8 +119,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent">
android:orientation="horizontal">
<TextView <TextView
android:id="@+id/dnsLabel" android:id="@+id/dnsLabel"

View File

@ -4,7 +4,7 @@ all:
-go get -u github.com/yggdrasil-network/yggdrasil-go; -go get -u github.com/yggdrasil-network/yggdrasil-go;
-cd $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go; \ -cd $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go; \
go get -v -d ./...; \ 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; ANDROID=true ./build;
mv $(GOPATH)/src/github.com/yggdrasil-network/yggdrasil-go/yggdrasil.aar yggdrasil.aar; mv -f $(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-sources.jar yggdrasil-sources.jar;