示例#1
0
        public void lookupname(QueryByName q)
        {
            System.Windows.Forms.MessageBox.Show(ServerApp._user.Username + " lookupname " + q.Name);
            ServerToServerServices friend;
            RemoteAsyncLookupNameDelegate remoteDel;
            ClientServices client;

            if (!ServerApp._serviceAvailable)
            {
                client = ((ClientServices)Activator.GetObject(typeof(ClientServices),
                    ServerApp._clientUri + "/" + ServicesNames.ClientServicesName));
                new RemoteAsyncServiceUnavailableDelegate(client.serviceUnavailable).BeginInvoke(null, null);
                return;
            }

            //One of this is the response uri and the other is the previous uri
            q.Uris.Add(ServerApp._primaryURI);
            q.ContactingServerUri.Add(ServerApp._primaryURI);

            byte[] data = Encoding.Default.GetBytes(q.ToString());
            byte[] signature = ServerApp._rsaProvider.SignData(data, "SHA1");
            SignedQueryByName signedQuery = new SignedQueryByName(q, signature);

            foreach (Friend i in ServerApp._user.Friends)
            {
                if (i.Uris.ElementAt(0) != null && i.SucessorSwarm) //only sends to the sucessor nodes
                {
                    friend = ((ServerToServerServices)Activator.GetObject(typeof(ServerToServerServices),
                        i.Uris.ElementAt(0) + "/" + ServicesNames.ServerToServerServicesName));
                    remoteDel = new RemoteAsyncLookupNameDelegate(friend.lookupname);
                    remoteDel.BeginInvoke(signedQuery, null, null);
                }
            }
        }
示例#2
0
 public SignedQueryByName(QueryByName query, byte[] signature)
     : base(signature)
 {
     Query = query;
 }
示例#3
0
        public void lookupname(SignedQueryByName incomingQuery)
        {
            ServerToServerServices friend;
            RemoteAsyncLookupNameDelegate remoteDel;
            QueryByName q = incomingQuery.Query;
            QueryByName newQ = new QueryByName(q.Name, q.Uris, new List<string>(),q.Id);
            newQ.ContactingServerUri.Clear();
            newQ.ContactingServerUri.Add(ServerApp._primaryURI);
            bool sendMessage = false;

            System.Windows.Forms.MessageBox.Show(ServerApp._user.Username + " : Received the request.");

            if (ServerApp._user.SentMessages.Contains(incomingQuery.Query.Id))
            {
                MessageBox.Show(ServerApp._user.Username + " : Message was already sent so the request was discarted!");
                return;
            }

            if (ServerApp._user.ReceivedNameMessages.Contains(incomingQuery.Query))
            {
                MessageBox.Show(ServerApp._user.Username + " : Message was already received so the request was discarted!");
                return;
            }

            //only accepts messages from predecessors!
            if (!isPredecessor(incomingQuery.Query))
            {
                MessageBox.Show(ServerApp._user.Username + " says " + whoSentQuery(incomingQuery.Query)
                                                         + " is trying to screw the comunication!");
                return;
            }

            if (!isLookupQueryValid(incomingQuery)) {
                MessageBox.Show(ServerApp._user.Username + " Could not verify lookup message");
                return;
            }

            ServerApp._user.ReceivedNameMessages.Add(q);

            //Is it receiving this message from the original requester? if so doesnt need consensus. (check expl @ shareObject())
            if (incomingQuery.Query.ContactingServerUri.ElementAt(0).CompareTo(incomingQuery.Query.Uris.ElementAt(0)) == 0)
            {
                //Does not need consensus
                MessageBox.Show(ServerApp._user.Username + ": Does not need consensus!");
                sendMessage = true;
            }
            else
            {
                //consensus
                sendMessage = consensus(incomingQuery.Query);

            }

            if (sendMessage)
            {
                MessageBox.Show(ServerApp._user.Username + ": Reached consensus!");
                if (ServerApp._user.Username[0] == q.Name[0])
                {
                    sendResponseToLookupQuery(q);
                    return;
                }

                /* sign the query which we send to our friends */
                byte[] queryData = Encoding.Default.GetBytes(newQ.ToString());
                byte[] signature = ServerApp._rsaProvider.SignData(queryData, "SHA1");
                SignedQueryByName signedNewNameQuery = new SignedQueryByName(newQ, signature);

                foreach (Friend i in ServerApp._user.Friends)
                {
                    if (i.Uris.ElementAt(0) != null && i.SucessorSwarm)
                    {
                        if (i.Uris.ElementAt(0).CompareTo(q.ContactingServerUri.ElementAt(0)) != 0)
                        {
                            System.Windows.Forms.MessageBox.Show(ServerApp._user.Username + " : forwarding to : " + i.Name);
                            friend = ((ServerToServerServices)Activator.GetObject(typeof(ServerToServerServices),
                                i.Uris.ElementAt(0) + "/" + ServicesNames.ServerToServerServicesName));
                            remoteDel = new RemoteAsyncLookupNameDelegate(friend.lookupname);
                            remoteDel.BeginInvoke(signedNewNameQuery, null, null);
                        }

                    }
                }

                ServerApp._user.SentMessages.Add(incomingQuery.Query.Id);
            }
            else
                MessageBox.Show(ServerApp._user + ": Didn't reach consensus yet!");
        }
示例#4
0
        private void sendResponseToLookupQuery(QueryByName q)
        {
            ServerToServerServices origin;
            RemoteAsyncLookupNameResponseDelegate remoteResDel;

            System.Windows.Forms.MessageBox.Show(ServerApp._user.Username + "@" + ServerApp._primaryURI + " : Its my node name!");
            String i = q.Uris.ElementAt(0);
            origin = ((ServerToServerServices)Activator.GetObject(typeof(ServerToServerServices),
                    i + "/" + ServicesNames.ServerToServerServicesName));
            remoteResDel = new RemoteAsyncLookupNameResponseDelegate(origin.lookupNameResponse);

            /* sign response */
            string data = getResponseDataForHash();
            byte[] bytestreamData = Encoding.Default.GetBytes(data);
            byte[] responseSignature = ServerApp._rsaProvider.SignData(bytestreamData, "SHA1");
            SignedLookupResponse signedLookupResponse =
                new SignedLookupResponse(ServerApp._user.Username, ServerApp._myUri,
                    ServerApp._user.RedirectionList, responseSignature);
            remoteResDel.BeginInvoke(signedLookupResponse, null, null);
        }
示例#5
0
 private void lookupNameButton_Click_1(object sender, EventArgs e)
 {
     this.lookupResultTextBox.Clear();
     QueryByName q = new QueryByName(this.lookupName.Text, new List<String>(), new List<String>(),DateTime.Now);
     RemoteAsyncLookupNameClientDelegate del = new RemoteAsyncLookupNameClientDelegate(_server.lookupname);
     del.BeginInvoke(q, null, null);
 }