Exemplo n.º 1
0
        public void SendNotInterested()
        {
            if (!IsInterestedSent)
            {
                return;
            }

            ConsoleLogger.WriteLn(this, "-> not interested");
            SendBytes(PeerEncoder.EncodeNotInterested());
            IsInterestedSent = false;
        }
Exemplo n.º 2
0
        public void SendInterested()
        {
            if (IsInterestedSent)
            {
                return;
            }

            ConsoleLogger.WriteLn(this, "-> interested");
            SendBytes(PeerEncoder.EncodeInterested());
            IsInterestedSent = true;
        }
Exemplo n.º 3
0
        public void SendUnchoke()
        {
            if (!IsChokeSent)
            {
                return;
            }

            ConsoleLogger.WriteLn(this, "-> unchoke");
            SendBytes(PeerEncoder.EncodeUnchoke());
            IsChokeSent = false;
        }
Exemplo n.º 4
0
        public void SendChoke()
        {
            if (IsChokeSent)
            {
                return;
            }

            ConsoleLogger.WriteLn(this, "-> choke");
            SendBytes(PeerEncoder.EncodeChoke());
            IsChokeSent = true;
        }
Exemplo n.º 5
0
        public void SendKeepAlive()
        {
            if (LastKeepAlive > DateTime.UtcNow.AddSeconds(-30))
            {
                return;
            }

            ConsoleLogger.WriteLn(this, "-> keep alive");
            SendBytes(PeerEncoder.EncodeKeepAlive());
            LastKeepAlive = DateTime.UtcNow;
        }
Exemplo n.º 6
0
        private void SendHandshake()
        {
            if (IsHandshakeSent)
            {
                return;
            }

            ConsoleLogger.WriteLn(this, "-> handshake");
            SendBytes(PeerEncoder.EncodeHandshake(Torrent.Infohash, LocalId));
            IsHandshakeSent = true;
        }
Exemplo n.º 7
0
 public void SendCancel(int index, int begin, int length)
 {
     ConsoleLogger.WriteLn(this, "-> cancel");
     SendBytes(PeerEncoder.EncodeCancel(index, begin, length));
 }
Exemplo n.º 8
0
 public void SendPiece(int index, int begin, byte[] data)
 {
     ConsoleLogger.WriteLn(this, "-> piece " + index + ", " + begin + ", " + data.Length);
     SendBytes(PeerEncoder.EncodePiece(index, begin, data));
     Uploaded += data.Length;
 }
Exemplo n.º 9
0
 public void SendRequest(int index, int begin, int length)
 {
     ConsoleLogger.WriteLn(this, "-> request " + index + ", " + begin + ", " + length);
     SendBytes(PeerEncoder.EncodeRequest(index, begin, length));
 }
Exemplo n.º 10
0
 public void SendBitfield(bool[] isPieceDownloaded)
 {
     ConsoleLogger.WriteLn(this, "-> bitfield " + string.Join("", isPieceDownloaded.Select(x => x ? 1 : 0)));
     SendBytes(PeerEncoder.EncodeBitfield(isPieceDownloaded));
 }
Exemplo n.º 11
0
 public void SendHave(int index)
 {
     ConsoleLogger.WriteLn(this, "-> have " + index);
     SendBytes(PeerEncoder.EncodeHave(index));
 }