Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit b4c788b

Browse files
fix bug
1 parent 7348d32 commit b4c788b

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

common/src/main/java/com/ljh/common/model/ProxyAccount.java

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class ProxyAccount implements Serializable {
3030
private String id;
3131
/**
3232
* "alterId": 32
33+
* 兼用新版 alterId 0
34+
* alterID 是 v2ray 的一个安全特性,用于防止被识别和干扰。但是在最新的 v2ray 版本中,已经引入了更先进的安全机制,所以不再需要 alterID 了。
3335
*/
3436
private Integer alterId = 64;
3537
/**

vpn-admin/src/main/java/com/jhl/admin/controller/UserController.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ public Result deleteUser(@CookieValue(COOKIE_NAME) String auth, @PathVariable In
270270

271271

272272
userRepository.deleteById(id);
273-
if (accounts != null)
274-
accountRepository.deleteAll(accounts);
273+
accountRepository.deleteAll(accounts);
275274

276275
return Result.doSuccess();
277276
}

vpn-admin/src/main/java/com/jhl/admin/entity/V2rayAccount.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class V2rayAccount {
1616
* "add": "",
1717
* "port": "443",
1818
* "id": "976fdcba-fb53-44a1-d7e2-74e4c3de0020",
19-
* "aid": "64",
19+
* "aid": "0",
2020
* "net": "ws",
2121
* "type": "none",
2222
* "host": "",
@@ -31,7 +31,7 @@ public class V2rayAccount {
3131
private String add;
3232
private String port;
3333
private String id;
34-
private String aid = "64";
34+
private String aid = "0";
3535
private String net = "ws";
3636
private String type = "none";
3737
private String host ="";

vpn-admin/src/main/java/com/jhl/admin/model/Server.java

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class Server extends BaseEntity implements Serializable {
5555

5656
//ws路径
5757
private String wsPath ="/ws/%s/";
58+
//默认0
59+
private Integer alterId=0;
5860

5961

6062
}

vpn-admin/src/main/java/com/jhl/admin/service/StatService.java

+15-11
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ public Stat createOrGetStat(Account account){
2626
Date today = new Date();
2727
Stat stat = statRepository.findByAccountIdAndFromDateBeforeAndToDateAfter(account.getId(), today,today);
2828
if (stat == null){
29-
Date fromDate =Utils.formatDate(today,null);
29+
synchronized (Utils.getInternersPoll().intern(account.getAccountNo())){
30+
stat = statRepository.findByAccountIdAndFromDateBeforeAndToDateAfter(account.getId(), today,today);
31+
if (stat != null) return stat;
32+
Date fromDate =Utils.formatDate(today,null);
3033

31-
Integer cycleNum = account.getCycle();
32-
Date maxToDate = account.getToDate();
33-
Date nextCycleDate = Utils.getDateBy(fromDate,cycleNum, Calendar.DAY_OF_YEAR);
34-
if (!maxToDate.after(fromDate)) return null;
35-
stat = new Stat();
36-
stat.setAccountId(account.getId());
37-
stat.setFromDate(fromDate);
38-
stat.setToDate(nextCycleDate);
39-
stat.setFlow(0l);
40-
statRepository.save(stat);
34+
Integer cycleNum = account.getCycle();
35+
Date maxToDate = account.getToDate();
36+
Date nextCycleDate = Utils.getDateBy(fromDate,cycleNum, Calendar.DAY_OF_YEAR);
37+
if (!maxToDate.after(fromDate)) return null;
38+
stat = new Stat();
39+
stat.setAccountId(account.getId());
40+
stat.setFromDate(fromDate);
41+
stat.setToDate(nextCycleDate);
42+
stat.setFlow(0l);
43+
statRepository.save(stat);
44+
}
4145
}
4246
return stat;
4347
}

vpn-admin/src/main/java/com/jhl/admin/service/v2ray/ProxyEventService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ProxyEventService {
4040
@Autowired
4141
V2rayAccountService v2rayAccountService;
4242

43-
private LinkedBlockingQueue<ProxyEvent> queue = new LinkedBlockingQueue<>();
43+
private LinkedBlockingQueue<ProxyEvent> queue = new LinkedBlockingQueue<>(100);
4444

4545
public void addProxyEvent(List<? extends ProxyEvent> proxyEvents) {
4646
for (ProxyEvent proxyEvent : proxyEvents) {
@@ -81,13 +81,13 @@ public void start() {
8181
return;
8282
}
8383
} catch (InterruptedException e) {
84-
log.error("event InterruptedException :{}", e);
84+
log.error("event InterruptedException :", e);
8585
Thread.currentThread().interrupt();
8686

8787
break;
8888

8989
} catch (Exception e) {
90-
log.error("event 队列 抛出异常:{}", e);
90+
log.error("event 队列 抛出异常:", e);
9191
}
9292
}
9393

vpn-admin/src/main/java/com/jhl/admin/service/v2ray/V2RayProxyEvent.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.jhl.admin.service.v2ray;
22

33

4+
import com.alibaba.fastjson.JSON;
45
import com.google.common.collect.Lists;
56
import com.jhl.admin.entity.V2rayAccount;
67
import com.jhl.admin.model.Account;
@@ -15,6 +16,7 @@
1516
import org.springframework.http.ResponseEntity;
1617
import org.springframework.web.client.RestTemplate;
1718

19+
import java.io.Serializable;
1820
import java.util.List;
1921

2022
@Slf4j
@@ -95,9 +97,10 @@ public ProxyAccount buildProxyAccount() {
9597
= account.getUuid() == null ?
9698
v2rayAccountService.buildV2rayAccount(Lists.newArrayList(server), account).get(0).getId()
9799
: account.getUuid();
100+
V2rayAccount v2rayAccount = JSON.parseObject(account.getContent(), V2rayAccount.class);
98101
proxyAccount.setAccountId(account.getId());
99102
proxyAccount.setAccountNo(account.getAccountNo());
100-
proxyAccount.setAlterId(64);
103+
proxyAccount.setAlterId(server.getAlterId());
101104
proxyAccount.setDownTrafficLimit(account.getSpeed());
102105
proxyAccount.setEmail(email);
103106
proxyAccount.setId(id);

vpn-admin/src/main/java/com/jhl/admin/service/v2ray/V2rayAccountService.java

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public List<V2rayAccount> buildV2rayAccount(List<Server> servers, Account accoun
5454
v2rayAccount.setTls(s.getSupportTLS() ? "tls" : "");
5555
v2rayAccount.setHost("");
5656
v2rayAccount.setPs(s.getServerName());
57+
v2rayAccount.setAid(s.getAlterId()+"");
5758
result.add(v2rayAccount);
5859
}
5960
return result;

0 commit comments

Comments
 (0)