public static void OnIdChanged() { if (IdChanged != null) { IdHandler messageDelegate = null; Delegate[] invocationList_ = IdChanged.GetInvocationList(); lock (typeof(RemoteZeus)) { foreach (Delegate del in invocationList_) { try { messageDelegate = (IdHandler)del; // levantar nuevo hilo para manejar la llamada de vuelta new Thread( () => RunDelegate(messageDelegate, ZeusWin.IdExpediente)). Start(); } catch { IdChanged -= messageDelegate; } } } } }
private void BtnConfirmPathClick(object sender, EventArgs e) { string hiddenPath = PathName() + @".hidden\", newPath = PathName() + @"TorPdos\"; if (Directory.Exists(PathName()) == true) { if (!Directory.Exists(hiddenPath) && chkCreateFolder.Checked == false) { DiskHelper.SetRegistryValue("Path", PathName()); HiddenFolder dih = new HiddenFolder(hiddenPath); } else if (Directory.Exists(hiddenPath) && chkCreateFolder.Checked == false) { DiskHelper.SetRegistryValue("Path", PathName()); } else if (chkCreateFolder.Checked == true) { DiskHelper.SetRegistryValue("Path", newPath); DirectoryInfo di = Directory.CreateDirectory(newPath); HiddenFolder dih = new HiddenFolder(newPath + @".hidden\"); } if (IdHandler.UserExists()) { Login(); } else { Create(); } } }
void BtnLoginClick(object sender, EventArgs e) { string pass = txtPassword.Text; string path = DiskHelper.GetRegistryValue("Path"); if (IdHandler.IsValidUser(pass)) { IdHandler.GetUuid(pass); LoggedIn(); loggedIn = true; _idx = new Index(path); _p2P = new Network(25565, _idx, path); _p2P.Start(); _idx.Load(); IndexEventHandlers(); if (!_idx.Load()) { _idx.BuildIndex(); } _idx.Start(); _idx.MakeIntegrityCheck(); } else { Controls.Add(lblNope); } }
public MyForm() { EventHandlers(); GuiLayout(); if (!string.IsNullOrEmpty(IdHandler.GetUuid())) { LoggedIn(); } else { if (NetworkPorts.IsPortAvailable(25565) == false) { Sorry(); } else if (String.IsNullOrEmpty(DiskHelper.GetRegistryValue("Path")) == true || Directory.Exists(DiskHelper.GetRegistryValue("Path")) == false) { FirstStartUp(); } else if (File.Exists(DiskHelper.GetRegistryValue("Path") + @".hidden\userdata") == false) { Create(); } else { Login(); } } }
/// <summary> /// Function to receive peers from one or your peers peer list /// </summary> /// <param name="message">It is the message which is sent to the receiver</param> private void ReceivedPeerFetch(PeerFetcherMessage message) { if (message.type.Equals(TypeCode.REQUEST)) { var outgoing = new List <Peer>(); var incoming = message.peers; // Adding sender to list if (!InPeerList(message.fromUuid, _peers)) { _peers.TryAdd(message.fromUuid, new Peer(message.fromUuid, message.fromIp)); } //Checks whether a incomming peer exists in the peerlist. foreach (var incomingPeer in incoming) { if (InPeerList(incomingPeer.GetUuid(), _peers)) { break; } _peers.TryAdd(incomingPeer.GetUuid(), incomingPeer); DiskHelper.ConsoleWrite("Peer added: " + incomingPeer.GetUuid()); } foreach (var outGoingPeer in _peers) { if (InPeerList(outGoingPeer.Value.GetUuid(), incoming)) { break; } if (outGoingPeer.Value.GetUuid() == message.fromUuid) { break; } outgoing.Add(outGoingPeer.Value); } message.CreateReply(); message.peers = outgoing; message.Send(); } else { // Rechieved response foreach (Peer incomingPeer in message.peers) { if (InPeerList(incomingPeer.GetUuid(), _peers)) { break; } if ((IdHandler.GetUuid().Equals(incomingPeer.GetUuid()))) { break; } _peers.TryAdd(incomingPeer.GetUuid(), incomingPeer); Console.WriteLine("Peer added: " + incomingPeer.GetUuid()); } } }
public BaseMessage(Peer to) { this._toUuid = to.GetUuid(); this.toIp = to.GetIp(); this.fromUuid = IdHandler.GetUuid(); this.fromIp = NetworkHelper.GetLocalIpAddress(); this.type = TypeCode.REQUEST; this.statusCode = StatusCode.OK; }
public void GetUUidIsCorrect() { string expected = IdHandler.CreateUser(Password); string result = IdHandler.GetUuid(Password); IdHandler.RemoveUser(); Assert.AreEqual(expected, result); }
public void WrongPasswordInvalidUser() { IdHandler.CreateUser(Password); bool result = IdHandler.IsValidUser("wrong"); IdHandler.RemoveUser(); Assert.IsFalse(result); }
private void RestoreOriginalFile(string path, P2PFile fileInformation) { DiskHelper.ConsoleWrite("File exist"); string pathWithoutExtension = (_path + @".hidden\incoming\" + fileInformation.hash); //Merge files var splitterLibrary = new SplitterLibrary(); if (!splitterLibrary.MergeFiles(_path + @".hidden\incoming\" + fileInformation.hash + @"\", pathWithoutExtension + ".aes", fileInformation.GetChunksAsString())) { _queue.Enqueue(fileInformation); return; } // Decrypt file var decryption = new FileEncryption(pathWithoutExtension, ".lzma"); if (!decryption.DoDecrypt(IdHandler.GetKeyMold())) { _queue.Enqueue(fileInformation); return; } DiskHelper.ConsoleWrite("File decrypted"); File.Delete(path); // Decompress file string pathToFileForCopying = Compressor.DecompressFile(pathWithoutExtension + ".lzma", pathWithoutExtension); DiskHelper.ConsoleWrite("File decompressed"); foreach (string filePath in _index.GetEntry(_fileHash).paths) { if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath) ?? throw new NullReferenceException()); } try{ if (!File.Exists(filePath)) { File.Copy(pathToFileForCopying, filePath); DiskHelper.ConsoleWrite($"File saved to: {filePath}"); } } catch (Exception e) { logger.Error(e); } } }
public void ValidateUser() { IdHandler.CreateUser(Password); bool result = IdHandler.IsValidUser(Password); IdHandler.RemoveUser(); Assert.IsTrue(result); }
public void GenerateUuidIsRandom() { string notExpected = IdHandler.CreateUser(Password); System.Threading.Thread.Sleep(5000); string actual = IdHandler.CreateUser(Password); IdHandler.RemoveUser(); Assert.AreNotEqual(notExpected, actual); }
private void BtnCreateClick(object sender, EventArgs e) { if (txtPassword.Text == txtConfirmPassword.Text) { IdHandler.CreateUser(txtPassword.Text); Login(); } else { Controls.Add(lblNope2); } }
private static void RunDelegate(IdHandler del, int param) { try { del(param); } catch { lock (typeof(RemoteZeus)) { IdChanged -= del; } } }
//此处生成的ItemData,除item未初始化以外其他均以初始化完成 public static ItemData GenerateItemData(GNET.Smshopdata data, IdHandler handler) { ItemData itemTemp = new ItemData(); itemTemp.SetCurrentId = handler; itemTemp.id = data.id; itemTemp.isopen = data.isopen; itemTemp.price = data.price; itemTemp.mysteriousshopTemplate = DataTemplate.GetInstance().GetMysteriousShopItemTemplateById(data.id); //43表一条数据 itemTemp.itemTemplate = DataTemplate.GetInstance().GetItemTemplateById(itemTemp.mysteriousshopTemplate.getCommodityid()); //26表一条数据 return(itemTemp); }
public void RemoveIdChanged(IdHandler handler) { IdChanged -= handler; }
public void AddIdChanged(IdHandler handler) { IdChanged += handler; }
static void Main() { bool running = true; bool firstRun = true; MyForm torPdos = new MyForm(); //If the ''Path'' variable is not set, the GUI is run to set this up. if (string.IsNullOrEmpty(DiskHelper.GetRegistryValue("Path"))) { Application.Run(torPdos); } //If the ''Path'' variable is set, but the userdata file does not exist, //the GUI is run to create this. else if (File.Exists(DiskHelper.GetRegistryValue("Path") + @".hidden\userdata") == false) { Application.Run(torPdos); } //Gets the local IP and the path to the users TorPDos-folder. string ownIp = NetworkHelper.GetLocalIpAddress(); string path = (DiskHelper.GetRegistryValue("Path")); //Starts the communication with the user, and ensures that //the user logs in. DiskHelper.ConsoleWrite("Welcome to TorPdos!"); Console.WriteLine(@"Please login by typing: login [PASSWORD] or gui"); while (running) { string console = Console.ReadLine(); if (console != null) { string[] param = console.Split(' '); //Close program if (console.Equals("quit") || console.Equals("q")) { Console.WriteLine(@"Quitting..."); _idx.Save(); _idx.Stop(); _p2P.SavePeer(); _p2P.Stop(); running = false; Console.WriteLine(" \n Press any button to quit!"); } else { //Handles the login of the user through the console. while (IdHandler.GetUuid() == null) { if (console.StartsWith("login") && param.Length == 2) { if (IdHandler.GetUuid(param[1]) == "Invalid Password") { Console.WriteLine(); Console.WriteLine(@"Invalid password, try again"); Console.WriteLine(@"Please login by typing: login [PASSWORD] or gui"); console = Console.ReadLine(); if (console != null) { param = console.Split(' '); } } //Gives the opportunity to open the GUI for login. } else if (console.Equals("gui")) { Application.Run(torPdos); } else { Console.WriteLine(); Console.WriteLine(@"Error! Try again"); Console.WriteLine(@"Please login by typing: login [PASSWORD] or gui"); console = Console.ReadLine(); param = console.Split(' '); } } //Handles the creation or loading of all the necessary //files and directories. if (firstRun) { // Load Index if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } _idx = new Index(path); torPdos._idx = _idx; // Prepare P2PNetwork try{ _p2P = new Network(25565, _idx, path); _p2P.Start(); torPdos._p2P = _p2P; } catch (SocketException) { Application.Run(torPdos); } _idx.Load(); _idx.FileAdded += Idx_FileAdded; _idx.FileChanged += Idx_FileChanged; _idx.FileDeleted += Idx_FileDeleted; _idx.FileMissing += Idx_FileMissing; if (!_idx.Load()) { _idx.BuildIndex(); } _idx.Start(); Console.WriteLine(@"Integrity check initialized..."); _idx.MakeIntegrityCheck(); Console.WriteLine(@"Integrity check finished!"); Console.WriteLine(@"Local: " + ownIp); Console.WriteLine(@"Free space on C: " + DiskHelper.GetTotalAvailableSpace("C:\\")); Console.WriteLine(@"UUID: " + IdHandler.GetUuid()); firstRun = false; //Restart loop to take input continue; } // Handle input if (console.StartsWith("add") && param.Length == 3) { _p2P.AddPeer(param[1].Trim(), param[2].Trim()); } else if (console.Equals("reindex")) { _idx.ReIndex(); } else if (console.Equals("gui")) { MyForm torPdos2 = new MyForm(); Application.Run(torPdos2); } else if (console.Equals("status")) { _idx.Status(); } else if (console.Equals("idxsave")) { _idx.Save(); } else if (console.Equals("peersave")) { _p2P.SavePeer(); } else if (console.Equals("ping")) { _p2P.Ping(); } else if (console.Equals("integrity")) { _idx.MakeIntegrityCheck(); } else if (console.Equals("list")) { List <Peer> peers = _p2P.GetPeerList(); Console.WriteLine(); Console.WriteLine(@"### Your Peerlist contains ###"); if (peers.Count > 0) { foreach (Peer peer in peers) { RankingHandler rankingHandler = new RankingHandler(); rankingHandler.GetRank(peer); Console.WriteLine(@"(R:" + peer.Rating + @") " + peer.GetUuid() + @" - " + peer.GetIp() + @" - " + (peer.IsOnline() ? "Online" : "Offline")); Console.WriteLine(@"disk: " + Convert.ToInt32((peer.diskSpace / 1e+9)) + @"GB | avgPing: " + peer.GetAverageLatency() + "\n"); } } else { Console.WriteLine(@"The list is empty..."); } Console.WriteLine(); } else if (console.Trim().Equals("")) { } else { Console.WriteLine(@"Unknown command"); } } } } Console.ReadKey(); }
/// <summary> /// Main running function for UploadManager, needs to be called for it to run. /// </summary> public void Run() { _isStopped = false; this._waitHandle.Set(); while (_isRunning) { this._waitHandle.WaitOne(); if (!_isRunning) { break; } while (this._queue.TryDequeue(out P2PFile file)) { bool uploaded = true; if (!_peers.Any(p => p.Value.IsOnline())) { this._queue.Enqueue(file); break; } if (!_isRunning) { this._queue.Enqueue(file); break; } string filePath = file.paths[0]; string compressedFilePath = this._path + @".hidden\" + file.hash; // Compress file bool compressionCompleted = Compressor.CompressFile(filePath, compressedFilePath); if (!compressionCompleted) { this._queue.Enqueue(file); continue; } // Encrypt file var encryption = new FileEncryption(compressedFilePath, ".lzma"); bool encryptionCompleted = encryption.DoEncrypt(IdHandler.GetKeyMold()); if (!encryptionCompleted) { this._queue.Enqueue(file); continue; } _hiddenFolder.Remove(compressedFilePath + ".lzma"); string encryptedFilePath = compressedFilePath + ".aes"; // Initialize splitter var splitter = new SplitterLibrary(); List <string> chunks = splitter.SplitFile(encryptedFilePath, file.hash, _path + @".hidden\splitter\"); file.AddChunk(chunks); FileUploader uploader = new FileUploader(_ports, _peers); int i = 0; foreach (var chunk in file.chunks) { string path = _path + @".hidden\splitter\" + chunk.hash; //3 is used, because the network is relatively small. 10 is the default. if (!uploader.Push(chunk, path, 3, i)) { uploaded = false; } i++; } if (!uploaded) { this._queue.Enqueue(file); } if (uploaded) { Console.WriteLine(); DiskHelper.ConsoleWrite($"The file {file.hash} was successfully sent to all \n"); } } this._waitHandle.Reset(); } _isStopped = true; }
public override bool Equals(object obj) { return(obj is Topic topic && Nombre.Equals(topic.Nombre) && IdHandler.Equals(topic.IdHandler)); }
/// <summary> /// register the delegate. /// </summary> /// <param name="_del"></param> public void RegisterHandler(IdHandler _del) { del = _del; }
public Entity() { id = IdHandler.GetUniqueId(); }