public void addClient(Member client, ulong sessionID)
 {
     ClientSession newSession = new ClientSession(client, sessionID);
     clientDB.Add(newSession.sessionID, newSession);
     ArrayList clientSessions = new ArrayList(1);
     clientSessions.Add(newSession.sessionID);
     sessionTable.Add(client.privateUserInfo.userID, clientSessions);
 }
 public bool addAccount(string userName, byte[] password, Member user)
 {
     Member newMember = new Member(userName, password, user.publicUserInfo, user.privateUserInfo, user.node,user.lords);
     if(accounts.Contains(user.privateUserInfo.userID))
         return false;
     accounts.Add(user.privateUserInfo.userID, newMember);
     userIDNameTable.Add(userName, user.privateUserInfo.userID);
     return true;
 }
 public void removeExistingClient(Member existingClient)
 {
     //update connection list
     foreach(DataRow dr in clientsTable.Rows)
     {
         if((uint)dr[0] == existingClient.privateUserInfo.userID)
         {
             clientsTable.Rows.Remove(dr);
             numClients.Text = Convert.ToString((Convert.ToUInt32(numClients.Text)-1));
             break;
         }
     }
 }
        public bool removeClient(Member client, ulong sessionID)
        {
            if(client == null)
                return false;

            object clientSessionObj = clientDB[sessionID];
            if(clientSessionObj == null)
                return false;

            clientDB.Remove(((ClientSession)clientSessionObj).sessionID);
            sessionTable.Remove(client.privateUserInfo.userID);
            return true;
        }
 public void updateExistingClient(Member existingClient)
 {
     int index = 0;
     bool found = false;
     //update connection list
     foreach(DataRow dr in clientsTable.Rows)
     {
         if((uint)dr[0] == existingClient.privateUserInfo.userID)
         {
             clientsTable.Rows.InsertAt(getClientRow(existingClient), index);
             clientsTable.Rows.Remove(dr);
             numClients.Text = Convert.ToString((Convert.ToUInt32(numClients.Text)-1));
             found = true;
             break;
         }
         index++;
     }
     if (!found)
         clientsTable.Rows.Add(getClientRow(existingClient));
 }
        public ClientSession findClientSession(Member client)
        {
            object clientSessionIDsObj = sessionTable[client.privateUserInfo.userID];
            if(clientSessionIDsObj == null)
                return null;

            ArrayList clientSessionIDs = (ArrayList)clientSessionIDsObj;
            for(int clientSessionIDIndx = 0; clientSessionIDIndx < clientSessionIDs.Count;
                clientSessionIDIndx++)
            {
                ulong sessionID = (ulong)clientSessionIDs[clientSessionIDIndx];
                ClientSession foundClient = (ClientSession)clientDB[sessionID];

                //only one instance from a device per user is allowed
                if(foundClient.user.node.syncCommunicationPoint.Equals(client.node.syncCommunicationPoint))
                    return foundClient;
            }

            return null;
        }
        public void loadAccounts()
        {
            string[] memberNames = {"bosnia", "albania", "france", "germany", "italy", "poland",
                                       "romania", "spain", "greece", "turkey", "israel", "palestine",
                                       "jordan", "syria", "iraq", "iran", "afghanistan", "pakistan",
                                       "india", "russia", "china", "indonesia", "taiwan", "vietnam",
                                       "thailand", "japan", "austrailia", "brazil", "peru", "mexico"};

            Random randomizer = new Random(System.DateTime.Now.Millisecond);
            Member[] members = new Member[memberNames.Length];
            int index = 0;
            foreach (string name in memberNames)
            {
                Member member = new Member(name, ASCIIEncoding.ASCII.GetBytes(name),
                    new PublicUserInfo(name), new PrivateUserInfo(userIDCounter++, "Mr.", "jose",
                "garcia", "morena", "III", "23 El dorado Rd", "San Pablo", 123477, "California", name),
                    new Node(new IPEndPoint(System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0],
                    1024 + randomizer.Next() % 14000), new IPEndPoint(System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0],
                    1024 + randomizer.Next() % 14000), Constants.LineSpeedType.LNSPEED_DSL));
                member.lords = Constants.DEFAULT_LORDS;
                members[index++] = member;
            }

            TextWriter writer = new StreamWriter(accountsFile);
            XmlSerializer serializer = new XmlSerializer(typeof(Member[]));
            serializer.Serialize(writer, members);
            writer.Close();

            XmlReader reader = new XmlTextReader(accountsFile);
            XmlSerializer deserializer = new XmlSerializer(typeof(Member[]));
            Member[] existingMembers = (Member[])deserializer.Deserialize(reader);
            foreach (Member existingMember in existingMembers)
            {
                addAccount(existingMember.userName, existingMember.password, existingMember);
            }
            reader.Close();
        }
