/// <summary> /// Return a list that contains the peers that have the searched file. /// </summary> /// <param name="FileName">The name of the file.</param> /// <param name="FileID">The ID of the file.</param> /// <returns>The list of the peers that have the searched file.</returns> public static List <Objects.Peer> GetPeersByFile(string FileName, string FileID) { List <Objects.Peer> returnPeers = new List <Objects.Peer>(); for (int i = 0; i < PeersList.List.Count; i++) { for (int j = 0; j < PeersList.List[i].Files.Count; j++) { Objects.Peer.File file = PeersList.List[i].Files[j]; if (file.Name == FileName && file.SHA1 == FileID) { returnPeers.Add(PeersList.List[i]); } } } return(returnPeers); }
/// <summary> /// Build a new XML_List with all the peers are contained in the Lists.PeersList. /// </summary> public static void Build_XML_List() { XmlDocument list = new XmlDocument(); list.LoadXml("<Peers></Peers>"); for (int i = 0; i < Lists.PeersList.Count; i++) { Objects.Peer peer = (Objects.Peer)Lists.PeersList.List[i]; if (peer.ID != "" && peer.ID != null) { XmlElement XE_peer = list.CreateElement("_" + peer.ID); XmlElement peer_IP = list.CreateElement("IP"); peer_IP.InnerText = peer.IP; XE_peer.AppendChild(peer_IP); XmlElement peer_time = list.CreateElement("Time"); peer_time.InnerText = peer.Date.ToString(); XE_peer.AppendChild(peer_time); XmlElement peer_files = list.CreateElement("Files"); try { for (int j = 0; j < peer.Files.Count; j++) { Objects.Peer.File file = peer.Files[j]; XmlElement file_sha = list.CreateElement("_" + file.SHA1); XmlElement file_name = list.CreateElement("Name"); file_name.InnerText = file.Name; file_sha.AppendChild(file_name); XmlElement file_size = list.CreateElement("Size"); file_size.InnerText = file.Size.ToString(); file_sha.AppendChild(file_size); peer_files.AppendChild(file_sha); } } catch { } XE_peer.AppendChild(peer_files); list.DocumentElement.AppendChild(XE_peer); } } // save the list XmlTextWriter writer = new XmlTextWriter(Global.iKiwiPath + "List.xml", null); writer.Formatting = Formatting.Indented; while (true) { try { list.Save(writer); writer.Flush(); writer.Close(); return; } catch { Thread.Sleep(1); } } }
public override void Process() { // read all the informations of the message sender and add them to the Lists.PeersList apposite item List<Objects.Peer.File> files = new List<Objects.Peer.File>(); if (m_arrFiles != null) { for (int i = 0; i < m_arrFiles.Length; i++) { Objects.Peer.File pFile = new Objects.Peer.File(); pFile.Name = m_arrFiles[i].Name; pFile.Size = m_arrFiles[i].Size; pFile.SHA1 = m_arrFiles[i].SHA1; files.Add(pFile); } } Lists.PeersList.UpdatePeer_ID_Files(this.SenderPeer.IP, m_strPeerID, files); }
public override void Process() { // read all the informations of the message sender and add them to the Lists.PeersList apposite item List<Objects.Peer.File> files = new List<Objects.Peer.File>(); if (m_arrFiles != null) { for (int i = 0; i < m_arrFiles.Length; i++) { Objects.Peer.File pFile = new Objects.Peer.File(); pFile.Name = m_arrFiles[i].Name; pFile.Size = m_arrFiles[i].Size; pFile.SHA1 = m_arrFiles[i].SHA1; files.Add(pFile); } } Lists.PeersList.UpdatePeer_ID_Files(this.SenderPeer.IP, m_strPeerID, files); // reply with a PO-message string[] PO_Params = new string[(Lists.FilesList.Count * 3) + 1]; PO_Params[0] = Global.MyPeerID; int n = 0; for (int i = 1; i < PO_Params.Length; i += 3) { if (n < Lists.FilesList.Count) { PO_Params[i] = Lists.FilesList.List[n].Name; PO_Params[i + 1] = Lists.FilesList.List[n].Size.ToString(); PO_Params[i + 2] = Lists.FilesList.List[n].SHA1; n++; } else { Array.Resize(ref PO_Params, i); break; } } // reply IMessage POmessage = MessagesFactory.Instance.CreateMessage(Commands.PO, PO_Params); this.SenderPeer.Send(POmessage); }