Рефакторинг
This commit is contained in:
@@ -27,8 +27,8 @@ dependencies {
|
|||||||
implementation 'org.springframework.session:spring-session-core'
|
implementation 'org.springframework.session:spring-session-core'
|
||||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
||||||
compile group: 'commons-io', name: 'commons-io', version: '2.6'
|
compile group: 'commons-io', name: 'commons-io', version: '2.6'
|
||||||
compile 'org.pcap4j:pcap4j-core:1.+'
|
compile 'org.pcap4j:pcap4j-core:1.8.2'
|
||||||
compile 'org.pcap4j:pcap4j-packetfactory-static:1.+'
|
compile 'org.pcap4j:pcap4j-packetfactory-static:1.8.2'
|
||||||
compile group: 'com.google.guava', name: 'guava', version: '28.2-jre'
|
compile group: 'com.google.guava', name: 'guava', version: '28.2-jre'
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
|
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ public class ApplicationConfiguration extends WebSecurityConfigurerAdapter imple
|
|||||||
@Autowired
|
@Autowired
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication()
|
||||||
.withUser(login).password(passwordEncoder().encode(password))
|
.withUser(login)
|
||||||
|
.password(passwordEncoder().encode(password))
|
||||||
.authorities("ROLE_USER");
|
.authorities("ROLE_USER");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class PcapWorker implements PacketListener {
|
|||||||
|
|
||||||
private final ListMultimap<UnfinishedStream, ru.serega6531.packmate.model.Packet> unfinishedStreams = ArrayListMultimap.create();
|
private final ListMultimap<UnfinishedStream, ru.serega6531.packmate.model.Packet> unfinishedStreams = ArrayListMultimap.create();
|
||||||
|
|
||||||
// в следующих мапах в Set находится srcIp соответствующего пакета
|
// в следующих мапах в значениях находится srcIp соответствующего пакета
|
||||||
private final SetMultimap<UnfinishedStream, ImmutablePair<Inet4Address, Integer>> fins = HashMultimap.create();
|
private final SetMultimap<UnfinishedStream, ImmutablePair<Inet4Address, Integer>> fins = HashMultimap.create();
|
||||||
private final SetMultimap<UnfinishedStream, ImmutablePair<Inet4Address, Integer>> acks = HashMultimap.create();
|
private final SetMultimap<UnfinishedStream, ImmutablePair<Inet4Address, Integer>> acks = HashMultimap.create();
|
||||||
|
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ class StreamOptimizer {
|
|||||||
Packet packet = packets.get(i);
|
Packet packet = packets.get(i);
|
||||||
if (packet.isIncoming() != incoming) {
|
if (packet.isIncoming() != incoming) {
|
||||||
if (packetsInRow > 1) {
|
if (packetsInRow > 1) {
|
||||||
final List<Packet> cut = packets.subList(start, i);
|
compress(start, i);
|
||||||
compress(cut, incoming);
|
|
||||||
|
|
||||||
i++; // продвигаем указатель на следующий после склеенного блок
|
i++; // продвигаем указатель на следующий после склеенного блок
|
||||||
}
|
}
|
||||||
@@ -73,17 +72,18 @@ class StreamOptimizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (packetsInRow > 1) {
|
if (packetsInRow > 1) {
|
||||||
final List<Packet> cut = packets.subList(start, packets.size());
|
compress(start, packets.size());
|
||||||
compress(cut, incoming);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сжать кусок cut в один пакет
|
* Сжать кусок со start по end в один пакет
|
||||||
*/
|
*/
|
||||||
private void compress(List<Packet> cut, boolean incoming) {
|
private void compress(int start, int end) {
|
||||||
|
final List<Packet> cut = packets.subList(start, end);
|
||||||
final long timestamp = cut.get(0).getTimestamp();
|
final long timestamp = cut.get(0).getTimestamp();
|
||||||
final boolean ungzipped = cut.stream().anyMatch(Packet::isUngzipped);
|
final boolean ungzipped = cut.stream().anyMatch(Packet::isUngzipped);
|
||||||
|
boolean incoming = cut.get(0).isIncoming();
|
||||||
//noinspection OptionalGetWithoutIsPresent
|
//noinspection OptionalGetWithoutIsPresent
|
||||||
final byte[] content = cut.stream()
|
final byte[] content = cut.stream()
|
||||||
.map(Packet::getContent)
|
.map(Packet::getContent)
|
||||||
@@ -91,7 +91,7 @@ class StreamOptimizer {
|
|||||||
.get();
|
.get();
|
||||||
|
|
||||||
packets.removeAll(cut);
|
packets.removeAll(cut);
|
||||||
packets.add(Packet.builder()
|
packets.add(start, Packet.builder()
|
||||||
.incoming(incoming)
|
.incoming(incoming)
|
||||||
.timestamp(timestamp)
|
.timestamp(timestamp)
|
||||||
.ungzipped(ungzipped)
|
.ungzipped(ungzipped)
|
||||||
@@ -176,6 +176,7 @@ class StreamOptimizer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Попытаться распаковать кусок пакетов с gzip body и вставить результат на их место
|
* Попытаться распаковать кусок пакетов с gzip body и вставить результат на их место
|
||||||
|
*
|
||||||
* @return получилось ли распаковать
|
* @return получилось ли распаковать
|
||||||
*/
|
*/
|
||||||
private boolean extractGzip(int gzipStartPacket, int gzipEndPacket) {
|
private boolean extractGzip(int gzipStartPacket, int gzipEndPacket) {
|
||||||
|
|||||||
Reference in New Issue
Block a user