Рефакторинг

This commit is contained in:
serega6531
2020-04-14 22:35:33 +03:00
parent 01a3c0e512
commit d975f425f8
13 changed files with 29 additions and 33 deletions

View File

@@ -7,6 +7,7 @@ import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import ru.serega6531.packmate.service.SubscriptionService;
@SuppressWarnings("NullableProblems")
@Component
public class WebSocketHandler extends TextWebSocketHandler {

View File

@@ -7,11 +7,11 @@ import java.util.Map;
@Getter
public class CountersHolder {
private Map<Integer, Integer> servicesPackets;
private Map<Integer, Integer> servicesStreams;
private final Map<Integer, Integer> servicesPackets;
private final Map<Integer, Integer> servicesStreams;
private int totalPackets;
private int totalStreams;
private final int totalPackets;
private final int totalStreams;
public CountersHolder(Map<Integer, Integer> servicesPackets, Map<Integer, Integer> servicesStreams,
int totalPackets, int totalStreams) {

View File

@@ -10,11 +10,11 @@ import java.net.Inet4Address;
@Getter
public class UnfinishedStream {
private Inet4Address firstIp;
private Inet4Address secondIp;
private int firstPort;
private int secondPort;
private Protocol protocol;
private final Inet4Address firstIp;
private final Inet4Address secondIp;
private final int firstPort;
private final int secondPort;
private final Protocol protocol;
@Override
public boolean equals(Object obj) {

View File

@@ -58,7 +58,8 @@ public class FilePcapWorker extends AbstractPcapWorker {
gotPacket(packet);
} catch (PcapNativeException e) {
log.error("Pcap read error: {}", e.getMessage());
Thread.sleep(100);
//noinspection BusyWait
Thread.sleep(100); // чтобы ошибки не летели слишком быстро
} catch (EOFException e) {
stop();

View File

@@ -17,8 +17,8 @@ public class CountingService {
private final SubscriptionService subscriptionService;
private Map<Integer, Counter> servicesPackets = new HashMap<>();
private Map<Integer, Counter> servicesStreams = new HashMap<>();
private final Map<Integer, Counter> servicesPackets = new HashMap<>();
private final Map<Integer, Counter> servicesStreams = new HashMap<>();
private Counter totalPackets = new Counter();
private Counter totalStreams = new Counter();

View File

@@ -32,15 +32,9 @@ class PatternMatcher {
private void match(Pattern pattern) {
switch (pattern.getSearchType()) {
case REGEX:
matchRegex(pattern);
break;
case SUBSTRING:
matchSubstring(pattern);
break;
case SUBBYTES:
matchSubbytes(pattern);
break;
case REGEX -> matchRegex(pattern);
case SUBSTRING -> matchSubstring(pattern);
case SUBBYTES -> matchSubbytes(pattern);
}
}

View File

@@ -15,7 +15,7 @@ import java.util.List;
@AllArgsConstructor
public class HttpChunksProcessor {
private List<Packet> packets;
private final List<Packet> packets;
public void processChunkedEncoding() {
boolean chunkStarted = false;

View File

@@ -22,7 +22,7 @@ public class HttpGzipProcessor {
private static final byte[] GZIP_HEADER = {0x1f, (byte) 0x8b, 0x08};
private List<Packet> packets;
private final List<Packet> packets;
/**
* Попытаться распаковать GZIP из исходящих http пакетов. <br>

View File

@@ -13,7 +13,7 @@ import java.util.List;
@Slf4j
public class HttpUrldecodeProcessor {
private List<Packet> packets;
private final List<Packet> packets;
/**
* Декодирование urlencode с http пакета до смены стороны или окончания стрима

View File

@@ -9,7 +9,7 @@ import java.util.List;
@AllArgsConstructor
public class PacketsMerger {
private List<Packet> packets;
private final List<Packet> packets;
/**
* Сжать соседние пакеты в одном направлении в один.

View File

@@ -5,11 +5,11 @@ import lombok.experimental.UtilityClass;
@UtilityClass
public class Bytes {
public static int indexOf(byte[] array, byte[] target) {
public int indexOf(byte[] array, byte[] target) {
return indexOf(array, target, 0, array.length);
}
public static int indexOf(byte[] array, byte[] target, int start, int end) {
public int indexOf(byte[] array, byte[] target, int start, int end) {
if (target.length == 0) {
return 0;
}

View File

@@ -10,7 +10,7 @@ import java.util.Optional;
@UtilityClass
public class PacketUtils {
public static Optional<byte[]> mergePackets(List<Packet> cut) {
public Optional<byte[]> mergePackets(List<Packet> cut) {
return cut.stream()
.map(Packet::getContent)
.reduce(ArrayUtils::addAll);