Example #1
0
        public Message CreateAddMemoMessage(Memo memo)
        {
            MemoInfo memoInfo = new MemoInfo (memo);

            Message message = new Message (network, MessageType.AddMemo);
            message.Content = memoInfo;
            return message;
        }
Example #2
0
 public Memo(Network network, MemoInfo memoInfo)
 {
     this.network = network;
     this.id = memoInfo.ID;
     this.node = network.Nodes[memoInfo.FromNodeID];
     this.createdOn = memoInfo.CreatedOn;
     this.signature = memoInfo.Signature;
     this.subject = memoInfo.Subject;
     this.text = memoInfo.Text;
 }
Example #3
0
        internal void ProcessAddMemoMessage(Node messageFrom, MemoInfo memoInfo)
        {
            Memo memo = new Memo (network, memoInfo);

            if (!Core.IsLocalNode(memo.Node)) {
                if (network.TrustedNodes.ContainsKey(memo.Node.NodeID) && memo.Verify() == false) {
                    LoggingService.LogWarning("Ignored a memo with an invalid signature!");
                    return;
                }
                network.AddOrUpdateMemo(memo);
            }
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
0
        public void SyncNetworkInfo()
        {
            foreach (NetworkInfo info in networks) {
                foreach (Network network in Core.Networks) {
                    if (network.NetworkID == info.NetworkID) {
                        info.TrustedNodes.Clear();
                        foreach (TrustedNodeInfo tni in network.TrustedNodes.Values) {
                            info.TrustedNodes.Add(tni.NodeID, tni);
                        }

                        info.Memos.Clear();
                        foreach (Memo memo in network.Memos) {
                            if (Core.IsLocalNode(memo.Node)) {
                                var memoInfo = new MemoInfo(memo);
                                memoInfo.FromNodeID = null;
                                info.Memos.Add(memoInfo);
                            }
                        }

                        break;
                    }
                }
            }
        }