Добавлена возможность задать направление паттерна
This commit is contained in:
@@ -34,6 +34,8 @@ public class Pattern {
|
|||||||
|
|
||||||
private boolean isRegex;
|
private boolean isRegex;
|
||||||
|
|
||||||
|
private PatternType type;
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "foundPatterns", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@ManyToMany(mappedBy = "foundPatterns", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private List<Stream> matchedStreams;
|
private List<Stream> matchedStreams;
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package ru.serega6531.packmate.model;
|
||||||
|
|
||||||
|
public enum PatternType {
|
||||||
|
INPUT, OUTPUT, BOTH
|
||||||
|
}
|
||||||
@@ -2,6 +2,12 @@ package ru.serega6531.packmate.repository;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.serega6531.packmate.model.Pattern;
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
|
import ru.serega6531.packmate.model.PatternType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface PatternRepository extends JpaRepository<Pattern, Integer> {
|
public interface PatternRepository extends JpaRepository<Pattern, Integer> {
|
||||||
|
|
||||||
|
List<Pattern> findAllByTypeEqualsOrTypeEquals(PatternType type, PatternType both);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Lazy;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.serega6531.packmate.model.Pattern;
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
|
import ru.serega6531.packmate.model.PatternType;
|
||||||
import ru.serega6531.packmate.model.Stream;
|
import ru.serega6531.packmate.model.Stream;
|
||||||
import ru.serega6531.packmate.repository.PatternRepository;
|
import ru.serega6531.packmate.repository.PatternRepository;
|
||||||
|
|
||||||
@@ -35,10 +36,10 @@ public class PatternService {
|
|||||||
return repository.findAll();
|
return repository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Pattern> findMatching(byte[] bytes) {
|
public List<Pattern> findMatching(byte[] bytes, boolean incoming) {
|
||||||
String content = new String(bytes);
|
String content = new String(bytes);
|
||||||
|
|
||||||
return findAll().stream()
|
return repository.findAllByTypeEqualsOrTypeEquals(incoming ? PatternType.INPUT : PatternType.OUTPUT, PatternType.BOTH).stream()
|
||||||
.filter(pattern -> matches(pattern, content))
|
.filter(pattern -> matches(pattern, content))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ public class StreamService {
|
|||||||
for (ru.serega6531.packmate.model.Packet packet : packets) {
|
for (ru.serega6531.packmate.model.Packet packet : packets) {
|
||||||
packet.setStream(savedStream);
|
packet.setStream(savedStream);
|
||||||
savedPackets.add(packetService.save(packet));
|
savedPackets.add(packetService.save(packet));
|
||||||
matches.addAll(patternService.findMatching(packet.getContent()));
|
matches.addAll(patternService.findMatching(packet.getContent(), packet.isIncoming()));
|
||||||
}
|
}
|
||||||
|
|
||||||
savedStream.setFoundPatterns(new ArrayList<>(matches));
|
savedStream.setFoundPatterns(new ArrayList<>(matches));
|
||||||
|
|||||||
Reference in New Issue
Block a user