-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
4,002 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
base/src/main/java/com/windscribe/vpn/api/CustomSocketFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.windscribe.vpn.api | ||
|
||
import com.windscribe.vpn.Windscribe | ||
import com.windscribe.vpn.apppreference.PreferencesHelper | ||
import com.windscribe.vpn.backend.wireguard.WireguardBackend | ||
import com.windscribe.vpn.exceptions.WindScribeException | ||
import com.windscribe.vpn.localdatabase.LocalDbInterface | ||
import com.windscribe.vpn.repository.LocationRepository | ||
import com.windscribe.vpn.repository.UserRepository | ||
import java.net.InetAddress | ||
import java.net.InetSocketAddress | ||
import java.net.Proxy | ||
import java.net.Socket | ||
import javax.inject.Singleton | ||
import javax.net.SocketFactory | ||
import kotlinx.coroutines.CoroutineScope | ||
import org.slf4j.LoggerFactory | ||
|
||
class CustomSocketFactory : SocketFactory() { | ||
private var logger = LoggerFactory.getLogger("socket_factory") | ||
override fun createSocket(): Socket { | ||
val socket = Socket(Proxy.NO_PROXY) | ||
try { | ||
socket.bind(InetSocketAddress(0)) | ||
val activeBackend = Windscribe.appContext.vpnController.vpnBackendHolder.activeBackend | ||
if (activeBackend is WireguardBackend && activeBackend.active) { | ||
val protected = activeBackend.service?.protect(socket) | ||
if(protected == false){ | ||
logger.debug("Failed to protect socket from wg tunnel") | ||
} | ||
} | ||
} catch (e: Exception) { | ||
logger.debug("Error creating socket: ${e.message}") | ||
} | ||
return socket | ||
} | ||
|
||
override fun createSocket(host: String?, port: Int): Socket { | ||
throw WindScribeException("Not supported") | ||
} | ||
|
||
override fun createSocket(host: String?, port: Int, localHost: InetAddress?, localPort: Int): Socket { | ||
throw WindScribeException("Not supported") | ||
} | ||
|
||
override fun createSocket(host: InetAddress?, port: Int): Socket { | ||
throw WindScribeException("Not supported") | ||
} | ||
|
||
override fun createSocket(address: InetAddress?, port: Int, localAddress: InetAddress?, localPort: Int): Socket { | ||
throw WindScribeException("Not supported") | ||
} | ||
} |
Oops, something went wrong.