1. fixed unnecessary empty array condition

This commit is contained in:
vadym 2020-06-12 06:52:28 -07:00
parent ae9f154dca
commit a1c175e9a4

View File

@ -124,6 +124,8 @@ class YggdrasilTunService : VpnService() {
//System.out.println("packet size:"+packet.size+" "+byteArrayToHex(packet)) //System.out.println("packet size:"+packet.size+" "+byteArrayToHex(packet))
//System.out.println("buffer size:"+buffer.array().size+" "+byteArrayToHex(buffer.array())) //System.out.println("buffer size:"+buffer.array().size+" "+byteArrayToHex(buffer.array()))
if (length > 0) { if (length > 0) {
// Ignore control messages, which start with zero.
if (packet.get(0).compareTo(0)!=0) {
var buffer = ByteBuffer.allocate(length); var buffer = ByteBuffer.allocate(length);
buffer.put(packet, 0, length) buffer.put(packet, 0, length)
buffer.limit(length) buffer.limit(length)
@ -131,6 +133,7 @@ class YggdrasilTunService : VpnService() {
} }
} }
} }
}
private fun isBufferEmpty(buffer: ByteArray): Boolean { private fun isBufferEmpty(buffer: ByteArray): Boolean {
var sum: Byte = 0 var sum: Byte = 0
@ -143,11 +146,9 @@ class YggdrasilTunService : VpnService() {
private fun writePacketsToTun() { private fun writePacketsToTun() {
if(tunOutputStream != null) { if(tunOutputStream != null) {
val buffer = yggConduitEndpoint.recv() val buffer = yggConduitEndpoint.recv()
if (!isBufferEmpty(buffer)) {
tunOutputStream!!.write(buffer) tunOutputStream!!.write(buffer)
} }
} }
}
override fun onRevoke() { override fun onRevoke() {
super.onRevoke() super.onRevoke()