From 34d7e9af736c299456785602715fceeb38775f10 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Wed, 19 Aug 2020 09:12:35 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A4=87=E4=BB=BDDP=E5=A4=84?= =?UTF-8?q?=E7=BD=AE=E8=AE=BE=E5=A4=87=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dispose/ability/AttackTypeTask.java | 39 ------ .../dispose/ability/AttackTypeTaskInfo.java | 27 ---- .../ability/DisposeAttackTypeTask.java | 33 ----- .../ability/impl/DpTechAbilityImpl.java | 127 +----------------- .../com/dispose/common/DpTechAttackType.java | 16 +++ 5 files changed, 17 insertions(+), 225 deletions(-) delete mode 100644 src/main/java/com/dispose/ability/AttackTypeTask.java delete mode 100644 src/main/java/com/dispose/ability/AttackTypeTaskInfo.java delete mode 100644 src/main/java/com/dispose/ability/DisposeAttackTypeTask.java diff --git a/src/main/java/com/dispose/ability/AttackTypeTask.java b/src/main/java/com/dispose/ability/AttackTypeTask.java deleted file mode 100644 index 99ceeec9..00000000 --- a/src/main/java/com/dispose/ability/AttackTypeTask.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.dispose.ability; - -import com.dispose.common.DpTechAttackType; -import com.dispose.common.ErrorCode; -import com.dispose.common.NetflowDirection; - -/** - * The interface Attack type task. - * - * @author - */ -public interface AttackTypeTask { - /** - * Inti attack type task dispose attack type task. - * - * @param ipAddr the ip addr - * @return the dispose attack type task - */ - DisposeAttackTypeTask intiAttackTypeTask(String ipAddr); - - /** - * Add attack type task error code. - * - * @param ipAddr the ip addr - * @param directions the directions - * @param attackTypes the attack types - * @param disposeTime the dispose time - * @return the error code - */ - ErrorCode addAttackTypeTask(String ipAddr, - NetflowDirection directions, - DpTechAttackType[] attackTypes, - Long disposeTime); - - /** - * Attack type task cleanup. - */ - void attackTypeTaskCleanup(); -} diff --git a/src/main/java/com/dispose/ability/AttackTypeTaskInfo.java b/src/main/java/com/dispose/ability/AttackTypeTaskInfo.java deleted file mode 100644 index 194136a9..00000000 --- a/src/main/java/com/dispose/ability/AttackTypeTaskInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.dispose.ability; - -import com.dispose.common.DisposeTaskStatus; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * The type Attack type task info. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class AttackTypeTaskInfo { - /** - * The Task end time. - */ - private Long taskEndTime; - /** - * The Task status. - */ - private DisposeTaskStatus taskStatus; -} diff --git a/src/main/java/com/dispose/ability/DisposeAttackTypeTask.java b/src/main/java/com/dispose/ability/DisposeAttackTypeTask.java deleted file mode 100644 index 5e78402f..00000000 --- a/src/main/java/com/dispose/ability/DisposeAttackTypeTask.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.dispose.ability; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.HashMap; - -/** - * The type Dispose attack type task. - * - * @author - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class DisposeAttackTypeTask { - /** - * The Dir in task. - */ - private HashMap dirInTask; - /** - * The Dir out task. - */ - private HashMap dirOutTask; - - /** - * The Ip address. - */ - private String ipAddress; -} diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 0444e35d..cbdd9305 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -1,12 +1,8 @@ package com.dispose.ability.impl; -import com.dispose.ability.AttackTypeTask; -import com.dispose.ability.AttackTypeTaskInfo; import com.dispose.ability.DisposeAbility; -import com.dispose.ability.DisposeAttackTypeTask; import com.dispose.common.DDoSAttackType; import com.dispose.common.DisposeCapacityType; -import com.dispose.common.DisposeTaskStatus; import com.dispose.common.DpTechAttackType; import com.dispose.common.DpTechConfigValue; import com.dispose.common.ErrorCode; @@ -23,13 +19,10 @@ import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; import org.apache.wss4j.dom.WSConstants; import org.apache.wss4j.dom.handler.WSHandlerConstants; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Nullable; import javax.xml.ws.BindingProvider; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -44,12 +37,7 @@ import java.util.stream.Collectors; */ @Component @Slf4j -public class DpTechAbilityImpl implements DisposeAbility, AttackTypeTask { - /** - * The Device task. - */ - private final HashMap deviceTask = new HashMap<>(); - +public class DpTechAbilityImpl implements DisposeAbility { /** * The Clean type port. */ @@ -244,117 +232,4 @@ public class DpTechAbilityImpl implements DisposeAbility, AttackTypeTask { .cpuUsed(-1) .build()); } - - /** - * Inti attack type task dispose attack type task. - * - * @param ipAddr the ip addr - * @return the dispose attack type task - */ - @Override - public DisposeAttackTypeTask intiAttackTypeTask(String ipAddr) { - if (deviceTask.containsKey(ipAddr)) { - return deviceTask.get(ipAddr); - } - - DisposeAttackTypeTask aTask = DisposeAttackTypeTask.builder() - .dirInTask(new HashMap<>(DpTechAttackType.values().length)) - .dirOutTask(new HashMap<>(DpTechAttackType.values().length)) - .ipAddress(ipAddr) - .build(); - - for (DpTechAttackType t : DpTechAttackType.values()) { - aTask.getDirInTask().put(t.getValue(), AttackTypeTaskInfo.builder() - .taskEndTime(0L) - .taskStatus(DisposeTaskStatus.TASK_FINISHED) - .build()); - aTask.getDirOutTask().put(t.getValue(), AttackTypeTaskInfo.builder() - .taskEndTime(0L) - .taskStatus(DisposeTaskStatus.TASK_FINISHED) - .build()); - } - - synchronized (this) { - deviceTask.put(ipAddr, aTask); - } - - return aTask; - } - - /** - * Add attack type task error code. - * - * @param ipAddr the ip addr - * @param directions the directions - * @param attackTypes the attack types - * @param disposeTime the dispose time - * @return the error code - */ - @Override - public ErrorCode addAttackTypeTask(String ipAddr, - NetflowDirection directions, - DpTechAttackType[] attackTypes, - Long disposeTime) { - DisposeAttackTypeTask taskInfo = intiAttackTypeTask(ipAddr); - Long endTime = System.currentTimeMillis() + (disposeTime * 60 * 1000); - - if (directions == NetflowDirection.DIRECTION_IN || directions == NetflowDirection.DIRECTION_BI) { - for (DpTechAttackType t : attackTypes) { - AttackTypeTaskInfo ti = taskInfo.getDirInTask().get(t.getValue()); - if (ti.getTaskEndTime() < endTime) { - ti.setTaskEndTime(endTime); - if (ti.getTaskStatus() == DisposeTaskStatus.TASK_CANCELED || - ti.getTaskStatus() == DisposeTaskStatus.TASK_FINISHED) { - ti.setTaskStatus(DisposeTaskStatus.TASK_NEW); - } - taskInfo.getDirInTask().put(t.getValue(), ti); - } - } - } - - if (directions == NetflowDirection.DIRECTION_OUT || directions == NetflowDirection.DIRECTION_BI) { - for (DpTechAttackType t : attackTypes) { - AttackTypeTaskInfo ti = taskInfo.getDirOutTask().get(t.getValue()); - if (ti.getTaskEndTime() < endTime) { - ti.setTaskEndTime(endTime); - if (ti.getTaskStatus() == DisposeTaskStatus.TASK_CANCELED || - ti.getTaskStatus() == DisposeTaskStatus.TASK_FINISHED) { - ti.setTaskStatus(DisposeTaskStatus.TASK_NEW); - } - taskInfo.getDirOutTask().put(t.getValue(), ti); - } - } - } - - return ErrorCode.ERR_OK; - } - - /** - * Attack type task cleanup. - */ - @Override - @Async("bizExecutor") - @Scheduled(fixedDelay = 1000 * 60) - public void attackTypeTaskCleanup() { - for (DisposeAttackTypeTask t : deviceTask.values()) { - boolean clean = true; - - List taskInfo = new ArrayList<>(); - taskInfo.addAll(t.getDirInTask().values()); - taskInfo.addAll(t.getDirOutTask().values()); - - for (AttackTypeTaskInfo v : taskInfo) { - if (v.getTaskEndTime() > System.currentTimeMillis()) { - clean = false; - break; - } - } - - if (clean) { - synchronized (this) { - deviceTask.remove(t.getIpAddress()); - } - } - } - } } diff --git a/src/main/java/com/dispose/common/DpTechAttackType.java b/src/main/java/com/dispose/common/DpTechAttackType.java index 2aa85d9f..9604a497 100644 --- a/src/main/java/com/dispose/common/DpTechAttackType.java +++ b/src/main/java/com/dispose/common/DpTechAttackType.java @@ -80,6 +80,22 @@ public enum DpTechAttackType implements BaseEnum { this.readme = readme; } + /** + * Gets type mask from attack type. + * + * @param types the types + * @return the type mask from attack type + */ + public static Long getTypeMaskFromAttackType(DpTechAttackType[] types) { + long mask = 0L; + + for (DpTechAttackType type : types) { + mask |= (long)1 << type.getValue(); + } + + return mask; + } + /** * From ddos attack type value stream. *