public void PublishNetwork(ulong target, uint service, uint datatype, byte[] data) { if (Core.InvokeRequired) { Debug.Assert(false); } string type = "Publish " + Core.GetServiceName(service); if (target == Core.UserID) { Network.UpdateLog("general", "Publishing " + Core.GetServiceName(service)); } DataReq store = new DataReq(null, target, service, datatype, data); // find users closest to publish target if (target == Network.Local.UserID) { foreach (DhtContact closest in Network.Routing.GetCacheArea()) { Send_StoreReq(closest, null, store); } foreach (TcpConnect socket in Network.TcpControl.ProxyClients) { Send_StoreReq(new DhtAddress(socket.RemoteIP, socket), null, store); } } else { DhtSearch search = Network.Searches.Start(target, type, 0, 0, null, null); if (search != null) { search.DoneEvent = Search_DonePublish; search.Carry = store; } } }
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)); } } } } }