Skip to content

Commit

Permalink
1. 增加基于 ipRegion 的访问策略
Browse files Browse the repository at this point in the history
 2. 优化channel id 生产(雪花算法)
 3. 更新JDK 17 镜像
  • Loading branch information
lin1810 committed Jul 27, 2024
1 parent 8f53926 commit 3ca8e9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.ipfilter.AbstractRemoteAddressFilter;
import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -17,7 +18,9 @@ public class IpRegionFilter extends AbstractRemoteAddressFilter<InetSocketAddres

public IpRegionFilter(IpRegionUtils regionUtils, String[] allowList) {
this.regionUtils = regionUtils;
Arrays.sort(allowList,String::compareTo);
if (!ArrayUtils.isEmpty(allowList)) {
Arrays.sort(allowList, String::compareTo);
}
this.allowList = allowList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Objects;
import java.util.StringTokenizer;

@Component
Expand All @@ -33,6 +34,9 @@ public class IpRegionUtils implements InitializingBean, DisposableBean {
@Override
public void afterPropertiesSet() throws Exception {
File ipRegionPath = serverProperties.getIpRegionPath();
if (Objects.isNull(ipRegionPath)) {
return;
}

byte[] cBuff;
try (RandomAccessFile file = new RandomAccessFile(ipRegionPath, "r")) {
Expand Down
16 changes: 8 additions & 8 deletions config/dev/NT-Server/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ nt:
# server-cert-path: /tmp/server.crt
# server-key-path: /tmp/pkcs8_server.key
# server-key-password:
ip-region-path: /tmp/ip2region.xdb # https://gitee.com/lionsoul/ip2region/blob/master/data/ip2region.xdb
# ip-region-path: /tmp/ip2region.xdb # https://gitee.com/lionsoul/ip2region/blob/master/data/ip2region.xdb
instance-list:
- instance-name: remote.ssh
port: 922
access-ip-region:
- 中国
# access-ip-region:
# - 中国
- instance-name: remote.https
port: 9443
access-ip-region:
- 中国
access-ip-region:
- 中国
- 0 #内网 IP
# access-ip-region:
# - 中国
# access-ip-region:
# - 中国
# - 0 #内网 IP
#logging:
# level:
# net.shihome.nt.server.tcp: DEBUG

0 comments on commit 3ca8e9b

Please sign in to comment.