Exemplo n.º 1
0
        private void AppendResult(G2PacketQH2 res)
        {
            G2Peer g2peer = G2Peer.ParseG2Peer (res);
            if (g2peer == null)
                return;

            /** Create a new search result from the hub ip  and the search transaction */
            SearchResult Results = new SearchResult(new System.Net.IPEndPoint(res.RemotePeer.Address,res.RemotePeer.Port),Transaction);

            bool PeerBrowsable = false;
            bool isFirewalled = false;
            int fileCount = 0;
            List<G2File> files = new List<G2File>();
            // add the files to the collections.
            foreach (G2Packet child in res.children)
            {
                if (child.type.Equals(G2PacketType.BH))
                {
                    PeerBrowsable = true;
                    continue;
                }
                if (child.type.Equals(G2PacketType.FW))
                {
                    isFirewalled = true;
                    continue;
                }
                if (!child.type.Equals(G2PacketType.H))
                    continue;

                G2PacketH hit = child as G2PacketH;
                G2File file = G2File.ParseHit(hit,FileLocationFound.ServerIndex);
                if (file == null) continue;
                files.Add(file);

                fileCount += 1;

            }
            if (fileCount == 0) return; // may have some hosts having only partial file,so no file for the application ...

            Results.PeerCollection.Add(g2peer);
            Peer p = Results.PeerCollection.Find(g2peer); // to get the right object reference may not be needed .. ?
            if (p.Ip.StartsWith ("192.168")) {
                return ;
            }
            foreach (G2File file in files)
            {
                p.Files.Add(file);
                file.PeerDiffusedFiles.Add(p); // ?? necessary or wrong ?
                Results.FileCollection.Add(file);
            }
            files.Clear();
            files = null;

            TotalFiles += fileCount;

            G2Log.Write("SearchResults : New result from " + res.RemotePeer.ToString() + " for " + SearchedWord + " ==> " + fileCount + " files");

            // try to see if we already have launched an browsing research on this peer or not
            bool notAlreadySearched = !PeersBrowsed.Contains(p);
            // make sure that the browsing will not increase the waiting time of the application for the result
            bool notTooLate = StartSearchTime.AddMilliseconds(Settings.WAIT_TIME_BROWSING_MS)
                < StartSearchTime.AddMilliseconds(Settings.SEARCH_TIME_OUT_MS + 100); // +100 to make sure browsing has time to regroup all
            bool notConnectedHub = res.RemotePeer.Address.ToString() != p.Ip;

            // verify that we dont search the hub, taht the peer is browsable and NOT firewalled
            // TODO can send a PUSH packet to the hub that will bring the peer to establish a connection to us
            if ( notConnectedHub && PeerBrowsable && !isFirewalled && notAlreadySearched && notTooLate)
            {

                    PeersBrowsed.Add(p);
                    G2BrowseSearch browser = new G2BrowseSearch(p,Results);
                    browser.EndSearch += new BrowseSearchEnd(BrowsingTerminated);
                    browser.StartBrowsing();
            }
            else // sends results to application
            {
                RegroupResults(Results);
            }
        }
Exemplo n.º 2
0
        private void AppendResult(G2PacketQH2 res)
        {
            G2Peer g2peer = G2Peer.ParseG2Peer(res);

            if (g2peer == null)
            {
                return;
            }

            /** Create a new search result from the hub ip  and the search transaction */
            SearchResult Results = new SearchResult(new System.Net.IPEndPoint(res.RemotePeer.Address, res.RemotePeer.Port), Transaction);

            bool          PeerBrowsable = false;
            bool          isFirewalled  = false;
            int           fileCount     = 0;
            List <G2File> files         = new List <G2File>();

            // add the files to the collections.
            foreach (G2Packet child in res.children)
            {
                if (child.type.Equals(G2PacketType.BH))
                {
                    PeerBrowsable = true;
                    continue;
                }
                if (child.type.Equals(G2PacketType.FW))
                {
                    isFirewalled = true;
                    continue;
                }
                if (!child.type.Equals(G2PacketType.H))
                {
                    continue;
                }


                G2PacketH hit  = child as G2PacketH;
                G2File    file = G2File.ParseHit(hit, FileLocationFound.ServerIndex);
                if (file == null)
                {
                    continue;
                }
                files.Add(file);

                fileCount += 1;
            }
            if (fileCount == 0)
            {
                return;                 // may have some hosts having only partial file,so no file for the application ...
            }
            Results.PeerCollection.Add(g2peer);
            Peer p = Results.PeerCollection.Find(g2peer); // to get the right object reference may not be needed .. ?

            if (p.Ip.StartsWith("192.168"))
            {
                return;
            }
            foreach (G2File file in files)
            {
                p.Files.Add(file);
                file.PeerDiffusedFiles.Add(p); // ?? necessary or wrong ?
                Results.FileCollection.Add(file);
            }
            files.Clear();
            files = null;

            TotalFiles += fileCount;


            G2Log.Write("SearchResults : New result from " + res.RemotePeer.ToString() + " for " + SearchedWord + " ==> " + fileCount + " files");

            // try to see if we already have launched an browsing research on this peer or not
            bool notAlreadySearched = !PeersBrowsed.Contains(p);
            // make sure that the browsing will not increase the waiting time of the application for the result
            bool notTooLate = StartSearchTime.AddMilliseconds(Settings.WAIT_TIME_BROWSING_MS)
                              < StartSearchTime.AddMilliseconds(Settings.SEARCH_TIME_OUT_MS + 100); // +100 to make sure browsing has time to regroup all
            bool notConnectedHub = res.RemotePeer.Address.ToString() != p.Ip;

            // verify that we dont search the hub, taht the peer is browsable and NOT firewalled
            // TODO can send a PUSH packet to the hub that will bring the peer to establish a connection to us
            if (notConnectedHub && PeerBrowsable && !isFirewalled && notAlreadySearched && notTooLate)
            {
                PeersBrowsed.Add(p);
                G2BrowseSearch browser = new G2BrowseSearch(p, Results);
                browser.EndSearch += new BrowseSearchEnd(BrowsingTerminated);
                browser.StartBrowsing();
            }
            else // sends results to application
            {
                RegroupResults(Results);
            }
        }