All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.acgist.snail.net.torrent.peer.PeerMessageHandler Maven / Gradle / Ivy

Go to download

基于Java开发的下载工具,支持下载协议:BT(BitTorrent、磁力链接、种子文件)、HLS(M3U8)、FTP、HTTP。

There is a newer version: 2.17.0
Show newest version
package com.acgist.snail.net.torrent.peer;

import java.nio.ByteBuffer;

import com.acgist.snail.context.exception.NetException;
import com.acgist.snail.net.TcpMessageHandler;
import com.acgist.snail.net.codec.IMessageEncoder;
import com.acgist.snail.net.torrent.IEncryptMessageSender;
import com.acgist.snail.net.torrent.IPeerConnect;

/**
 * 

Peer消息代理

* * @author acgist */ public final class PeerMessageHandler extends TcpMessageHandler implements IEncryptMessageSender { /** *

消息编码器

*/ private final IMessageEncoder messageEncoder; /** *

Peer消息代理

*/ private final PeerSubMessageHandler peerSubMessageHandler; /** *

服务端

*/ public PeerMessageHandler() { this(PeerSubMessageHandler.newInstance()); } /** *

客户端

* * @param peerSubMessageHandler Peer消息代理 */ public PeerMessageHandler(PeerSubMessageHandler peerSubMessageHandler) { peerSubMessageHandler.messageEncryptSender(this); final var peerUnpackMessageCodec = new PeerUnpackMessageCodec(peerSubMessageHandler); final var peerCryptMessageCodec = new PeerCryptMessageCodec(peerUnpackMessageCodec, peerSubMessageHandler); this.messageDecoder = peerCryptMessageCodec; this.messageEncoder = peerCryptMessageCodec; this.peerSubMessageHandler = peerSubMessageHandler; } @Override public boolean useless() { return this.peerSubMessageHandler.useless(); } @Override public void sendEncrypt(ByteBuffer buffer, int timeout) throws NetException { this.messageEncoder.encode(buffer); this.send(buffer, timeout); } @Override public IPeerConnect.ConnectType connectType() { return IPeerConnect.ConnectType.TCP; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy