Skip to content

Commit

Permalink
阻止模块被 SpringContext 扫描加载,我们手动加载他们
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Aug 17, 2024
1 parent 469fd4f commit 0861089
Show file tree
Hide file tree
Showing 30 changed files with 98 additions and 41 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/ghostchu/peerbanhelper/AppConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ghostchu.peerbanhelper;

import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.simplereloadlib.ReloadManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
Expand All @@ -9,7 +10,7 @@
import java.io.File;

@Configuration
@ComponentScan("com.ghostchu.peerbanhelper")
@ComponentScan(value = "com.ghostchu.peerbanhelper", excludeFilters = @ComponentScan.Filter(IgnoreScan.class))
@Slf4j
public class AppConfig {
@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ private void validate() {
// }
}

@UpdateScript(version = 17)
public void windowsEcoQoSApi() {
conf.set("performance.windows-ecoqos-api", true);
}

@UpdateScript(version = 16)
public void fixNonProxyHosts() {
if (!conf.isSet("proxy.non-proxy-hosts")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,36 @@ public List<ProgressCheatBlocker.ClientTask> fetchFromDatabase(ProgressCheatBloc
public void flushDatabase(List<ProgressCheatBlocker.ClientTaskRecord> records) throws SQLException {
callBatchTasks(() -> {
records.forEach(record -> {
String torrentId = record.client().getTorrentId();
record.task().forEach(task -> {
try {
var entity = findExists(task.getPeerIp(), torrentId);
if (entity == null) {
entity = new ProgressCheatBlockerPersistEntity(null,
task.getPeerIp(),
torrentId,
task.getLastReportProgress(),
task.getLastReportUploaded(),
task.getTrackingUploadedIncreaseTotal(),
task.getRewindCounter(),
task.getProgressDifferenceCounter(),
new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis())
);
create(entity);
} else {
entity.setLastReportProgress(task.getLastReportProgress());
entity.setLastReportUploaded(task.getLastReportUploaded());
entity.setProgressDifferenceCounter(task.getProgressDifferenceCounter());
entity.setRewindCounter(task.getRewindCounter());
entity.setTrackingUploadedIncreaseTotal(task.getTrackingUploadedIncreaseTotal());
entity.setLastTimeSeen(new Timestamp(System.currentTimeMillis()));
update(entity);
}
} catch (SQLException e) {
log.error("Unable write PCB persist data into database", e);
String torrentId = record.client().getTorrentId();
record.task().forEach(task -> {
try {
var entity = findExists(task.getPeerIp(), torrentId);
if (entity == null) {
entity = new ProgressCheatBlockerPersistEntity(null,
task.getPeerIp(),
torrentId,
task.getLastReportProgress(),
task.getLastReportUploaded(),
task.getTrackingUploadedIncreaseTotal(),
task.getRewindCounter(),
task.getProgressDifferenceCounter(),
new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis())
);
create(entity);
} else {
entity.setLastReportProgress(task.getLastReportProgress());
entity.setLastReportUploaded(task.getLastReportUploaded());
entity.setProgressDifferenceCounter(task.getProgressDifferenceCounter());
entity.setRewindCounter(task.getRewindCounter());
entity.setTrackingUploadedIncreaseTotal(task.getTrackingUploadedIncreaseTotal());
entity.setLastTimeSeen(new Timestamp(System.currentTimeMillis()));
update(entity);
}
});
} catch (SQLException e) {
log.error("Unable write PCB persist data into database", e);
}
});
});
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ghostchu.peerbanhelper.module.AbstractFeatureModule;
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.util.MiscUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.simplereloadlib.ReloadResult;
import com.ghostchu.simplereloadlib.Reloadable;
import com.google.common.cache.Cache;
Expand All @@ -28,6 +29,7 @@

@Slf4j
@Component
@IgnoreScan
public class ActiveMonitoringModule extends AbstractFeatureModule implements Reloadable {
private final PeerRecordDao peerRecordDao;
private final Deque<PeerRecordDao.BatchHandleTasks> dataBuffer = new ConcurrentLinkedDeque<>();
Expand Down Expand Up @@ -127,10 +129,10 @@ private void writeJournal() {
long uploaded = 0;
long downloaded = 0;
if (data != null) {
if(data[0]!=null && !data[0].isBlank()){
if (data[0] != null && !data[0].isBlank()) {
uploaded = Long.parseLong(data[0]);
}
if(data[1]!=null && !data[1].isBlank()){
if (data[1] != null && !data[1].isBlank()) {
downloaded = Long.parseLong(data[1]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.wrapper.StdResp;
Expand All @@ -28,6 +29,7 @@

@Slf4j
@Component
@IgnoreScan
public class AutoRangeBan extends AbstractRuleFeatureModule implements Reloadable {
@Autowired
private PeerBanHelperServer peerBanHelperServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.NullUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.util.rule.Rule;
import com.ghostchu.peerbanhelper.util.rule.RuleMatchResult;
import com.ghostchu.peerbanhelper.util.rule.RuleParser;
Expand All @@ -29,6 +30,7 @@

@Slf4j
@Component
@IgnoreScan
public class BtnNetworkOnline extends AbstractRuleFeatureModule implements Reloadable {
private final CheckResult BTN_MANAGER_NOT_INITIALIZED = new CheckResult(getClass(), PeerAction.NO_ACTION, 0, new TranslationComponent(Lang.GENERAL_NA), new TranslationComponent("BtnManager not initialized"));
@Autowired(required = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.util.rule.Rule;
import com.ghostchu.peerbanhelper.util.rule.RuleMatchResult;
import com.ghostchu.peerbanhelper.util.rule.RuleParser;
Expand All @@ -28,6 +29,7 @@

@Getter
@Component
@IgnoreScan
public class ClientNameBlacklist extends AbstractRuleFeatureModule implements Reloadable {
private List<Rule> bannedPeers;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
import com.ghostchu.peerbanhelper.module.CheckResult;
import com.ghostchu.peerbanhelper.module.PeerAction;
import com.ghostchu.peerbanhelper.peer.Peer;
import com.ghostchu.peerbanhelper.peer.PeerImpl;
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.torrent.TorrentImpl;
import com.ghostchu.peerbanhelper.util.HTTPUtil;
import com.ghostchu.peerbanhelper.util.IPAddressUtil;
import com.ghostchu.peerbanhelper.util.StrUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.util.json.JsonUtil;
import com.ghostchu.peerbanhelper.util.time.InfoHashUtil;
import com.ghostchu.peerbanhelper.wrapper.PeerAddress;
import com.ghostchu.simplereloadlib.ReloadResult;
import com.ghostchu.simplereloadlib.Reloadable;
import com.googlecode.aviator.AviatorEvaluator;
Expand Down Expand Up @@ -54,6 +52,7 @@

@Slf4j
@Component
@IgnoreScan
public class ExpressionRule extends AbstractRuleFeatureModule implements Reloadable {
private final long maxScriptExecuteTime = 1500;
private final Map<ExpressionMetadata, ReentrantLock> threadLocks = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.IPAddressUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.wrapper.StdResp;
Expand All @@ -33,6 +34,7 @@

@Slf4j
@Component
@IgnoreScan
public class IPBlackList extends AbstractRuleFeatureModule implements Reloadable {
private Set<IPAddress> ips;
private Set<Integer> ports;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.HTTPUtil;
import com.ghostchu.peerbanhelper.util.IPAddressUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.util.paging.Page;
import com.ghostchu.peerbanhelper.util.paging.Pageable;
import com.ghostchu.peerbanhelper.util.rule.MatchResult;
Expand Down Expand Up @@ -58,6 +59,7 @@
@Slf4j
@Component
@Getter
@IgnoreScan
public class IPBlackRuleList extends AbstractRuleFeatureModule implements Reloadable {
private final RuleSubLogsDao ruleSubLogsDao;
private List<IPMatcher> ipBanMatchers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.IPAddressUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.wrapper.StdResp;
Expand All @@ -34,6 +35,7 @@
*/
@Slf4j
@Component
@IgnoreScan
public class MultiDialingBlocker extends AbstractRuleFeatureModule implements Reloadable {
// 计算缓存容量
private static final int TORRENT_PEER_MAX_NUM = 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.util.rule.Rule;
import com.ghostchu.peerbanhelper.util.rule.RuleMatchResult;
import com.ghostchu.peerbanhelper.util.rule.RuleParser;
Expand All @@ -26,6 +27,7 @@
import java.util.concurrent.ExecutorService;

@Component
@IgnoreScan
public class PeerIdBlacklist extends AbstractRuleFeatureModule implements Reloadable {
private List<Rule> bannedPeers;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.util.IPAddressUtil;
import com.ghostchu.peerbanhelper.util.MsgUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.wrapper.StdResp;
Expand All @@ -37,6 +38,7 @@

@Component
@Slf4j
@IgnoreScan
public class ProgressCheatBlocker extends AbstractRuleFeatureModule implements Reloadable {
private final Deque<ClientTaskRecord> pendingPersistQueue = new ConcurrentLinkedDeque<>();
private final Cache<Client, List<ClientTask>> progressRecorder = CacheBuilder.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ghostchu.peerbanhelper.module.AbstractFeatureModule;
import com.ghostchu.peerbanhelper.util.IPAddressUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.wrapper.BanMetadata;
Expand All @@ -18,6 +19,7 @@
import java.util.UUID;

@Component
@IgnoreScan
public class BlockListController extends AbstractFeatureModule {
@Autowired
private JavalinWebContainer webContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ghostchu.peerbanhelper.alert.AlertManager;
import com.ghostchu.peerbanhelper.module.AbstractFeatureModule;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.wrapper.StdResp;
Expand All @@ -11,6 +12,7 @@
import org.springframework.stereotype.Component;

@Component
@IgnoreScan
public class PBHAlertController extends AbstractFeatureModule {
@Autowired
private AlertManager alertManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ghostchu.peerbanhelper.module.AbstractFeatureModule;
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.exception.NeedInitException;
Expand All @@ -20,6 +21,7 @@

@Component
@Slf4j
@IgnoreScan
public class PBHAuthenticateController extends AbstractFeatureModule {
@Autowired
private JavalinWebContainer webContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.ghostchu.peerbanhelper.database.table.HistoryEntity;
import com.ghostchu.peerbanhelper.metric.BasicMetrics;
import com.ghostchu.peerbanhelper.module.AbstractFeatureModule;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.util.paging.Page;
import com.ghostchu.peerbanhelper.util.paging.Pageable;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
Expand All @@ -31,6 +32,7 @@

@Slf4j
@Component
@IgnoreScan
public class PBHBanController extends AbstractFeatureModule {
@Autowired
private Database db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.util.MiscUtil;
import com.ghostchu.peerbanhelper.util.WebUtil;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.exception.RequirePBHPlusLicenseException;
Expand All @@ -35,6 +36,7 @@

@Component
@Slf4j
@IgnoreScan
public class PBHChartController extends AbstractFeatureModule {
@Autowired
private JavalinWebContainer webContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ghostchu.peerbanhelper.module.impl.webapi.dto.PopulatedPeerDTO;
import com.ghostchu.peerbanhelper.text.Lang;
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.wrapper.StdResp;
Expand All @@ -31,6 +32,7 @@

@Slf4j
@Component
@IgnoreScan
public class PBHDownloaderController extends AbstractFeatureModule {
@Autowired
private JavalinWebContainer webContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ghostchu.peerbanhelper.Main;
import com.ghostchu.peerbanhelper.module.AbstractFeatureModule;
import com.ghostchu.peerbanhelper.util.context.IgnoreScan;
import com.ghostchu.peerbanhelper.web.JavalinWebContainer;
import com.ghostchu.peerbanhelper.web.Role;
import com.ghostchu.peerbanhelper.web.wrapper.StdResp;
Expand All @@ -15,6 +16,7 @@
import java.util.List;

@Component
@IgnoreScan
public class PBHGeneralController extends AbstractFeatureModule {
@Autowired
private JavalinWebContainer webContainer;
Expand Down
Loading

0 comments on commit 0861089

Please sign in to comment.