internal void SendMessage(Message message) { if (connectionState == ConnectionState.Disconnected) { throw new InvalidOperationException("Not connected"); } // XXX: Clean up this validation if (message.From == transport.Network.LocalNode.NodeID && message.To != String.Empty && Network.InsecureMessageTypes.IndexOf(message.Type) == -1) { if (!transport.Network.TrustedNodes.ContainsKey(message.To)) { throw new Exception("You cannot send messages to untrusted nodes." + Environment.NewLine + " Type: " + message.Type + Environment.NewLine + " From: " + message.From + Environment.NewLine + " To: " + message.To + Environment.NewLine + " MessageID: " + message.MessageID); } } AsyncCallback messageSentCallback = new AsyncCallback(MessageSent); SentMessageInfo info = new SentMessageInfo(); byte[] messageBytes = message.GetAssembledData(); transport.BeginSendMessage(messageBytes, messageSentCallback, info); info.Connection = this; info.Message = message; Core.RaiseMessageSent(info); }