Skip to content

Commit

Permalink
proxy: migrating ss to libv2ray
Browse files Browse the repository at this point in the history
  • Loading branch information
nexplorer-3e committed Aug 18, 2023
1 parent 3b20db0 commit 2a5887e
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 532 deletions.
2 changes: 1 addition & 1 deletion TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ android {
srcDirs "src/main/java", "src/gservcies/java"
}
jniLibs {
srcDir "src/main/libs"
srcDirs "src/main/libs", "jni"
}
manifest {
srcFile "src/gservcies/AndroidManifest.xml"
Expand Down
3 changes: 3 additions & 0 deletions TMessagesProj/src/main/java/com/v2ray/ang/V2RayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ object V2RayConfig {
@JvmField
val Trojan = 2

@JvmField
val Shadowsocks = 3

}

}
10 changes: 10 additions & 0 deletions TMessagesProj/src/main/java/com/v2ray/ang/dto/AngConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.v2ray.ang.dto
import cn.hutool.core.codec.Base64
import com.google.gson.Gson
import com.v2ray.ang.V2RayConfig
import com.v2ray.ang.V2RayConfig.SS_PROTOCOL
import com.v2ray.ang.V2RayConfig.SSR_PROTOCOL
import com.v2ray.ang.V2RayConfig.TROJAN_PROTOCOL
import com.v2ray.ang.V2RayConfig.VMESS_PROTOCOL
import com.v2ray.ang.util.Utils
Expand Down Expand Up @@ -59,6 +61,14 @@ data class AngConfig(

return VMESS_PROTOCOL + Base64.encode(Gson().toJson(vmessQRCode))

} else if (configType == V2RayConfig.EConfigType.Shadowsocks) {

val remark = "#" + Base64.encodeUrlSafe(remarks)

val url = String.format("%s:%s@%s:%s", security, id, address, port)

return SS_PROTOCOL + Base64.encode(url.toByteArray(charset("UTF-8"))) + remark

} else if (configType == V2RayConfig.EConfigType.Trojan) {

val params = if (requestHost.isNotBlank()) "?sni=" + Utils.urlEncode(requestHost) else ""
Expand Down
6 changes: 4 additions & 2 deletions TMessagesProj/src/main/java/com/v2ray/ang/dto/V2rayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ data class V2rayConfig(
data class ServersBean(var address: String,
var password: String,
var port: Int,
var email: String)

var email: String?,
var method: String?,
var ota: Boolean?,
var level: Int?)
}

data class StreamSettingsBean(var network: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ object V2rayConfigUtil {

outbound.protocol = "vmess"
}
V2RayConfig.EConfigType.Shadowsocks -> {
outbound.settings?.vnext = null

val server = outbound.settings?.servers?.get(0)
server?.address = vmess.address
server?.method = vmess.security
server?.ota = false
server?.password = vmess.id
server?.port = vmess.port
server?.level = 8

//Mux
outbound.mux?.enabled = false

outbound.protocol = "shadowsocks"
}
V2RayConfig.EConfigType.Trojan -> {

outbound.streamSettings = V2rayConfig.OutboundBean.StreamSettingsBean(
Expand All @@ -137,7 +153,7 @@ object V2rayConfigUtil {
vmess.address,
vmess.id,
vmess.port,
"[email protected]"
"[email protected]", null, null, null
)))

//Mux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3969,16 +3969,16 @@ public static void showShadowsocksAlert(Context activity, final SharedConfig.Sha
String text = null;
String detail = null;
if (a == 0) {
text = info.bean.getHost();
text = info.bean.getAddress();
detail = LocaleController.getString("UseProxyAddress", R.string.UseProxyAddress);
} else if (a == 1) {
text = "" + info.bean.getRemotePort();
text = "" + info.bean.getPort();
detail = LocaleController.getString("UseProxyPort", R.string.UseProxyPort);
} else if (a == 2) {
text = info.bean.getPassword();
text = info.bean.getId();
detail = LocaleController.getString("UseProxyPassword", R.string.UseProxyPassword);
} else if (a == 3) {
text = info.bean.getMethod();
text = info.bean.getSecurity();
detail = LocaleController.getString("SSMethod", R.string.SSMethod);
} else {
text = LocaleController.getString("Checking", R.string.Checking);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import okhttp3.HttpUrl;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.proxy.ProxyManager;
import tw.nekomimi.nekogram.proxy.ShadowsocksLoader;
import tw.nekomimi.nekogram.proxy.ShadowsocksRLoader;
import tw.nekomimi.nekogram.proxy.VmessLoader;
import tw.nekomimi.nekogram.proxy.tcp2ws.WsLoader;
Expand Down Expand Up @@ -723,83 +722,32 @@ public boolean equals(@Nullable Object obj) {

}

public static class ShadowsocksProxy extends ExternalSocks5Proxy {
public static class ShadowsocksProxy extends VmessProxy {

public ShadowsocksLoader.Bean bean;
public ShadowsocksLoader loader;
public AngConfig.VmessBean bean;
public VmessLoader loader;

public ShadowsocksProxy(String ssLink) {

this(ShadowsocksLoader.Bean.Companion.parse(ssLink));

this(VmessLoader.Companion.parseVmessLink(ssLink));
}

public ShadowsocksProxy(ShadowsocksLoader.Bean bean) {

public ShadowsocksProxy(AngConfig.VmessBean bean) {
this.bean = bean;

if (BuildVars.isMini) {

throw new RuntimeException(LocaleController.getString("MiniVersionAlert", R.string.MiniVersionAlert));

}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

throw new RuntimeException(LocaleController.getString("MinApi21Required", R.string.MinApi21Required));

}

}

@Override
public String getAddress() {
return bean.getHost() + ":" + bean.getRemotePort();
}

@Override
public boolean isStarted() {

return loader != null;

}

@Override
public void start() {

if (loader != null) return;

port = ProxyManager.mkPort();
ShadowsocksLoader loader = new ShadowsocksLoader();
loader.initConfig(bean, port);

loader.start();

this.loader = loader;

if (SharedConfig.proxyEnabled && SharedConfig.currentProxy == this) {

ConnectionsManager.setProxySettings(true, address, port, username, password, secret);

}

super.start();
}

@Override
public void stop() {

if (loader != null) {

FileLog.d(getTitle() + " stopped");

ShadowsocksLoader loader = this.loader;

loader.stop();

this.loader = null;

}

super.stop();
}

@Override
Expand Down Expand Up @@ -835,14 +783,12 @@ public JSONObject toJsonInternal() throws JSONException {

@Override
public int hashCode() {

return (bean.getHost() + bean.getRemotePort() + bean.getMethod()).hashCode();

return super.hashCode();
}

@Override
public boolean equals(@Nullable Object obj) {
return super.equals(obj) || (obj instanceof ShadowsocksProxy && bean.equals(((ShadowsocksProxy) obj).bean));
return super.equals(obj);
}

}
Expand Down
Loading

0 comments on commit 2a5887e

Please sign in to comment.