Inheritance: PeerMessage
Exemplo n.º 1
0
        private void CreateWebRequests(RequestMessage start, RequestMessage end)
        {
            // Properly handle the case where we have multiple files
            // This is only implemented for single file torrents
            var uri = Uri;

            if (Uri.OriginalString.EndsWith("/"))
                uri = new Uri(uri, Manager.Torrent.Name + "/");

            // startOffset and endOffset are *inclusive*. I need to subtract '1' from the end index so that i
            // stop at the correct byte when requesting the byte ranges from the server
            var startOffset = (long) start.PieceIndex*Manager.Torrent.PieceLength + start.StartOffset;
            var endOffset = (long) end.PieceIndex*Manager.Torrent.PieceLength + end.StartOffset + end.RequestLength;

            foreach (var file in Manager.Torrent.Files)
            {
                var u = uri;
                if (Manager.Torrent.Files.Length > 1)
                    u = new Uri(u, file.Path);
                if (endOffset == 0)
                    break;

                // We want data from a later file
                if (startOffset >= file.Length)
                {
                    startOffset -= file.Length;
                    endOffset -= file.Length;
                }
                // We want data from the end of the current file and from the next few files
                else if (endOffset >= file.Length)
                {
                    var request = (HttpWebRequest) WebRequest.Create(u);
                    AddRange(request, startOffset, file.Length - 1);
                    _webRequests.Enqueue(new KeyValuePair<WebRequest, int>(request, (int) (file.Length - startOffset)));
                    startOffset = 0;
                    endOffset -= file.Length;
                }
                // All the data we want is from within this file
                else
                {
                    var request = (HttpWebRequest) WebRequest.Create(u);
                    AddRange(request, startOffset, endOffset - 1);
                    _webRequests.Enqueue(new KeyValuePair<WebRequest, int>(request, (int) (endOffset - startOffset)));
                    endOffset = 0;
                }
            }
        }
 public RejectRequestMessage(RequestMessage message)
     : this(message.PieceIndex, message.StartOffset, message.RequestLength)
 {
 }
 protected override void HandleRequestMessage(PeerId id, RequestMessage message)
 {
     base.HandleRequestMessage(id, message);
     unchoker.SentBlock(id, message.PieceIndex);
 }
Exemplo n.º 4
0
 public HttpRequestData(RequestMessage request)
 {
     Request = request;
     var m = new PieceMessage(request.PieceIndex, request.StartOffset, request.RequestLength);
     TotalToReceive = m.ByteLength;
 }