use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class MSECipherTest method testCosted.
@Test
void testCosted() throws NetException {
final byte[] secret = ArrayUtils.random(16);
final InfoHash infoHash = InfoHash.newInstance(ArrayUtils.random(20));
final var sender = MSECipher.newSender(secret, infoHash);
final var recver = MSECipher.newRecver(secret, infoHash);
final byte[] data = ArrayUtils.random(20);
final long costed = this.costed(100000, () -> {
try {
final byte[] senderEncryptData = sender.encrypt(data);
final byte[] recverDecryptData = recver.decrypt(senderEncryptData);
if (recverDecryptData == null) {
LOGGER.warn("解密失败");
}
} catch (NetException e) {
LOGGER.error("数据加解密异常", e);
}
});
assertTrue(costed < 1000);
}
use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class LoggerTest method testLevel.
@Test
void testLevel() {
String arga = null;
String argb = "";
final TaskEntity taskEntity = new TaskEntity();
LOGGER.debug("debug:{}-{}-{}-{}", arga, argb, taskEntity);
LOGGER.info("info:{}-{}-{}-{}", arga, argb, taskEntity);
LOGGER.warn("warn:{}-{}-{}-{}", arga, argb, taskEntity);
LOGGER.error("error:{}-{}-{}-{}", arga, argb, taskEntity);
try {
throw new NetException("错误测试");
} catch (Exception e) {
LOGGER.debug("debug", e);
LOGGER.info("info", e);
LOGGER.warn("warn", e);
LOGGER.error("error", e);
}
assertNotNull(LOGGER);
}
use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class FtpProtocol method buildSize.
@Override
protected void buildSize() throws DownloadException {
final FtpClient client = FtpClient.newInstance(this.url);
try {
client.connect();
final long size = client.size();
this.taskEntity.setSize(size);
} catch (NetException e) {
throw new DownloadException(e);
} finally {
client.close();
}
}
use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class M3u8Builder method buildCipher.
/**
* <p>新建加密套件</p>
*
* @return 加密套件
*
* @throws NetException 网络异常
*/
private Cipher buildCipher() throws NetException {
final var optional = this.labels.stream().filter(label -> LABEL_EXT_X_KEY.equalsIgnoreCase(label.getName())).findFirst();
if (optional.isEmpty()) {
// 没有加密标签:不用解密
return null;
}
final KeyValueWrapper wrapper = optional.get().attrs();
final String method = wrapper.getIgnoreCase(ATTR_METHOD);
final M3u8.Protocol protocol = M3u8.Protocol.of(method);
LOGGER.debug("HLS加密算法:{}", method);
if (protocol == null || protocol == M3u8.Protocol.NONE) {
throw new NetException("不支持的HLS加密算法:" + method);
}
if (protocol == M3u8.Protocol.AES_128) {
return this.buildCipherAes128(wrapper.getIgnoreCase(ATTR_IV), wrapper.getIgnoreCase(ATTR_URI));
} else {
throw new NetException("不支持的HLS加密算法:" + method);
}
}
use of com.acgist.snail.context.exception.NetException in project snail by acgist.
the class UpnpMessageHandler method onMessage.
@Override
public void onMessage(String message, InetSocketAddress address) {
final HeaderWrapper headers = HeaderWrapper.newInstance(message);
// 判断是否支持UPNP设置
final boolean support = headers.allHeaders().values().stream().anyMatch(list -> list.stream().anyMatch(value -> StringUtils.startsWith(value, UpnpServer.UPNP_ROOT_DEVICE)));
if (!support) {
LOGGER.warn("UPNP设置失败(不支持的驱动):{}", message);
return;
}
final String location = headers.header(HEADER_LOCATION);
if (StringUtils.isEmpty(location)) {
LOGGER.warn("UPNP设置失败(没有描述文件地址):{}", message);
return;
}
final UpnpContext upnpContext = UpnpContext.getInstance();
try {
upnpContext.load(location);
} catch (NetException e) {
LOGGER.error("UPNP端口映射异常:{}", location, e);
} finally {
// 可用才能释放:可能收到不是UPNP消息
if (upnpContext.available()) {
NatContext.getInstance().unlock();
}
}
}
Aggregations