Пример #8
0
        private void processClientRingLogin(BinaryReader clientReader, BinaryWriter clientWriter)
        {
            //deserialize the message
            BinaryFormatter deserializer = new BinaryFormatter();
            uint ringID = (uint)deserializer.Deserialize(clientReader.BaseStream);
            string userName = (string)deserializer.Deserialize(clientReader.BaseStream);
            byte[] password = (byte[])deserializer.Deserialize(clientReader.BaseStream);
            IPEndPoint commPoint = (IPEndPoint)deserializer.Deserialize(clientReader.BaseStream);
            InformationEntropy[] IE = (InformationEntropy[])deserializer.Deserialize(clientReader.BaseStream);

            ServerRingInfo serverRingInfo = ServerRingInfo.findServerRingInfoByID(this.serverRingsInfo, ringID);
            byte[] message = new byte[Constants.WRITEBUFFSIZE];
            MemoryStream stream = new MemoryStream(message);
            BinaryFormatter serializer = deserializer; //reuse the object
            Member member = null;

            NetLib.insertEntropyHeader(serializer, stream);

            //not a member need to signup first, goodbye =)
            if((member = accountsManager.findMemberByUserName(userName)) == null)
            {
                deserializer.Serialize(stream, Constants.MessageTypes.MSG_NOTAMEMBER);
                clientWriter.Write(message);
                clientWriter.Flush();
                return;
            }

            ClientSession session;
            ulong sessionID;
            Peer memberAsPeer = new Peer(member.node, member.publicUserInfo, IE);

            //get users current node settings
            member.node.syncCommunicationPoint = commPoint;

            //Already on the network from the requesting device (are you a hacker?)
            if((session = serverRingInfo.ringClientManager.findClientSession(member)) == null)
            {
                //get a session ID add the user to the client manager database
                sessionID = serverRingInfo.getNextSessionID();

                serverRingInfo.ringClientManager.addClient(member, sessionID);
            }
            else
                sessionID = session.sessionID;

            memberAsPeer.token = sessionID;
            //give the session id and adjacent peers
            serializer.Serialize(stream, Constants.MessageTypes.MSG_RINGNEIGHBORS);
            serializer.Serialize(stream, sessionID);
            serializer.Serialize(stream, serverRingInfo.serverPolicyManager.getSearchQueryPolicy());
            serializer.Serialize(stream, serverRingInfo.serverPolicyManager.queryServer);
            serializer.Serialize(stream, serverRingInfo.ringPeerManager.getAdjacentPeers(memberAsPeer,
                Constants.IE_MAX_KEYWORDS_TO_CONSIDER, Constants.MAX_PEERS_TO_CONSIDER_FOR_KEYWORD,
                Constants.MAX_PEERS));

            clientWriter.Write(message);
            clientWriter.Flush();

            //Now add the new peer to the database
            serverRingInfo.ringPeerManager.addPeer(memberAsPeer);

            //invoke the user interface call back to update everything that depends on a new user
            //joining the network
            Member[] methodInvokeArgs = new Member[1];
            methodInvokeArgs[0] = member;
            //Asynchronous call to the UI thread
            ServerUserInterface.serverUserInterfaceInstance.BeginInvoke(
                serverUserInterfaceCallbackTable.addNewClient, methodInvokeArgs);
        }
