/// <summary> /// Search for something on all hubs /// this will send a search request to every /// connected hub /// </summary> /// <param name="sp">all search parameters in one single parameter</param> public void Search(Hub.SearchParameters sp) { search_results.SearchTerm = sp.search_string; lock (connected_hubs_lock) { foreach (Hub hub in connected_hubs) {//search on all connected hubs // add filter hubs possibilities hub.Search(sp); } } }
/// <summary> /// Reply to a search from a user via udp /// (active connection of peer user required) /// </summary> /// <param name="result_name">the filename of the share found</param> /// <param name="filesize">the filesize of the share</param> /// <param name="hub">the hub the user is connected to</param> /// <param name="search">a whole lot of parameters of the search initiated by a remote user (including ip and port,which we will need here)</param> public void SearchReply(string result_name, long filesize, Hub hub, Hub.SearchParameters search) { try { string temp_hub = hub.Name; if (search.HasTTH) { temp_hub = "TTH:" + search.tth; } string reply = "$SR " + hub.Nick + " " + result_name + (char)0x05 + filesize + " 1/1" + (char)0x05 + temp_hub + " (" + hub.IP + ":" + hub.Port + ")|"; Console.WriteLine("Replying to active search: " + reply); IPEndPoint udp_reply_endpoint = new IPEndPoint(IPAddress.Parse(search.ip), search.port); //EndPoint temp_receive_from_endpoint = (EndPoint)receive_from_endpoint; byte[] send_bytes = System.Text.Encoding.Default.GetBytes(reply); udp_socket.BeginSendTo(send_bytes, 0, send_bytes.Length, SocketFlags.None, udp_reply_endpoint, new AsyncCallback(SearchReplyCallback), udp_socket); } catch (Exception ex) { Console.WriteLine("Exception during sending of SearchReply to: " + search.ip + ":" + search.port + " : " + ex.Message); } }