Skip to content

Commit

Permalink
fix MTU
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Aug 5, 2015
1 parent c31a5c1 commit de7e516
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.shadowsocks"
android:versionCode="113"
android:versionName="2.7.5">
android:versionCode="114"
android:versionName="2.7.6">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand Down
23 changes: 14 additions & 9 deletions src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {

private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]
val TAG = "ShadowsocksVpnService"
val VPN_MTU = 1400
val VPN_MTU = 1500
val PRIVATE_VLAN = "26.26.26.%s"
var conn: ParcelFileDescriptor = null
var notificationManager: NotificationManager = null
Expand Down Expand Up @@ -103,21 +103,13 @@ class ShadowsocksVpnService extends VpnService with BaseService {
null
}

override def onDestroy() {
super.onDestroy()
if (vpnThread != null) vpnThread.stopThread()
}

override def onCreate() {
super.onCreate()

ConfigUtils.refresh(this)

notificationManager = getSystemService(Context.NOTIFICATION_SERVICE)
.asInstanceOf[NotificationManager]

vpnThread = new ShadowsocksVpnThread(this)
vpnThread.start()
}

override def onRevoke() {
Expand All @@ -126,6 +118,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {

override def stopRunner() {

if (vpnThread != null) {
vpnThread.stopThread()
vpnThread = null
}

// channge the state
changeState(State.STOPPING)

Expand Down Expand Up @@ -185,6 +182,14 @@ class ShadowsocksVpnService extends VpnService with BaseService {

override def startRunner(c: Config) {

if (vpnThread != null) {
vpnThread.stopThread()
vpnThread = null
}

vpnThread = new ShadowsocksVpnThread(this)
vpnThread.start()

config = c

// ensure the VPNService is prepared
Expand Down
24 changes: 11 additions & 13 deletions src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,43 +45,38 @@ import java.util.concurrent.Executors
import android.net.{LocalServerSocket, LocalSocket, LocalSocketAddress}
import android.util.Log

object ShadowsocksVpn {
@volatile var serverSocket: LocalServerSocket = null
}

class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {

val TAG = "ShadowsocksVpnService"
val PATH = "shadowsocks_protect"

var isRunning: Boolean = true
var serverSocket: LocalServerSocket = null

def stopThread() {
isRunning = false
if (serverSocket != null) {
serverSocket.close()
serverSocket = null
}
}

override def run(): Unit = {

try {
if (serverSocket != null) {
serverSocket.close()
serverSocket = null
if (ShadowsocksVpn.serverSocket == null) {
ShadowsocksVpn.serverSocket = new LocalServerSocket(PATH)
}
serverSocket = new LocalServerSocket(PATH)
} catch {
case e: IOException =>
Log.e(TAG, "unable to bind", e)
vpnService.stopBackgroundService()
return
}

val pool = Executors.newFixedThreadPool(4)

while (isRunning) {

try {
val socket = serverSocket.accept()
val socket = ShadowsocksVpn.serverSocket.accept()

pool.execute(new Runnable {
override def run() {
Expand Down Expand Up @@ -126,7 +121,10 @@ class ShadowsocksVpnThread(vpnService: ShadowsocksVpnService) extends Thread {

}})
} catch {
case e: IOException => Log.e(TAG, "Error when accept socket", e)
case e: IOException => {
Log.e(TAG, "Error when accept socket", e)
return
}
}
}
}
Expand Down

0 comments on commit de7e516

Please sign in to comment.