public PossibleRemoteHostsForm(ref FileDetails _fd) { InitializeComponent(); fd = _fd; }
// Publishing the file via the DHT public int PulishFileViaDht(FileDetails fd) { try { // The key = file name // The value = local node Ip @ IPAddress[] ips = Dns.GetHostByName(Dns.GetHostName()).AddressList; // TODO: Verify the correct Ip@ if (RemoteDHTCall.SendPutRequestToRemoteDHT(fd.FileName, ips[0].ToString()) == 1) { // Published return 1; } else { // Error occured on the underlying RemoteDhtApi.dll MessageBox.Show("Error occured while trying to publish the new torrent file.","DHT API",MessageBoxButtons.OK,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1); return 0; } } catch { // Error occured while trying to publish a new torrent file MessageBox.Show("Error occured while trying to publish the new torrent file."); return 0; } }
public void ParseSingleFileMessage(string message, ref string existingFileName) { try { // Single file format: node1Ip#file1*file1.size*file1.description*file1.numberofleechers*file1.numberofseeders \r\n string nodeIp = null; string fileName = null; string fileDescription = null; long fileSize = 0; int numberOfLeechers = 0; int numberOfSeeders = 0; string tmp = null; Int32 dz = message.IndexOf('#'); Trace.Assert(dz > 0, "ParseTrackerMessage::ParseSingleFileMessage, received message does not correspond to the template: " + message); nodeIp = message.Substring(0, dz ); // Get the file name tmp = message.Substring(dz + 1); dz = tmp.IndexOf('*'); Trace.Assert(dz > 0, "ParseTrackerMessage::ParseSingleFileMessage, received message does not correspond to the template: " + message); fileName = tmp.Substring(0, dz ); // Get the file size tmp = tmp.Substring(dz + 1); dz = tmp.IndexOf('*'); Trace.Assert(dz > 0, "ParseTrackerMessage::ParseSingleFileMessage, received message does not correspond to the template: " + message); fileSize = long.Parse(tmp.Substring(0, dz)); // Get the file description tmp = tmp.Substring(dz + 1); dz = tmp.IndexOf('*'); Trace.Assert(dz > 0, "ParseTrackerMessage::ParseSingleFileMessage, received message does not correspond to the template: " + message); fileDescription = tmp.Substring(0, dz); //Get the number of leechers tmp = tmp.Substring(dz + 1); dz = tmp.IndexOf('*'); Trace.Assert(dz > 0, "ParseTrackerMessage::ParseSingleFileMessage, received message does not correspond to the template: " + message); numberOfLeechers = Int32.Parse(tmp.Substring(0, dz)); //Get the number of seeders tmp = tmp.Substring(dz + 1); numberOfSeeders = Int32.Parse(tmp); int remotePort = TorrentFConfig.GetConfig().uploadingServerPort; FileDetails fd = FilesManager.GetFileManager().GetFileDetails(ref fileName); bool exists = false; if (fd == null) { // Verify the local list foreach (FileDetails x in resultingFiles) { if (x.FileName.CompareTo(fileName) == 0) { exists = true; fd = x; break; } } } else { exists = true; } if(!exists) { fd = new FileDetails(false, fileName, fileSize, nodeIp, remotePort, ""); // Append the related data file description string dfd = fileDescription; fd.DataDescription = dfd; // Append the related sharing session details SharingSessionDetails ssd = new SharingSessionDetails(); ssd.NumberOfLeechers = numberOfLeechers; ssd.NumberOfSeerders = numberOfSeeders; fd.AppendRelatedSessionDetails(ref ssd); resultingFiles.Add(fd); } else { // File already available // Just add a possible Downloading remote host, the number of seeders and the number of leecherss fd.AddHostCoordinates(ref nodeIp, ref remotePort); fd.SessionDetails.NumberOfLeechers = numberOfLeechers; fd.SessionDetails.NumberOfSeerders = numberOfSeeders; // Specify the existing fileName existingFileName = fileName; } } catch { MessageBox.Show("Error occured while trying to parse a single file tracker's response.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } }
private void AddFile(string _fileName, FileDetails _fileDetails) { lock (this) { if (!mainFilesDic.ContainsKey(_fileName)) { mainFilesDic.Add(_fileName, _fileDetails); } } }
private void AddFile(ref bool _strorageStatus, ref string _fileName, ref Int32 _fileSize, ref string _remoteHostIp, ref Int32 _remoteHostPort, ref string _localFilePath) { lock (this) { if (mainFilesDic.Count == 0 || !mainFilesDic.ContainsKey(_fileName)) { // Adding the file to the main dic FileDetails fd = new FileDetails(_strorageStatus, _fileName, _fileSize, _remoteHostIp,_remoteHostPort, _localFilePath); mainFilesDic.Add(_fileName, fd); } } }
// Publishing the file via the DHT public Int32 PublishFileViaDHT(string fileAbsolutePath, out FileDetails _fd) { // Verify if we have already tried to publish this file or not if (!mainFilesDic.ContainsKey(Path.GetFileName(fileAbsolutePath))) { // Get file details Bsed on its path FileInfo fi = new FileInfo(fileAbsolutePath); FilePublishingStatus fd = new FilePublishingStatus(true, fi.Name, fi.Length, "", 0, fileAbsolutePath); fd.DataDescription = null; int res = filePublisher.PulishFileViaDht(fd); if (res == 1) { _fd = fd; // Adding the published file to the local dict AddFile(fi.Name, (FileDetails)fd); } else _fd = null; return res; } else { // Already exists in the dict FileDetails fd = mainFilesDic[Path.GetFileName(fileAbsolutePath)]; int res = filePublisher.PulishFileViaDht(fd); if (res == 1) _fd = fd; else _fd = null; return res; } }
// Default publishing method via the local tracker public void PublishFile(string fileAbsolutePath, out FileDetails _fd) { FilePublisherThreadParam tp = new FilePublisherThreadParam(this); // Verify if we have already tried to publish this file or not if (!mainFilesDic.ContainsKey(Path.GetFileName(fileAbsolutePath))) { // Get file details Bsed on its path FileInfo fi = new FileInfo(fileAbsolutePath); FilePublishingStatus fd = new FilePublishingStatus(true, fi.Name, fi.Length, "", 0, fileAbsolutePath); FileDescription fileDescriptionDialog = new FileDescription(); fileDescriptionDialog.Closed += new EventHandler(fileDescriptionDialog_Closed); fileDescriptionDialog.ShowDialog(); fd.DataDescription = CurrentDataDescription; tp.CurrentFileDetails = fd; tp.CurrentFileDescription = fi.Name; filePublisher.PulishFile(tp); _fd = fd; // Adding the published file to the local dict AddFile(fi.Name, (FileDetails)fd); } else { // Already exists in the dict FileDetails fd = mainFilesDic[Path.GetFileName(fileAbsolutePath)]; _fd = fd; tp.CurrentFileDetails = fd; tp.CurrentFileDescription = fd.FileName; filePublisher.PulishFile(tp); } }
public RelatedTorrentDetails(ref FileDetails _fd) { InitializeComponent(); fd = _fd; }