Рефакторинг

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

@@ -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.
![Settings](screenshots/Screenshot_Settings.png) ![Settings](screenshots/Screenshot_Settings.png)
@@ -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">

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;
} }
} }

View File

@@ -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;

View File

@@ -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>

View File

@@ -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 пакета до смены стороны или окончания стрима

View File

@@ -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;
/** /**
* Сжать соседние пакеты в одном направлении в один. * Сжать соседние пакеты в одном направлении в один.

View File

@@ -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;
} }

View File

@@ -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);