/// <summary> /// 发送piece信息 /// pieces: <len=0009+X><id=7><index><begin><block> /// </summary> /// <param name="index">片断索引号</param> /// <param name="begin">子片断的起始位置</param> /// <param name="pieces">子片断的数据</param> public void SendPiece(int index, int begin, byte[] pieces) { //更新上传速率 connecter.UpdateUploadRate(pieces.Length); //发送piece信息 message = DummyMessageFactory.GetPieceMessage(index, begin, pieces); encryptedConnection.SendMessage(message.Encode()); }
/// <summary> /// 发送port信息 /// port: <len=0003><id=9><listen-port> /// </summary> /// <param name="port">DHT监听端口</param> public void SendPort(ushort port) { //发送port信息 message = DummyMessageFactory.GetPortMessage(port); encryptedConnection.SendMessage(message.Encode()); }
/// <summary> /// 发送cancel信息 /// cancel: <len=0013><id=8><index><begin><lengthBytes> /// </summary> /// <param name="index">片断索引号</param> /// <param name="begin">子片断的起始位置</param> /// <param name="lengthBytes">子片断的长度</param> public void SendCancel(int index, int begin, int length) { //发送cancel信息 message = DummyMessageFactory.GetCancelMessage(index, begin, length); encryptedConnection.SendMessage(message.Encode()); }
/// <summary> /// 发送request信息 /// request: <len=0013><id=6><index><begin><lengthBytes> /// </summary> /// <param name="index">片断索引号</param> /// <param name="begin">子片断的起始位置</param> /// <param name="lengthBytes">子片断的长度</param> public void SendRequest(int index, int begin, int length) { //发送request信息 message = DummyMessageFactory.GetRequestMessage(index, begin, length); encryptedConnection.SendMessage(message.Encode()); }
/// <summary> /// 发送bitfield信息 /// bitfield: <len=0001+X><id=5><bitfield> /// </summary> /// <param name="bitField">已经下载的文件片断</param> public void SendBitfield(bool[] bitfield) { //发送bitfield信息 message = DummyMessageFactory.GetBitfieldMessage(bitfield); encryptedConnection.SendMessage(message.Encode()); }
/// <summary> /// 发送have信息 /// have: <len=0005><id=4><pieces index> /// </summary> /// <param name="index">片断索引号</param> public void SendHave(int index) { //发送have信息 message = DummyMessageFactory.GetHaveMessage(index); encryptedConnection.SendMessage(message.Encode()); }
/// <summary> /// 发送not interested信息 /// not interested: <len=0001><id=3> /// </summary> public void SendNotInterested() { //发送not interested信息 message = DummyMessageFactory.GetNotInterestedMessage(); encryptedConnection.SendMessage(message.Encode()); }
/// <summary> /// 发送unchoke信息 /// unchoke: <len=0001><id=1> /// </summary> public void SendUnchoke() { //发送unchoke信息 message = DummyMessageFactory.GetUnchokeMessage(); encryptedConnection.SendMessage(message.Encode()); }