Пример #9
0
        /// <summary>
        /// Logoff a client and release resources
        /// </summary>
        /// <param name="clientReader">A handle for reading client Logoff message</param>
        /// <param name="clientWriter">A handle for writing to the client</param>
        private void processClientLogoff(BinaryReader clientReader, BinaryWriter clientWriter)
        {
            //deserialize the message
            BinaryFormatter deserializer = new BinaryFormatter();
            ulong sessionID = (ulong)deserializer.Deserialize(clientReader.BaseStream);
            uint ringID = (uint)deserializer.Deserialize(clientReader.BaseStream);
            string userName = (string)deserializer.Deserialize(clientReader.BaseStream);
            byte[] password = (byte[])deserializer.Deserialize(clientReader.BaseStream);

            Member member;
            //make sure that the user is the member it claims to be
            if((member = accountsManager.findMemberByUserName(userName)) == null)
                return;

            //remove the user from the client manager database
            if(!clientManager.removeClient(member, sessionID))
                return;

            //invoke the user interface call back to update everything that depends on an existing user
            //leaving the network
            Member[] methodInvokeArgs = new Member[1];
            methodInvokeArgs[0] = member;
            //Asynchronous call to the UI thread
            ServerUserInterface.serverUserInterfaceInstance.BeginInvoke(serverUserInterfaceCallbackTable.removeExistingClient, methodInvokeArgs);
        }
Пример #10
0
        /// <summary>
        /// Login a client to the server and dispatch it membership info as well as adjacent neighbors
        /// </summary>
        /// <param name="clientReader">A handle for reading client Login message</param>
        /// <param name="clientWriter">A handle for writing to the client</param>
        private void processClientLogin(BinaryReader clientReader, BinaryWriter clientWriter)
        {
            //deserialize the message
            BinaryFormatter deserializer = new BinaryFormatter();
            uint ringID = (uint)deserializer.Deserialize(clientReader.BaseStream);
            string userName = (string)deserializer.Deserialize(clientReader.BaseStream);
            byte[] password = (byte[])deserializer.Deserialize(clientReader.BaseStream);
            IPEndPoint syncCommPoint = (IPEndPoint)deserializer.Deserialize(clientReader.BaseStream);

            byte[] message = new byte[Constants.WRITEBUFFSIZE];
            MemoryStream stream = new MemoryStream(message);
            BinaryFormatter serializer = deserializer; //reuse the object
            Member member = null;

            NetLib.insertEntropyHeader(serializer, stream);
            //not a member need to signup first, goodbye =)
            if((member = accountsManager.findMemberByUserName(userName)) == null)
            {
                deserializer.Serialize(stream, Constants.MessageTypes.MSG_NOTAMEMBER);
                clientWriter.Write(message);
                clientWriter.Flush();
                return;
            }

            //Already on the network from the requesting device (are you a hacker?)
            if(clientManager.findClientSession(member) != null)
            {
                deserializer.Serialize(stream, Constants.MessageTypes.MSG_ALREADYSIGNEDIN);
                clientWriter.Write(message);
                clientWriter.Flush();
                return;
            }

            //get a session ID add the user to the client manager database
            ulong tokenID = getNextTokenID();

            //get users current node settings
            member.node.syncCommunicationPoint = syncCommPoint;
            clientManager.addClient(member, tokenID);

            //give the session id and adjacent peers
            serializer.Serialize(stream, Constants.MessageTypes.MSG_OK);
            serializer.Serialize(stream, tokenID);
            serializer.Serialize(stream, (uint)member.lords.Length);
            foreach (LordInfo lord in member.lords)
            {
                serializer.Serialize(stream, lord);
            }

            clientWriter.Write(message);
            clientWriter.Flush();

            //invoke the user interface call back to update everything that depends on a new user
            //joining the network
            Member[] methodInvokeArgs = new Member[1];
            methodInvokeArgs[0] = member;
            //Asynchronous call to the UI thread
            ServerUserInterface.serverUserInterfaceInstance.BeginInvoke(
                serverUserInterfaceCallbackTable.addNewClient, methodInvokeArgs);
        }
 public ClientSession(Member __user, ulong __sessionID)
 {
     user = __user;
     sessionID = __sessionID;
 }
        private DataRow getClientRow(Member client)
        {
            PublicUserInfo publicUserInfo = client.publicUserInfo;
            PrivateUserInfo privateUserInfo = client.privateUserInfo;

            DataRow dr = clientsTable.NewRow();
            dr[0] = privateUserInfo.userID;
            dr[1] = client.userName;
            dr[2] = (new System.Net.IPAddress(client.node.syncCommunicationPoint.Address)).ToString();
            dr[3] = privateUserInfo.prefix+" "+privateUserInfo.firstName +
                " " + privateUserInfo.middleName + " " + privateUserInfo.lastName +
                " " + privateUserInfo.suffix;
            dr[4] = privateUserInfo.streetAddress;
            dr[5] = privateUserInfo.city;
            dr[6] = privateUserInfo.state;
            dr[7] = privateUserInfo.country;

            System.Text.Encoding.ASCII.GetString(client.password);
            return dr;
        }
        public bool updateClient(Member client, ulong sessionID)
        {
            if(client == null)
                return false;

            object clientSessionObj = clientDB[sessionID];
            if(clientSessionObj == null)
                return false;

            ClientSession clientSession = (ClientSession)clientSessionObj;
            ClientSession newSession = new ClientSession(client, clientSession.sessionID);
            clientDB[clientSession.sessionID] = newSession;
            return true;
        }
