示例#1
0
        /** TODO prefere call CRAWL packet to get a fresh list
         * FIrst check in the cache if we have something
         * If not , call the Gwebcache service to bootstrap into gnutella2 network
         * */
        public NodePeer ConnectToRandomHub()
        {
            NodePeer p = null;

            do
            {
                while (GHubCache.Instance.HubCacheSize > 0 && (p = ConnectToHubInCache()) == null)
                {
                }
                if (p != null)
                {
                    break;
                }
                p = Bootstrap();
                if (p == null)
                {
                    GWebCache.Instance.ForceRefresh = true; // if we have bootstrap one time and no answer is good, we force the refresh
                }
            } while (p == null);
            if (p != null)
            {
                G2Log.Write("G2Network : Connected to " + p.ToString());
            }
            return(p);
        }
示例#2
0
        // True if connected to a hub
        // false if attempted to connect to a leaf ( but has certainly retrieved many hubs )
        public bool TryConnect()
        {
            try {
                bool success = false;
                G2Log.Write("GHandshake : Try to connect to " + remote_host.ToString());
                var isConnected = tcp.Connect();
                if (!isConnected)
                {
                    return(false);
                }
                OnConnected();
                success = OnResponse();
                if (success)
                {
                    //bool connected = tcp.CheckConnection();
                    //Log.Write("GHandshake : Connected ? " + connected);
                    OnReply();
                }
                else
                {
                    tcp.Close();
                }

                return(success);
            } catch (Exception e) {
                tcp.Close();
                return(false);
            }
        }
示例#3
0
 /**
  * Add the hub to the list of connected hub
  * and remove it from the list of available hubs
  * */
 public void AddConnectedHub(NodePeer hub)
 {
     lock (ConnectedHub_) {
         RemoveHub(hub);
         ConnectedHub_.Add(hub);
         G2Log.Write("GHUBCACHE : ADDED CONNECTED HUB " + hub.ToString());
     }
 }
示例#4
0
 /** Remove the hub from the connected hub cache and close its connection */
 public void RemoveConnectedHub(NodePeer hub)
 {
     lock (ConnectedHub_) {
         ConnectedHub_.Remove(hub);
         hub.Close();
         G2Log.Write("Cache : Removing hub " + hub.ToString() + " ... ");
     }
 }
示例#5
0
 public bool Connect()
 {
     try {
         sock.Connect(new IPEndPoint(peer.Address, (int)peer.Port));
     } catch (Exception e) {
         G2Log.Write("TCP " + peer.ToString() + " => " + e.ToString());
         return(false);
     }
     return(true);
 }
示例#6
0
        public void StartBrowsing()
        {
            TCPConnection con = TCPConnection.getPeerConnection(Peer);

            if (!con.Connect())
            {
                G2Log.Write("G2BrowseSearch could not connect to Peer " + this.Peer.ToString());
                if (EndSearch != null)
                {
                    EndSearch(referenceToPeer, referenceToSearchResults, packetResults);
                }
                return;
            }
            if (!SendHttpRequest(con))
            {
                if (EndSearch != null)
                {
                    EndSearch(referenceToPeer, referenceToSearchResults, packetResults);
                }
                Peer.Close();
                return;
            }

            bool streaming = ReadResponseHeader(con);

            if (!streaming)
            {
                if (EndSearch != null)
                {
                    EndSearch(referenceToPeer, referenceToSearchResults, packetResults);
                }
                Peer.Close();
                return;
            }

            // start to  read the flow of packets
            this.Peer.connection = new HubSocket(this.Peer, con.sock, reader);
            this.Peer.connection.Start();


            G2Log.Write("G2BrowseSearch : browsing peer " + Peer.ToString() + " ...");
            SearchTimer           = new Timer(Settings.WAIT_TIME_BROWSING_MS);
            SearchTimer.Elapsed  += new ElapsedEventHandler(SearchTimeOut);
            SearchTimer.AutoReset = false;

            SearchTimer.Start();
        }
示例#7
0
 /**
  * Add the hub to the list of connected hub
  * and remove it from the list of available hubs
  * */
 public void AddConnectedHub(NodePeer hub)
 {
     lock (ConnectedHub_) {
         RemoveHub (hub);
         ConnectedHub_.Add (hub);
         G2Log.Write ("GHUBCACHE : ADDED CONNECTED HUB " + hub.ToString ());
     }
 }
示例#8
0
        /** Remove the hub from the connected hub cache and close its connection */
        public void RemoveConnectedHub(NodePeer hub)
        {
            lock (ConnectedHub_) {
                ConnectedHub_.Remove (hub);
                hub.Close ();
                G2Log.Write ("Cache : Removing hub " + hub.ToString() + " ... ");

            }
        }
示例#9
0
        /**
         * Send the request to connected hubs .
         * */
        private void DispatchRequest(G2PacketQ2 pack)
        {
            int      count = 0;
            NodePeer hub   = null;

            while (count < Settings.PEER_DISPATCH_QUERY)
            {
                hub = G2Network.Instance.getQueryableHub();
                hub.DontQueryBefore(Settings.SEARCH_TIME_OUT_MS);
                hub.SendPacket(pack);
                G2Log.Write("G2SearchManager : Sent Query " + getTermsByGUID(pack.guid) + " on " + hub.ToString());
                count++;
            }
        }