Skip to content

Commit

Permalink
修复花里胡哨
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Dec 31, 2024
1 parent feb03de commit 2547d94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import com.ghostchu.btn.sparkle.module.banhistory.internal.BanHistoryRepository;
import com.ghostchu.btn.sparkle.module.clientdiscovery.ClientDiscoveryService;
import com.ghostchu.btn.sparkle.module.clientdiscovery.ClientIdentity;
import com.ghostchu.btn.sparkle.util.*;
import com.ghostchu.btn.sparkle.util.IPMerger;
import com.ghostchu.btn.sparkle.util.IPUtil;
import com.ghostchu.btn.sparkle.util.PeerUtil;
import com.ghostchu.btn.sparkle.util.TimeUtil;
import inet.ipaddr.IPAddress;
import inet.ipaddr.format.util.DualIPv4v6Tries;
import io.micrometer.core.instrument.MeterRegistry;
Expand Down Expand Up @@ -265,13 +268,11 @@ private void scanFile(Consumer<Peer.PeerInfo> predicate, ExecutorService service
log.error("Tracker dump file not found: {}", dumpFilePath);
return;
}

try (FileInputStream fis = new FileInputStream(file); FileLock ignored = fis.getChannel().lock(0L, Long.MAX_VALUE, true)) {
LargeFileReader reader = new LargeFileReader(fis.getChannel());
while (reader.available() > 0) {
int sizeInIntNeedToFix = ByteBuffer.wrap(reader.read(4)).order(ByteOrder.LITTLE_ENDIAN).getInt();
while (fis.available() > 0) {
int sizeInIntNeedToFix = ByteBuffer.wrap(fis.readNBytes(4)).order(ByteOrder.LITTLE_ENDIAN).getInt();
long remainingToRead = Integer.toUnsignedLong(sizeInIntNeedToFix);
byte[] buffer = reader.read((int) remainingToRead);
byte[] buffer = fis.readNBytes((int) remainingToRead);
var peerInfo = Peer.PeerInfo.parseFrom(buffer);
service.submit(() -> predicate.accept(peerInfo));
}
Expand Down
100 changes: 0 additions & 100 deletions src/main/java/com/ghostchu/btn/sparkle/util/LargeFileReader.java

This file was deleted.

0 comments on commit 2547d94

Please sign in to comment.