Пример #14
0
        private void processClientSyncUserInfo(BinaryReader clientReader, BinaryWriter clientWriter)
        {
            //deserialize the message
            BinaryFormatter deserializer = new BinaryFormatter();
            ulong sessionID = (ulong)deserializer.Deserialize(clientReader.BaseStream);
            uint ringID = (uint)deserializer.Deserialize(clientReader.BaseStream);
            string userName = (string)deserializer.Deserialize(clientReader.BaseStream);
            byte[] password = (byte[])deserializer.Deserialize(clientReader.BaseStream);
            Member member = (Member)deserializer.Deserialize(clientReader.BaseStream);

            Member existingMember;
            //make sure that the user is the member it claims to be
            if((existingMember = accountsManager.findMemberByUserName(userName)) == null)
                return;

            //update client manager with the new info
            if(!clientManager.updateClient(existingMember, sessionID))
                return;

            //update accounts manager with the user's new info
            accountsManager.updateAccount(userName, password, member);

            //invoke the user interface call back to update everything that depends on an existing user
            //updating its settings
            Member[] methodInvokeArgs = new Member[1];
            methodInvokeArgs[0] = existingMember;
            //Asynchronous call to the UI thread
            ServerUserInterface.serverUserInterfaceInstance.BeginInvoke(serverUserInterfaceCallbackTable.updateExistingClient, methodInvokeArgs);
        }
 public void addNewClient(Member newClient)
 {
     //update connection list
     updateExistingClient(newClient);
     numClients.Text = Convert.ToString((Convert.ToUInt32(numClients.Text)+1));
 }
Пример #16
0
 public static User memberToUser(Member member)
 {
     return (new User(null, member.publicUserInfo, member.privateUserInfo, member.node));
 }
        public bool updateAccount(string userName, byte[] password, Member user)
        {
            Member newMember = new Member(userName, password, user.publicUserInfo, user.privateUserInfo, user.node, user.lords);
            if(accounts.Contains(user.privateUserInfo.userID))
                return false;

            Member member;
            if((member = findMemberByUserName(userName)) != null)
            {
                userIDNameTable.Remove(userName);
                userIDNameTable.Add(userName, user.privateUserInfo.userID);
            }
            accounts[member.privateUserInfo.userID] = newMember;
            return true;
        }