public void CreateNewSessionKey() { if (this.FinishedKeyExchange == false) { // The logic elsewhere is to call this method unless RemoteHasKey == true. // That needs to be cleaned up, because this is pointless. if (sentKeyExchange == true) { //LogManager.Current.WriteToLog("CreateNewSessionKey() AGAIN for " + this.ToString() + "\n" + Environment.StackTrace); return; } try { Core.LoggingService.LogInfo("Creating secure communication channel to {0}...", this.ToString()); sentKeyExchange = true; byte[] keyExchange = diffieHellman.CreateKeyExchange(); Message m = network.MessageBuilder.CreateNewSessionKeyMessage(this, keyExchange); AckMethod c = new AckMethod(); c.args = new object[] { this }; c.Method += new AckMethod.MethodEventHandler(network.NewSessionKeyReady); network.AckMethods.Add(m.MessageID, c); network.SendRoutedMessage(m); } catch (Exception ex) { Core.LoggingService.LogError("Failed to create key exchange! Hopefully we will retry... " + ex.Message); sentKeyExchange = false; throw ex; } } else { Core.LoggingService.LogWarning("Why are we trying to CreateNewSessionKey for {0} when FinishedKeyExchange=True?", this.ToString()); } }
internal void ProcessAckMessage(Node messageFrom, string hash) { if (network.AckMethods.ContainsKey(hash)) { AckMethod m = network.AckMethods[hash]; m.CallMethod(DateTime.Now); network.AckMethods.Remove(hash); } }
public void CreateNewSessionKey() { if (this.FinishedKeyExchange == false) { // The logic elsewhere is to call this method unless RemoteHasKey == true. // That needs to be cleaned up, because this is pointless. if (sentKeyExchange == true) { //LogManager.Current.WriteToLog("CreateNewSessionKey() AGAIN for " + this.ToString() + "\n" + Environment.StackTrace); return; } try { LoggingService.LogInfo("Creating secure communication channel to {0}...", this.ToString()); sentKeyExchange = true; byte[] keyExchange = diffieHellman.CreateKeyExchange(); Message m = network.MessageBuilder.CreateNewSessionKeyMessage(this, keyExchange); AckMethod c = new AckMethod(); c.args = new object[]{ this }; c.Method += new AckMethod.MethodEventHandler(network.NewSessionKeyReady); network.AckMethods.Add(m.MessageID, c); network.SendRoutedMessage(m); } catch (Exception ex) { LoggingService.LogError("Failed to create key exchange! Hopefully we will retry..."); sentKeyExchange = false; throw ex; } } else { LoggingService.LogWarning("Why are we trying to CreateNewSessionKey for {0} when FinishedKeyExchange=True?", this.ToString()); } }
private void base_SendMessage(object sender, EventArgs args) { AddToChat(network.LocalNode, inputTextView.Buffer.Text); Message message = network.SendPrivateMessage(node, inputTextView.Buffer.Text); AckMethod method = new AckMethod (); method.Method += (AckMethod.MethodEventHandler)DispatchService.GuiDispatch(new AckMethod.MethodEventHandler(OnMessageReceived)); method.MessageID = message.MessageID; network.AckMethods.Add (method.MessageID, method); LoggingService.LogDebug("Sending message..."); }
private void messageSenderSendButton_Clicked(object sender, EventArgs args) { TreeIter iter; if (messageSenderToComboBox.GetActiveIter(out iter)) { Network network = (Network)messageSenderToComboBox.Model.GetValue(iter, 1); Node node = (Node)messageSenderToComboBox.Model.GetValue(iter, 2); for (int x = 0; x < 10; x++) { Thread thread = new Thread(delegate () { try { for (int y = 0; y < 10; y++) { double kilobytes = messageSenderSizeSpinButton.Value; string data = new String('X', (int)kilobytes * 1024); Message message = new Message(network, MessageType.Test); message.To = node.NodeID; message.Content = data; AckMethod m = new AckMethod(); m.Method += MessageSent; network.AckMethods.Add(message.MessageID, m); network.SendRoutedMessage(message); Gtk.Application.Invoke(delegate { messageSenderLogTextView.Buffer.Text += "\nSending..."; }); } } catch (Exception ex) { Gtk.Application.Invoke(delegate { messageSenderLogTextView.Buffer.Text += "\n" + ex; }); } }); thread.Start(); } } }