Skip to content

Commit

Permalink
对上报的 snapshot 中的本地地址在生成规则时进行过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Oct 6, 2024
1 parent 44cc2b3 commit d151363
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ghostchu.btn.sparkle.util.IPMerger;
import com.ghostchu.btn.sparkle.util.IPUtil;
import com.ghostchu.btn.sparkle.util.MsgUtil;
import inet.ipaddr.IPAddressString;
import jakarta.persistence.EntityManager;
import jakarta.persistence.LockModeType;
import jakarta.persistence.PersistenceContext;
Expand Down Expand Up @@ -127,12 +128,19 @@ AggregatedUploads AS (
var ips = ipMerger.merge(queryResult.stream().map(arr -> IPUtil.toString(((InetAddress) arr[1]))).collect(Collectors.toList()));
List<AnalysedRule> rules = new ArrayList<>();
for (String ip : ips) {
rules.add(new AnalysedRule(
null,
ip,
OVER_DOWNLOAD,
"Generated at " + MsgUtil.getNowDateTimeString()
));
try {
if (new IPAddressString(ip).getAddress().isLocal()) {
continue;
}
rules.add(new AnalysedRule(
null,
ip,
OVER_DOWNLOAD,
"Generated at " + MsgUtil.getNowDateTimeString()
));
} catch (Exception ignored) {

}
}
analysedRuleRepository.deleteAllByModule(OVER_DOWNLOAD);
analysedRuleRepository.saveAll(rules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public byte[] announce() {
Validate.isTrue(infoHash.length == 20);
Validate.notBlank(req.getParameter("peer_id"));
byte[] peerId = req.getParameter("peer_id").getBytes(StandardCharsets.ISO_8859_1);
String peerIp = Optional.ofNullable(req.getParameter("ip")).orElse(ip(req));
Validate.isTrue(StringUtils.isNumeric(req.getParameter("port")));
int port = Integer.parseInt(req.getParameter("port"));
Validate.isTrue(StringUtils.isNumeric(req.getParameter("uploaded")));
Expand Down

0 comments on commit d151363

Please sign in to comment.