Пример #1
0
        void UpdateList(DhtSearch search)
        {
            if (search.FoundValues.Count > 0)
            {
                LabelResults.Text = search.FoundValues.Count.ToString() + " Values Found, ";
            }

            if (search.FoundContact != null)
            {
                LabelResults.Text = "Found Contact(" + search.FoundContact.ClientID.ToString() + ") ";

                if (search.FoundProxy)
                {
                    LabelResults.Text += "is a proxy";
                }
            }



            // Dht
            // client

            foreach (DhtLookup lookup in search.LookupList)
            {
                ListResults.Items.Add(new ListViewItem(new string[]
                {
                    Utilities.IDtoBin(lookup.Contact.UserID),
                    lookup.Contact.ClientID.ToString()
                }));
            }
        }
Пример #2
0
        public void StartSearch(ulong id, uint version)
        {
            byte[] parameters = BitConverter.GetBytes(version);

            DhtSearch search = Network.Searches.Start(id, "Location", ServiceID, 0, parameters, Search_Found);

            if (search != null)
            {
                search.TargetResults = 2;
            }
        }
Пример #3
0
        private void ButtonSearch_Click(object sender, EventArgs e)
        {
            ulong TargetID = 0;

            // find Dht id or user or operation
            if (Sim != null)
            {
                Sim.Instances.SafeForEach(instance =>
                {
                    instance.Context.Cores.SafeForEach(core =>
                    {
                        if (RadioOp.Checked && core.User.Settings.Operation == TextSearch.Text)
                        {
                            TargetID = core.Network.OpID;
                            return;
                        }

                        if (RadioUser.Checked && core.User.Settings.UserName == TextSearch.Text)
                        {
                            TargetID = Network.IsLookup ? core.Context.Lookup.UserID : core.UserID;
                            return;
                        }
                    });
                });
            }

            if (TargetID == 0)
            {
                MessageBox.Show(this, "Not Found");
                return;
            }

            ListResults.Items.Clear();
            LabelResults.Text = "";

            DhtSearch search = Network.Searches.Start(TargetID, "MANUAL", Network.Core.DhtServiceID, 0, null, null);

            search.DoneEvent = (s) => BeginInvoke(OnUpdateList, s);
        }
Пример #4
0
        private void StartSearch(ulong user, uint version)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(delegate() { StartSearch(user, version); });
                return;
            }

            byte[]    parameters = BitConverter.GetBytes(version);
            DhtSearch search     = Core.Network.Searches.Start(user, Core.GetServiceName(Service), Service, DataType, parameters, Search_Found);

            if (search != null)
            {
                search.TargetResults = 2;
            }


            // node is in our local cache area, so not flooding by directly connecting
            if ((!GlobalIM && Network.Routing.InCacheArea(user)) ||
                (GlobalIM && Core.Buddies.BuddyList.SafeContainsKey(user)))
            {
                foreach (ClientInfo client in Core.Locations.GetClients(user))
                {
                    if (client.Data.TunnelClient == null)
                    {
                        Network.Searches.SendDirectRequest(new DhtAddress(client.Data.IP, client.Data.Source), user, Service, DataType, BitConverter.GetBytes(version));
                    }
                    else
                    {
                        foreach (DhtAddress server in client.Data.TunnelServers)
                        {
                            DhtContact contact = new DhtContact(client.Data.Source, client.Data.IP, client.Data.TunnelClient, server);
                            Network.Searches.SendDirectRequest(contact, user, Service, DataType, BitConverter.GetBytes(version));
                        }
                    }
                }
            }
        }
Пример #5
0
        void Search_Found(DhtSearch search, DhtAddress source, byte[] data)
        {
            G2Header root = new G2Header(data);

            if (!G2Protocol.ReadPacket(root))
            {
                return;
            }

            UpdateInfo info = UpdateInfo.Decode(root); // verifies signature

            if (info == null)
            {
                return;
            }

            if (Core.Context.SignedUpdate == null || Core.Context.SignedUpdate.SequentialVersion < info.SequentialVersion)
            {
                Core.Context.SignedUpdate = info;
                LookupConfig.WriteUpdateInfo(Core);
            }

            // version less than what we have
            else if (Core.Context.SignedUpdate.SequentialVersion > info.SequentialVersion)
            {
                return;
            }

            // version remote has already loaded
            if (Core.Context.SignedUpdate.Loaded)
            {
                return;
            }

            // same sources will be hit as file download search progresses
            StartDownload(search.TargetID);
        }
Пример #6
0
        public void Search(ulong target, object hostArg, Action <byte[], object> hostFoundEvent, OpCore core)
        {
            DhtSearch search = Network.Searches.Start(target, "Temp Search", ServiceID, DataType, null, Search_FoundTemp);

            if (search != null)
            {
                search.Carry = new object[] { hostArg, hostFoundEvent, core }
            }
            ;
        }

        void Search_FoundTemp(DhtSearch search, DhtAddress source, byte[] data)
        {
            object[] carry = search.Carry as object[];

            object hostArg = carry[0];
            Action <byte[], object> hostFoundEvent = carry[1] as Action <byte[], object>;
            OpCore sourceCore = carry[2] as OpCore;


            // strip temp data
            TempData temp = TempData.Decode(search.TargetID, data);

            if (temp == null)
            {
                return;
            }

            Action FireEvent = () => hostFoundEvent.Invoke(temp.Data, hostArg);

            // fire host event with carry vars
            if (sourceCore != null)
            {
                sourceCore.RunInCoreAsync(FireEvent);
            }
            else
            {
                FireEvent.Invoke();
            }
        }

        List <byte[]> Store_Replicate(DhtContact contact)
        {
            List <byte[]> patches = new List <byte[]>();

            foreach (TempData temp in CachedData)
            {
                if (Network.Routing.InCacheArea(temp.TargetID))
                {
                    patches.Add(BitConverter.GetBytes(temp.TargetID));
                }
            }

            return(patches);
        }

        void Store_Patch(DhtAddress source, byte[] data)
        {
            if (!Network.Established || data.Length < 8)
            {
                return;
            }

            ulong user = BitConverter.ToUInt64(data, 0);

            if (!Network.Routing.InCacheArea(user))
            {
                return;
            }

            if (!CachedData.Any(d => d.TargetID == user))
            {
                Network.Searches.SendDirectRequest(source, user, ServiceID, DataType, null);
            }
        }
    }
Пример #7
0
 void Search_Found(DhtSearch search, DhtAddress source, byte[] data)
 {
     Store_Local(new DataReq(source, search.TargetID, Service, DataType, data));
 }
Пример #8
0
        void EndLocationSearch(DhtSearch search)
        {
            if (search.FoundValues.Count == 0)
                return;

            SharedFile file = search.Carry as SharedFile;

            if (file.Completed)
                return;

            OpTransfer transfer = null;

            // add locations to running transfer
            foreach (byte[] result in search.FoundValues.Select(v => v.Value))
            {
                LocationData loc = LocationData.Decode(result);
                DhtClient client = new DhtClient(loc.UserID, loc.Source.ClientID);

                if (transfer == null)
                    transfer = StartTransfer(client, file);

                Core.Network.LightComm.Update(loc);
                transfer.AddPeer(client);
            }
        }
Пример #9
0
        void Search_Found(DhtSearch search, DhtAddress source, byte[] data)
        {
            DataReq store = new DataReq(source, search.TargetID, ServiceID, 0, data);

            Store_Local(store);
        }