private void Session_RawMessageReceived(NodeSession <T> sender, NodeMessage <T> message, byte[] payload) { if (message.Receiver != null) { if (message.Receiver.Equals(keyPair.Public)) { HandleMessage(message, payload); } else { rootNode.Find(message.Receiver).Session.SendMessage(message, payload); } } else { foreach (var node in rootNode.Children.Where(o => !o.PublicKey.Equals(sender.ReceivedPublicKey))) { node.Session.SendMessage(message, payload); } HandleMessage(message, payload); } }
private Node <T> SetupNode(CryptedStream cryptStream) { var session = new NodeSession <T>(cryptStream); session.InternalExceptionOccured += Session_InternalExceptionOccured; session.RawMessageReceived += Session_RawMessageReceived; var joinMsg = new NodeJoinedMessage() { ParentPublicKey = rootNode.PublicKey, PublicKey = session.ReceivedPublicKey, }; foreach (var n in rootNode.Children) { n.Session.SendMessage(null, joinMsg, null); } foreach (var n in rootNode.GetAllChildren(true, true)) { session.SendMessage(null, new NodeJoinedMessage() { ParentPublicKey = n.Parent.PublicKey, PublicKey = n.PublicKey, }, null); } var node = new Node <T>(session); rootNode.AddChild(node); session.StartReadLoop(); CallNodeJoined(node.PublicKey); return(node); }
public Node(NodeSession <T> nodeSession) : this(nodeSession.ReceivedPublicKey) { session = nodeSession; }