Рефакторинг
This commit is contained in:
10
README_EN.md
10
README_EN.md
@@ -86,7 +86,7 @@ If everything went fine, Packmate will be available on port `65000` from any hos
|
|||||||
When you open a web interface for the first time, you will be asked for a login and password
|
When you open a web interface for the first time, you will be asked for a login and password
|
||||||
you specified in the env file.
|
you specified in the env file.
|
||||||
After entering the credentials, open the settings by clicking on the cogs
|
After entering the credentials, open the settings by clicking on the cogs
|
||||||
in the top right corner and enter login and password again.
|
in the top right corner and enter the specified login and password again.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -109,10 +109,10 @@ you can click a button in the sidebar to switch between binary and text views.
|
|||||||
|
|
||||||
### Shortcuts
|
### Shortcuts
|
||||||
To quickly navigate streams you can use the following shortcuts:
|
To quickly navigate streams you can use the following shortcuts:
|
||||||
* `Ctrl+Up` -- go to next stream
|
* `Ctrl+Up` -- go to the next stream
|
||||||
* `Ctrl+Down` -- go to previous stream
|
* `Ctrl+Down` -- go to the previous stream
|
||||||
* `Ctrl+Home` -- go to latest stream
|
* `Ctrl+Home` -- go to the latest stream
|
||||||
* `Ctrl+End` -- go to first stream
|
* `Ctrl+End` -- go to the first stream
|
||||||
|
|
||||||
<div align="right">
|
<div align="right">
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.web.socket.WebSocketSession;
|
|||||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||||
import ru.serega6531.packmate.service.SubscriptionService;
|
import ru.serega6531.packmate.service.SubscriptionService;
|
||||||
|
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
@Component
|
@Component
|
||||||
public class WebSocketHandler extends TextWebSocketHandler {
|
public class WebSocketHandler extends TextWebSocketHandler {
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import java.util.Map;
|
|||||||
@Getter
|
@Getter
|
||||||
public class CountersHolder {
|
public class CountersHolder {
|
||||||
|
|
||||||
private Map<Integer, Integer> servicesPackets;
|
private final Map<Integer, Integer> servicesPackets;
|
||||||
private Map<Integer, Integer> servicesStreams;
|
private final Map<Integer, Integer> servicesStreams;
|
||||||
|
|
||||||
private int totalPackets;
|
private final int totalPackets;
|
||||||
private int totalStreams;
|
private final int totalStreams;
|
||||||
|
|
||||||
public CountersHolder(Map<Integer, Integer> servicesPackets, Map<Integer, Integer> servicesStreams,
|
public CountersHolder(Map<Integer, Integer> servicesPackets, Map<Integer, Integer> servicesStreams,
|
||||||
int totalPackets, int totalStreams) {
|
int totalPackets, int totalStreams) {
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import java.net.Inet4Address;
|
|||||||
@Getter
|
@Getter
|
||||||
public class UnfinishedStream {
|
public class UnfinishedStream {
|
||||||
|
|
||||||
private Inet4Address firstIp;
|
private final Inet4Address firstIp;
|
||||||
private Inet4Address secondIp;
|
private final Inet4Address secondIp;
|
||||||
private int firstPort;
|
private final int firstPort;
|
||||||
private int secondPort;
|
private final int secondPort;
|
||||||
private Protocol protocol;
|
private final Protocol protocol;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ public class FilePcapWorker extends AbstractPcapWorker {
|
|||||||
gotPacket(packet);
|
gotPacket(packet);
|
||||||
} catch (PcapNativeException e) {
|
} catch (PcapNativeException e) {
|
||||||
log.error("Pcap read error: {}", e.getMessage());
|
log.error("Pcap read error: {}", e.getMessage());
|
||||||
Thread.sleep(100);
|
//noinspection BusyWait
|
||||||
|
Thread.sleep(100); // чтобы ошибки не летели слишком быстро
|
||||||
} catch (EOFException e) {
|
} catch (EOFException e) {
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public class CountingService {
|
|||||||
|
|
||||||
private final SubscriptionService subscriptionService;
|
private final SubscriptionService subscriptionService;
|
||||||
|
|
||||||
private Map<Integer, Counter> servicesPackets = new HashMap<>();
|
private final Map<Integer, Counter> servicesPackets = new HashMap<>();
|
||||||
private Map<Integer, Counter> servicesStreams = new HashMap<>();
|
private final Map<Integer, Counter> servicesStreams = new HashMap<>();
|
||||||
|
|
||||||
private Counter totalPackets = new Counter();
|
private Counter totalPackets = new Counter();
|
||||||
private Counter totalStreams = new Counter();
|
private Counter totalStreams = new Counter();
|
||||||
|
|||||||
@@ -32,15 +32,9 @@ class PatternMatcher {
|
|||||||
|
|
||||||
private void match(Pattern pattern) {
|
private void match(Pattern pattern) {
|
||||||
switch (pattern.getSearchType()) {
|
switch (pattern.getSearchType()) {
|
||||||
case REGEX:
|
case REGEX -> matchRegex(pattern);
|
||||||
matchRegex(pattern);
|
case SUBSTRING -> matchSubstring(pattern);
|
||||||
break;
|
case SUBBYTES -> matchSubbytes(pattern);
|
||||||
case SUBSTRING:
|
|
||||||
matchSubstring(pattern);
|
|
||||||
break;
|
|
||||||
case SUBBYTES:
|
|
||||||
matchSubbytes(pattern);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class HttpChunksProcessor {
|
public class HttpChunksProcessor {
|
||||||
|
|
||||||
private List<Packet> packets;
|
private final List<Packet> packets;
|
||||||
|
|
||||||
public void processChunkedEncoding() {
|
public void processChunkedEncoding() {
|
||||||
boolean chunkStarted = false;
|
boolean chunkStarted = false;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class HttpGzipProcessor {
|
|||||||
|
|
||||||
private static final byte[] GZIP_HEADER = {0x1f, (byte) 0x8b, 0x08};
|
private static final byte[] GZIP_HEADER = {0x1f, (byte) 0x8b, 0x08};
|
||||||
|
|
||||||
private List<Packet> packets;
|
private final List<Packet> packets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Попытаться распаковать GZIP из исходящих http пакетов. <br>
|
* Попытаться распаковать GZIP из исходящих http пакетов. <br>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class HttpUrldecodeProcessor {
|
public class HttpUrldecodeProcessor {
|
||||||
|
|
||||||
private List<Packet> packets;
|
private final List<Packet> packets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Декодирование urlencode с http пакета до смены стороны или окончания стрима
|
* Декодирование urlencode с http пакета до смены стороны или окончания стрима
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PacketsMerger {
|
public class PacketsMerger {
|
||||||
|
|
||||||
private List<Packet> packets;
|
private final List<Packet> packets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сжать соседние пакеты в одном направлении в один.
|
* Сжать соседние пакеты в одном направлении в один.
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import lombok.experimental.UtilityClass;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class Bytes {
|
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);
|
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) {
|
if (target.length == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.Optional;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class PacketUtils {
|
public class PacketUtils {
|
||||||
|
|
||||||
public static Optional<byte[]> mergePackets(List<Packet> cut) {
|
public Optional<byte[]> mergePackets(List<Packet> cut) {
|
||||||
return cut.stream()
|
return cut.stream()
|
||||||
.map(Packet::getContent)
|
.map(Packet::getContent)
|
||||||
.reduce(ArrayUtils::addAll);
|
.reduce(ArrayUtils::addAll);
|
||||||
|
|||||||
Reference in New Issue
Block a user