Ejemplo n.º 1
0
        public OutgoingTransfer(ConnectionHandler ch, ShareFileInfo sfi) : base()
        {
            direction = TransferDirection.Out;

            this.ch       = ch;
            this.sfi      = sfi;
            this.hostName = ch.Client.Client.RemoteEndPoint.ToString();
            this.file1    = sfi.relativeVPath;
            this.file2    = "(remote)";
        }
Ejemplo n.º 2
0
        void InnerHandleHTTPRequest(string path)
        {
            if (path == "/filelist")
            {
                string[] fileList = ShareManager.Instance.GetFullVFileList();
                byte[]   buf      = Encoding.UTF8.GetBytes(String.Join("\r\n", fileList));

                stream.WriteHTTPResponseHeader(200, "text/plain", buf.Length);
                client.WriteStreamAsHTTPContent(new MemoryStream(buf));
            }
            else if (path == "/info")
            {
                string version = Application.ProductVersion;
                string resp    = String.Format("version:{0}\nfiles:{1}\nname:{2}", version, ShareManager.Instance.TotalFiles, SettingsManager.Instance.ComputerName);
                stream.WriteSimpleHTTPResponse(200, "text/plain", resp);

                string remoteIp = (client.Client.RemoteEndPoint as IPEndPoint).Address.ToString();
                if (remoteIp != "127.0.0.1" && !NetworkManager.Instance.HostIPIsKnown(remoteIp))
                {
                    Host h = NetworkManager.Instance.AddHost(remoteIp, NetworkManager.LANLINE_PORT, false);
                    h.Name = "<downloader>";
                }
            }
            else if (path.StartsWith("/f/"))
            {
                ShareFileInfo sfi = ShareManager.Instance.ResolveVPath(path.Substring(3));
                if (sfi == null)
                {
                    stream.WriteSimpleHTTPResponse(404, "text/plain", "Not found!");
                }
                else
                {
                    OutgoingTransfer transfer = new OutgoingTransfer(this, sfi);
                    XferManager.Instance.Track(transfer);
                    try {
                        transfer.RunTransferInThisThread();
                    } catch (Exception) {
                        transfer.CancelWithError();
                    }
                }
            }
            else
            {
                stream.WriteSimpleHTTPResponse(200, "text/plain", "Requested: " + path);
            }
        }