-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from JNU-econovation/fix_monitor_interface
[FIX] Fix monitor interface
- Loading branch information
Showing
33 changed files
with
214 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dependencies { | ||
compileOnly project(":modules:main-api") | ||
|
||
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") | ||
implementation 'org.springframework.boot:spring-boot-starter-data-redis' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...-api/src/main/java/com/whoz_in/main_api/command/device/presentation/DeviceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main-api/src/main/java/com/whoz_in/main_api/shared/jwt/tokens/RefreshTokenSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 13 additions & 6 deletions
19
modules/network-api/src/main/java/com/whoz_in/network_api/common/NetworkInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
package com.whoz_in.network_api.common; | ||
|
||
import jakarta.annotation.Nullable; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
public final class NetworkInterface{ | ||
// | ||
@EqualsAndHashCode.Exclude | ||
private final String altSsid; //network log의 ssid는 이걸로 저장된다. (ex: econo) | ||
private final String interfaceName; | ||
private final String realSsid; //실제 연결될 와이파이 이름 (ex: ECONO_5G) | ||
private final String mode; | ||
|
||
public NetworkInterface(String altSsid, String interfaceName, String realSsid, String mode) { | ||
this.altSsid = altSsid; | ||
@EqualsAndHashCode.Exclude | ||
@Nullable private final String altSsid; //network log의 ssid는 이걸로 저장된다. (ex: econo) | ||
@EqualsAndHashCode.Exclude | ||
@Nullable private final String command; //실행할 명령어 | ||
|
||
public NetworkInterface(String interfaceName, String realSsid, String mode, String altSsid, String command) { | ||
this.interfaceName = interfaceName; | ||
this.realSsid = realSsid; | ||
this.mode = mode; | ||
this.altSsid = altSsid; | ||
this.command = command; | ||
} | ||
|
||
public NetworkInterface(String interfaceName, String realSsid, String mode) { | ||
this(realSsid, interfaceName, realSsid, mode); | ||
this(interfaceName, realSsid, mode, realSsid, null); | ||
} | ||
} |
22 changes: 3 additions & 19 deletions
22
modules/network-api/src/main/java/com/whoz_in/network_api/common/util/IpHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
package com.whoz_in.network_api.common.util; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class IpHolder implements RequesterInfo{ | ||
|
||
private final ThreadLocal<String> ip = new ThreadLocal<>(); | ||
|
||
public void setIp(String ip) { | ||
this.ip.set(ip); | ||
} | ||
|
||
public String getIp(){ | ||
return ip.get(); | ||
} | ||
|
||
public void clear(){ | ||
ip.remove(); | ||
} | ||
|
||
//요청의 아이피를 꺼낼 수 있는 인터페이스 | ||
public interface IpHolder { | ||
String getIp(); | ||
} |
11 changes: 0 additions & 11 deletions
11
modules/network-api/src/main/java/com/whoz_in/network_api/common/util/RequesterInfo.java
This file was deleted.
Oops, something went wrong.
94 changes: 28 additions & 66 deletions
94
modules/network-api/src/main/java/com/whoz_in/network_api/config/NetworkConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,57 @@ | ||
package com.whoz_in.network_api.config; | ||
|
||
import com.whoz_in.network_api.common.NetworkInterface; | ||
import com.whoz_in.network_api.managed.ManagedInfo; | ||
import com.whoz_in.network_api.monitor.MonitorInfo; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import lombok.Getter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding; | ||
import org.springframework.stereotype.Component; | ||
|
||
//실행시킬 프로세스들이 필요로 하는 정보를 제공하는 역할을 한다. | ||
//다른 모듈이 구현한 LogWriterConfig를 통해 정보를 초기화한다. | ||
//이 서버의 전체적인 설정 값을 관리한다. | ||
@Getter | ||
@Component | ||
public class NetworkConfig { | ||
private final String room; | ||
private final String sudoPassword; | ||
private final List<NetworkInterface> networkInterfaces; | ||
private final MonitorInfo monitorInfo; | ||
private final List<ManagedInfo> mdnsList; | ||
private final List<ManagedInfo> arpList; | ||
private final NetworkInterface monitorNI; | ||
private final List<NetworkInterface> mdnsNIs; | ||
private final List<NetworkInterface> arpNIs; | ||
|
||
public NetworkConfig( | ||
NetworkConfigProperties properties, | ||
NetworkInterfaceProperties properties, | ||
@Value("${room-setting.room-name}") String roomName, | ||
@Value("${sudo_password}") String sudoPassword, | ||
@Value("${command.monitor}") String monitorCommandTemplate, | ||
@Value("${command.managed.mdns}") String mdnsCommandTemplate, | ||
@Value("${command.managed.arp}") String arpCommandTemplate | ||
) { | ||
this.room = properties.getRoom(); | ||
this.room = roomName; | ||
this.sudoPassword = sudoPassword; | ||
this.networkInterfaces = properties.getNIs(); | ||
this.monitorInfo = new MonitorInfo(properties.getMonitorNI(), generateCommand(monitorCommandTemplate, properties.getMonitorNI().getInterfaceName())); | ||
this.mdnsList=properties.getMdnsNIs().stream() | ||
.map(ni-> new ManagedInfo(ni, generateCommand(mdnsCommandTemplate, ni.getInterfaceName()))) | ||
this.monitorNI = new NetworkInterface(properties.getMonitor().interfaceName(), null, "monitor", | ||
null, generateCommand(monitorCommandTemplate, properties.getMonitor().interfaceName())); | ||
this.mdnsNIs = properties.getMdns().stream() | ||
.map(mdns -> { | ||
String altSsid = (mdns.altSsid() != null) ? mdns.altSsid() : mdns.realSsid(); | ||
return new NetworkInterface(mdns.interfaceName() , mdns.realSsid(), "managed", altSsid, | ||
generateCommand(mdnsCommandTemplate, mdns.interfaceName())); | ||
}) | ||
.toList(); | ||
this.arpList=properties.getArpNIs().stream() | ||
.map(ni-> new ManagedInfo(ni, generateCommand(arpCommandTemplate, ni.getInterfaceName()))) | ||
this.arpNIs = properties.getArp().stream() | ||
.map(arp -> { | ||
String altSsid = (arp.altSsid() != null) ? arp.altSsid() : arp.realSsid(); | ||
return new NetworkInterface(arp.interfaceName(), arp.realSsid(), "managed", altSsid, | ||
generateCommand(arpCommandTemplate, arp.interfaceName())); | ||
}) | ||
.toList(); | ||
this.networkInterfaces = Stream.of(monitorNI, mdnsNIs, arpNIs) | ||
.flatMap(list -> list instanceof Collection<?> ? | ||
((Collection<NetworkInterface>) list).stream() : Stream.of((NetworkInterface) list)) | ||
.toList(); | ||
} | ||
|
||
private String generateCommand(String commandTemplate, String interfaceName) { | ||
private static String generateCommand(String commandTemplate, String interfaceName) { | ||
return commandTemplate.replace("{{interface}}", interfaceName); | ||
} | ||
|
||
|
||
@Getter | ||
@ConfigurationProperties(prefix = "room-setting") | ||
public static class NetworkConfigProperties { | ||
|
||
private final String room; | ||
private final NetworkInterface monitorNI; | ||
private final List<NetworkInterface> mdnsNIs; | ||
private final List<NetworkInterface> arpNIs; | ||
|
||
public record Monitor(String interfaceName) {} | ||
public record Managed(List<Mdns> mdns, List<Arp> arp) { | ||
public record Mdns(String altSsid, String realSsid, String interfaceName) {} | ||
public record Arp(String altSsid, String realSsid, String interfaceName) {} | ||
} | ||
|
||
public List<NetworkInterface> getNIs() { | ||
List<NetworkInterface> nis = new ArrayList<>(); | ||
nis.add(getMonitorNI()); | ||
nis.addAll(getMdnsNIs()); | ||
nis.addAll(getArpNIs()); | ||
return nis; | ||
} | ||
|
||
@ConstructorBinding | ||
public NetworkConfigProperties( | ||
String roomName, | ||
Monitor monitor, | ||
Managed managed | ||
) { | ||
this.room = roomName; | ||
this.monitorNI = new NetworkInterface(null, monitor.interfaceName, null, "monitor"); | ||
this.mdnsNIs = managed.mdns.stream() | ||
.map(ni -> { | ||
String altSsid = (ni.altSsid != null) ? ni.altSsid : ni.realSsid; | ||
return new NetworkInterface(altSsid, ni.interfaceName, ni.realSsid, "managed"); | ||
}) | ||
.toList(); | ||
this.arpNIs = managed.arp.stream() | ||
.map(ni -> { | ||
String altSsid = (ni.altSsid != null) ? ni.altSsid : ni.realSsid; | ||
return new NetworkInterface(altSsid, ni.interfaceName, ni.realSsid, "managed"); | ||
}) | ||
.toList(); | ||
} | ||
} | ||
} |
Oops, something went wrong.