예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 public Node(NodeSession <T> nodeSession)
     : this(nodeSession.ReceivedPublicKey)
 {
     session = nodeSession;
 }