Esempio n. 1
0
        private void keepOrForward(QueryByFile query)
        {
            RemoteAsyncShareObjectDelegate del;
            ServerToServerServices friend;
            Friend predecessor = null;
            QueryByFile q1;
            List<String> contacting = new List<string>();
            contacting.Add(ServerApp._myUri);
            if (ServerApp._user.Username[0] == query.Name[0])
            {
                //should store in redirection
                MessageBox.Show(ServerApp._user.Username + " will put uri on redirection list. (obj=now)");
                ServerApp._user.addRedirection(new RedirectionFile(query.Name, query.Uris.ElementAt(0)));
                return;
            }
            else
            {
                foreach (Friend node in ServerApp._user.Friends)
                    if (!node.SucessorSwarm)
                    {
                        predecessor = node;
                        break;
                    }
                if (predecessor == null)
                {
                    MessageBox.Show(ServerApp._user.Username + " says : Inconsistent routing table");
                    return;
                }
                if (predecessor.Name[0] > ServerApp._user.Username[0] && query.Name[0] > predecessor.Name[0])
                {
                    //should store in redirection
                    MessageBox.Show(ServerApp._user.Username + " will put uri on redirection list. (before>now && obj>before)");
                    ServerApp._user.addRedirection(new RedirectionFile(query.Name, query.Uris.ElementAt(0)));
                    return;
                }
                if (query.Name[0] > predecessor.Name[0] && query.Name[0] < ServerApp._user.Username[0])
                {
                    //should store in redirection
                    MessageBox.Show(ServerApp._user.Username + " will put uri on redirection list. (obj>before && obj<now)");
                    ServerApp._user.addRedirection(new RedirectionFile(query.Name, query.Uris.ElementAt(0)));
                    return;
                }
                //if(lower[0] >= ServerApp._user.Username[0])

                //should continue sending
                foreach (Friend f in ServerApp._user.Friends)
                {
                    if (f.Uris.ElementAt(0) != null && f.SucessorSwarm)
                    {
                        if (f.Uris.ElementAt(0).CompareTo(query.ContactingServerUri.ElementAt(0)) != 0)
                        {
                            MessageBox.Show(ServerApp._user.Username + " sending a request to share to " + f.Name);
                            friend = ((ServerToServerServices)Activator.GetObject(typeof(ServerToServerServices),
                                f.Uris.ElementAt(0) + "/" + ServicesNames.ServerToServerServicesName));

                            q1 = new QueryByFile(query.Name, query.Uris, contacting,
                                (ServerApp._user.Username[0] > query.LowestId[0]) ? query.LowestId : ServerApp._user.Username, query.Id);

                            byte[] data = Encoding.Default.GetBytes(q1.ToString());
                            byte[] signature = ServerApp._rsaProvider.SignData(data, "SHA1");
                            SignedQueryByFile signedForwardQuery = new SignedQueryByFile(q1, signature);

                            del = new RemoteAsyncShareObjectDelegate(friend.shareObject);
                            del.BeginInvoke(signedForwardQuery, null, null);
                        }
                    }
                }

            }
        }
Esempio n. 2
0
        public void shareObject(ObjectFile file)
        {
            ServerToServerServices friend;
            RemoteAsyncShareObjectDelegate del;
            ServerApp._user.addObject(file);
            List<String> uri = new List<string>();
            List<String> contacting = new List<string>();

            contacting.Add(ServerApp._primaryURI);
            uri.Add(ServerApp._primaryURI);
            QueryByFile query = new QueryByFile(file.FileName, uri, contacting, ServerApp._user.Username,DateTime.Now);

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

            MessageBox.Show(ServerApp._user.Username + " :  wants to share " + file.FileName);

            foreach (Friend f in ServerApp._user.Friends)
            {
                if (f.Uris.ElementAt(0) != null && f.SucessorSwarm)
                {
                    friend = ((ServerToServerServices)Activator.GetObject(typeof(ServerToServerServices),
                        f.Uris.ElementAt(0) + "/" + ServicesNames.ServerToServerServicesName));

                    MessageBox.Show(ServerApp._user.Username + " sends to " + f.Name);

                    del = new RemoteAsyncShareObjectDelegate(friend.shareObject);
                    del.BeginInvoke(signedQuery, null, null);
                }
            }
        }