Exemplo n.º 1
0
        public Message CreateMyInfoMessage(Node MessageTo)
        {
            Message p = new Message(network, MessageType.MyInfo);
            p.To = MessageTo.NodeID;
            TrustedNodeInfo t = network.TrustedNodes[MessageTo.NodeID];

            NodeInfo nodeInfo = new NodeInfo();

            nodeInfo.NodeID = network.LocalNode.NodeID;
            nodeInfo.NickName = network.LocalNode.NickName;

            nodeInfo.AvatarSize = network.LocalNode.AvatarSize;

            if (MessageTo.IsConnectedLocally == true || t.AllowNetworkInfo == true) {
                nodeInfo.DestinationInfos = Core.DestinationManager.DestinationInfos;
            }
            if (t.AllowProfile == true) {
                nodeInfo.RealName = network.LocalNode.RealName;
                nodeInfo.Email = network.LocalNode.Email;
            }
            nodeInfo.ClientName = network.LocalNode.ClientName;
            nodeInfo.ClientVersion = network.LocalNode.ClientVersion;
            if (t.AllowSharedFiles == true) {
                nodeInfo.Bytes = network.LocalNode.Bytes;
                nodeInfo.Files = network.LocalNode.Files;
            }

            List<ConnectionInfo> connections = new List<ConnectionInfo>();
            List<ChatRoomInfo> rooms = new List<ChatRoomInfo>();
            List<MemoInfo> memos = new List<MemoInfo>();

            foreach (INodeConnection con in network.Connections) {
                if (con.NodeLocal != MessageTo & con.NodeRemote != MessageTo) {
                    if (con.ConnectionState == ConnectionState.Ready | con.ConnectionState == ConnectionState.Remote) {
                        ConnectionInfo n = new ConnectionInfo();
                        Node ConnectionSourceNode = con.NodeLocal;
                        Node ConnectionDestNode = con.NodeRemote;
                        n.SourceNodeID = ConnectionSourceNode.NodeID;
                        n.SourceNodeNickname = ConnectionSourceNode.NickName;
                        n.DestNodeID = ConnectionDestNode.NodeID;
                        n.DestNodeNickname = ConnectionDestNode.NickName;
                        connections.Add (n);
                    }
                }
            }

            foreach (ChatRoom currentRoom in network.ChatRooms) {
                ChatRoomInfo roomInfo = new ChatRoomInfo();
                roomInfo.Id = currentRoom.Id;
                roomInfo.Name = currentRoom.Name;
                roomInfo.Users = new string[currentRoom.Users.Count];
                int x = 0;
                foreach (Node node in currentRoom.Users.Values) {
                    roomInfo.Users[x] = node.NodeID;
                    x ++;
                }
                rooms.Add(roomInfo);
            }

            foreach (Memo currentMemo in network.Memos) {
                if (Core.IsLocalNode(currentMemo.Node)) {
                    MemoInfo info = new MemoInfo(currentMemo);
                    memos.Add(info);
                }
            }

            nodeInfo.KnownConnections = connections.ToArray();
            nodeInfo.KnownChatRooms = rooms.ToArray();
            nodeInfo.KnownMemos = memos.ToArray();

            p.Content = nodeInfo;
            return p;
        }
Exemplo n.º 2
0
        public Message CreateHelloMessage()
        {
            Message message = new Message (network, MessageType.Hello);
            HelloInfo hello = new HelloInfo ();

            List<ConnectionInfo> connections = new List<ConnectionInfo>();
            List<ChatRoomInfo> rooms = new List<ChatRoomInfo>();
            List<MemoInfo> memos = new List<MemoInfo>();

            foreach (INodeConnection con in network.Connections) {
                if (con.ConnectionState == ConnectionState.Ready | con.ConnectionState == ConnectionState.Remote) {
                    ConnectionInfo n = new ConnectionInfo();
                    Node ConnectionSourceNode = con.NodeLocal;
                    Node ConnectionDestNode = con.NodeRemote;
                    n.SourceNodeID = ConnectionSourceNode.NodeID;
                    n.SourceNodeNickname = ConnectionSourceNode.NickName;
                    n.DestNodeID = ConnectionDestNode.NodeID;
                    n.DestNodeNickname = ConnectionDestNode.NickName;
                    connections.Add(n);
                }
            }

            foreach (ChatRoom currentRoom in network.ChatRooms) {
                ChatRoomInfo tmpRoom = new ChatRoomInfo();
                tmpRoom.Id = currentRoom.Id;
                tmpRoom.Name = currentRoom.Name;
                tmpRoom.Users = new string[currentRoom.Users.Count];
                int x = 0;
                foreach (Node node in currentRoom.Users.Values) {
                    tmpRoom.Users[x] = node.NodeID;
                    x ++;
                }
                rooms.Add(tmpRoom);
            }

            foreach (Memo currentMemo in network.Memos) {
                MemoInfo info = new MemoInfo(currentMemo);
                memos.Add(info);
            }

            hello.KnownConnections = connections.ToArray();
            hello.KnownChatRooms = rooms.ToArray();
            hello.KnownMemos = memos.ToArray();
            hello.MyNickName = network.LocalNode.NickName;

            message.Content = hello;
            return message;
        }
