diff --git a/app/src/main/java/com/lipisoft/toyshark/PacketManager.kt b/app/src/main/java/com/lipisoft/toyshark/PacketManager.kt index 3d22ff2..01014d0 100644 --- a/app/src/main/java/com/lipisoft/toyshark/PacketManager.kt +++ b/app/src/main/java/com/lipisoft/toyshark/PacketManager.kt @@ -29,10 +29,6 @@ enum class PacketManager { return list.add(packet) } - fun getList(): List { - return list - } - fun setAdapter(adapter: PacketListAdapter) { this.adapter = adapter } diff --git a/app/src/main/java/com/lipisoft/toyshark/ToySharkVPNService.kt b/app/src/main/java/com/lipisoft/toyshark/ToySharkVPNService.kt index 4de7d0d..2647437 100644 --- a/app/src/main/java/com/lipisoft/toyshark/ToySharkVPNService.kt +++ b/app/src/main/java/com/lipisoft/toyshark/ToySharkVPNService.kt @@ -342,6 +342,7 @@ class ToySharkVPNService : VpnService(), Handler.Callback, Runnable, IProtectSoc } Log.i(TAG, "startVpnService => create builder") + // Configure a builder while parsing the parameters. val builder = Builder() .addAddress("10.120.0.1", 32) @@ -350,12 +351,12 @@ class ToySharkVPNService : VpnService(), Handler.Callback, Runnable, IProtectSoc fileDescriptor = builder.establish() - if (fileDescriptor != null) { + return if (fileDescriptor != null) { Log.i(TAG, "VPN Established:interface = " + fileDescriptor!!.fileDescriptor.toString()) - return true + true } else { Log.d(TAG, "fileDescriptor is null") - return false + false } } diff --git a/app/src/main/java/com/lipisoft/toyshark/network/ip/IPPacketFactory.kt b/app/src/main/java/com/lipisoft/toyshark/network/ip/IPPacketFactory.kt index 6ce156e..cbb6775 100755 --- a/app/src/main/java/com/lipisoft/toyshark/network/ip/IPPacketFactory.kt +++ b/app/src/main/java/com/lipisoft/toyshark/network/ip/IPPacketFactory.kt @@ -45,7 +45,7 @@ object IPPacketFactory { iPv4Header.totalLength, iPv4Header.identification, iPv4Header.isMayFragment, - iPv4Header.isLastFragment, + iPv4Header.lastFragment, iPv4Header.fragmentOffset, iPv4Header.timeToLive, iPv4Header.protocol, diff --git a/app/src/main/java/com/lipisoft/toyshark/network/ip/IPv4Header.kt b/app/src/main/java/com/lipisoft/toyshark/network/ip/IPv4Header.kt index 0040cab..2433aab 100755 --- a/app/src/main/java/com/lipisoft/toyshark/network/ip/IPv4Header.kt +++ b/app/src/main/java/com/lipisoft/toyshark/network/ip/IPv4Header.kt @@ -54,7 +54,7 @@ class IPv4Header( var totalLength: Int, var identification: Int, private var mayFragment: Boolean, - val isLastFragment: Boolean, + val lastFragment: Boolean, val fragmentOffset: Short, val timeToLive: Byte, val protocol: Byte, @@ -68,7 +68,7 @@ class IPv4Header( if (mayFragment) this.flag = this.flag or 0x40 - if (isLastFragment) + if (lastFragment) this.flag = this.flag or 0x20 } diff --git a/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataReaderWorker.kt b/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataReaderWorker.kt index 7051023..737d50e 100755 --- a/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataReaderWorker.kt +++ b/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataReaderWorker.kt @@ -30,6 +30,10 @@ import java.util.Date internal class SocketDataReaderWorker(private val writer: ClientPacketWriter, private val sessionKey: String) : Runnable { private val socketData: SocketData = SocketData.instance + companion object { + private const val TAG = "SocketDataReaderWorker" + } + override fun run() { val session = SessionManager.INSTANCE.getSessionByKey(sessionKey) if (session == null) { @@ -127,6 +131,7 @@ internal class SocketDataReaderWorker(private val writer: ClientPacketWriter, pr val data = ByteArray(dataSize) System.arraycopy(buffer.array(), 0, data, 0, dataSize) session.addReceivedData(data) + // pushing all data to vpn client while (session.hasReceivedData()) { pushDataToClient(session) @@ -140,7 +145,7 @@ internal class SocketDataReaderWorker(private val writer: ClientPacketWriter, pr */ private fun pushDataToClient(session: Session) { if (!session.hasReceivedData()) { - //no data to send + // no data to send Log.d(TAG, "no data for vpn client") } @@ -243,8 +248,4 @@ internal class SocketDataReaderWorker(private val writer: ClientPacketWriter, pr } } - - companion object { - private val TAG = "SocketDataReaderWorker" - } } diff --git a/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataWriterWorker.kt b/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataWriterWorker.kt index 51f1194..c9645e5 100755 --- a/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataWriterWorker.kt +++ b/app/src/main/java/com/lipisoft/toyshark/socket/SocketDataWriterWorker.kt @@ -18,7 +18,7 @@ import java.util.Date class SocketDataWriterWorker(writer: ClientPacketWriter, private val sessionKey: String) : Runnable { companion object { - private val TAG = "SocketDataWriterWorker" + private const val TAG = "SocketDataWriterWorker" private var writer: ClientPacketWriter? = null } diff --git a/app/src/main/java/com/lipisoft/toyshark/socket/SocketNIODataService.kt b/app/src/main/java/com/lipisoft/toyshark/socket/SocketNIODataService.kt index c08c2e1..ec7a42f 100755 --- a/app/src/main/java/com/lipisoft/toyshark/socket/SocketNIODataService.kt +++ b/app/src/main/java/com/lipisoft/toyshark/socket/SocketNIODataService.kt @@ -77,6 +77,7 @@ class SocketNIODataService(private val clientPacketWriter: ClientPacketWriter) : if (shutdown) { break } + synchronized(syncSelector2) { val iterator = selector!!.selectedKeys().iterator() while (iterator.hasNext()) { diff --git a/app/src/main/java/com/lipisoft/toyshark/socket/SocketProtector.kt b/app/src/main/java/com/lipisoft/toyshark/socket/SocketProtector.kt index e6a3bd4..9749d88 100755 --- a/app/src/main/java/com/lipisoft/toyshark/socket/SocketProtector.kt +++ b/app/src/main/java/com/lipisoft/toyshark/socket/SocketProtector.kt @@ -63,10 +63,6 @@ class SocketProtector { protector!!.protectSocket(socket) } - fun protect(socket: Int) { - protector!!.protectSocket(socket) - } - fun protect(socket: DatagramSocket) { protector!!.protectSocket(socket) } diff --git a/app/src/main/java/com/lipisoft/toyshark/transport/udp/UDPPacketFactory.kt b/app/src/main/java/com/lipisoft/toyshark/transport/udp/UDPPacketFactory.kt index 29ffaf3..f2cef51 100755 --- a/app/src/main/java/com/lipisoft/toyshark/transport/udp/UDPPacketFactory.kt +++ b/app/src/main/java/com/lipisoft/toyshark/transport/udp/UDPPacketFactory.kt @@ -25,13 +25,6 @@ object UDPPacketFactory { return UDPHeader(srcPort, destPort, length, checksum) } - fun copyHeader(header: UDPHeader): UDPHeader { - return UDPHeader(header.sourcePort, - header.destinationPort, - header.length, - header.checksum) - } - /** * create packet data for responding to vpn client * diff --git a/app/src/main/java/com/lipisoft/toyshark/util/ByteUtils.kt b/app/src/main/java/com/lipisoft/toyshark/util/ByteUtils.kt index 26ac2a4..e3ef5ba 100644 --- a/app/src/main/java/com/lipisoft/toyshark/util/ByteUtils.kt +++ b/app/src/main/java/com/lipisoft/toyshark/util/ByteUtils.kt @@ -325,7 +325,7 @@ class ByteUtils { * @param num target number will be changed * @return flipped representation. */ - fun flip16(num: Int): Int { + private fun flip16(num: Int): Int { return (num and 0x00FF shl 8) + (num and 0xFF00 shr 8) } diff --git a/app/src/main/java/com/lipisoft/toyshark/util/PacketUtil.kt b/app/src/main/java/com/lipisoft/toyshark/util/PacketUtil.kt index 7555eb7..c5d2899 100755 --- a/app/src/main/java/com/lipisoft/toyshark/util/PacketUtil.kt +++ b/app/src/main/java/com/lipisoft/toyshark/util/PacketUtil.kt @@ -17,12 +17,10 @@ package com.lipisoft.toyshark.util import java.net.Inet4Address -import java.net.InetAddress import java.net.NetworkInterface import java.net.SocketException import java.nio.ByteBuffer import java.nio.ByteOrder -import java.util.Enumeration import android.util.Log import com.lipisoft.toyshark.network.ip.IPv4Header @@ -296,7 +294,7 @@ object PacketUtil { "\r\nIP Header length: " + ipheader.ipHeaderLength + "\r\nIP checksum: " + ipheader.headerChecksum + "\r\nMay fragement? " + ipheader.isMayFragment + - "\r\nLast fragment? " + ipheader.isLastFragment + + "\r\nLast fragment? " + ipheader.lastFragment + "\r\nFlag: " + ipheader.flag + "\r\nFragment Offset: " + ipheader.fragmentOffset + "\r\nDest: " + intToIPAddress(ipheader.destinationIP) + @@ -346,7 +344,7 @@ object PacketUtil { .append("\r\nTCP Checksum: ").append(tcpheader.checksum) .append("\r\nIs Valid TCP checksum: ").append(isValidChecksum) .append("\r\nMay fragement? ").append(ipHeader.isMayFragment) - .append("\r\nLast fragment? ").append(ipHeader.isLastFragment) + .append("\r\nLast fragment? ").append(ipHeader.lastFragment) .append("\r\nFlag: ").append(ipHeader.flag.toInt()) .append("\r\nFragment Offset: ").append(ipHeader.fragmentOffset.toInt()) .append("\r\nWindow: ").append(tcpheader.windowSize)