Exemplo n.º 3
0
 public Message CreateConnectionDownMessage(string ConnectionSourceNodeID, string ConnectionDestNodeID)
 {
     Message p = new Message(network, MessageType.ConnectionDown);
     ConnectionInfo c = new ConnectionInfo();
     c.SourceNodeID = ConnectionSourceNodeID;
     c.DestNodeID = ConnectionDestNodeID;
     p.Content = c;
     return p;
 }
Exemplo n.º 4
0
 internal RemoteNodeConnection(Network theNetwork, ConnectionInfo info)
 {
     parentNetwork = theNetwork;
     thisNodeLocal = parentNetwork.Nodes[info.SourceNodeID];
     thisNodeRemote = parentNetwork.Nodes[info.DestNodeID];
 }
Exemplo n.º 5
0
        private void ProcessNewConnection(ConnectionInfo connection)
        {
            lock (nodes) {
                Node DestNode = GetNode(connection.DestNodeID);
                Node SourceNode = GetNode(connection.SourceNodeID);

                if (DestNode != this.LocalNode & SourceNode != this.LocalNode) {
                    if (DestNode != SourceNode) {

                        if (this.FindConnection(connection.SourceNodeID, connection.DestNodeID) == null) {

                            if (SourceNode == null) {
                                SourceNode = new Node(this, connection.SourceNodeID);
                                SourceNode.NickName = connection.SourceNodeNickname;
                                AddNode(SourceNode);
                                if (this.TrustedNodes.ContainsKey(SourceNode.NodeID)) {
                                    SourceNode.CreateNewSessionKey();
                                }
                            } else {
                                SourceNode.NickName = connection.SourceNodeNickname;
                            }

                            if (DestNode == null) {
                                DestNode = new Node(this, connection.DestNodeID);
                                DestNode.NickName = connection.DestNodeNickname;
                                AddNode(DestNode);
                                if (this.TrustedNodes.ContainsKey(DestNode.NodeID)) {
                                    DestNode.CreateNewSessionKey();
                                }
                            } else {
                                DestNode.NickName = connection.DestNodeNickname;
                            }

                            RemoteNodeConnection c = new RemoteNodeConnection(this);
                            c.NodeLocal = SourceNode;
                            c.NodeRemote = DestNode;
                            c.ConnectionState = ConnectionState.Remote;
                            AddConnection(c);
                        } else {
                            // I am not really sure if this is actually useful...
                            SourceNode.NickName = connection.SourceNodeNickname;
                            DestNode.NickName = connection.DestNodeNickname;
                        }
                    } else {
                        LoggingService.LogWarning("Someone told me about an invalid connection - both sides are the same?! Thats no good!! " + connection.SourceNodeNickname + " <-> " + connection.DestNodeNickname);
                    }
                } else {
                    if (this.FindConnection(connection.SourceNodeID, connection.DestNodeID) == null) {
                        LoggingService.LogWarning("THAT CONNECTION DOESNT EXIST!!!" + connection.SourceNodeNickname + " <-> " + connection.DestNodeNickname);
                        this.SendBroadcast(this.MessageBuilder.CreateConnectionDownMessage(connection.SourceNodeID, connection.DestNodeID), this.LocalNode);
                    }
                }
            }
        }
Exemplo n.º 6
0
 internal void ProcessConnectionDownMessage(Node messageFrom, ConnectionInfo info)
 {
     INodeConnection c = network.FindConnection(info.SourceNodeID, info.DestNodeID);
     if (c != null) {
         network.RemoveConnection(c);
     } else {
         LoggingService.LogWarning("MessageProcessor: ConnectionDown received from {0} for a non-existant connection!", messageFrom);
     }
     network.Cleanup();
 }