public void Load(DhtNetwork network) { // if the user has multiple ops, the lookup network is setup with the same settings // so it is easy to find and predictable for other's bootstrapping // we put it in local settings so we safe-guard these settings from moving to other computers // and having dupe dht lookup ids on the network try { var serializer = new XmlSerializer(typeof(PortsConfig)); using (var reader = new StreamReader(PortsConfigPath)) Ports = (PortsConfig)serializer.Deserialize(reader); } catch { Ports = new PortsConfig(); } if (Ports.UserID == 0 || network.Core.Sim != null) Ports.UserID = Utilities.StrongRandUInt64(network.Core.StrongRndGen); // keep tcp/udp the same by default if (Ports.Tcp == 0 || network.Core.Sim != null) Ports.Tcp = (ushort)network.Core.RndGen.Next(3000, 15000); if (Ports.Udp == 0 || network.Core.Sim != null) Ports.Udp = Ports.Tcp; // dont want instances saving and loading same lookup file if (network.Core.Sim == null && File.Exists(BootstrapPath)) { try { using (IVCryptoStream crypto = IVCryptoStream.Load(BootstrapPath, BootstrapKey)) { PacketStream stream = new PacketStream(crypto, network.Protocol, FileAccess.Read); G2Header root = null; while (stream.ReadPacket(ref root)) { if (root.Name == IdentityPacket.LookupCachedIP) network.Cache.AddSavedContact(CachedIP.Decode(root)); if (root.Name == IdentityPacket.LookupCachedWeb) network.Cache.AddWebCache(WebCache.Decode(root)); } } } catch (Exception ex) { network.UpdateLog("Exception", "LookupSettings::Load " + ex.Message); } } }
public void Load(DhtNetwork network) { // if the user has multiple ops, the lookup network is setup with the same settings // so it is easy to find and predictable for other's bootstrapping // we put it in local settings so we safe-guard these settings from moving to other computers // and having dupe dht lookup ids on the network try { var serializer = new XmlSerializer(typeof(PortsConfig)); using (var reader = new StreamReader(PortsConfigPath)) Ports = (PortsConfig)serializer.Deserialize(reader); } catch { Ports = new PortsConfig(); } if (Ports.UserID == 0 || network.Core.Sim != null) { Ports.UserID = Utilities.StrongRandUInt64(network.Core.StrongRndGen); } // keep tcp/udp the same by default if (Ports.Tcp == 0 || network.Core.Sim != null) { Ports.Tcp = (ushort)network.Core.RndGen.Next(3000, 15000); } if (Ports.Udp == 0 || network.Core.Sim != null) { Ports.Udp = Ports.Tcp; } // dont want instances saving and loading same lookup file if (network.Core.Sim == null && File.Exists(BootstrapPath)) { try { using (IVCryptoStream crypto = IVCryptoStream.Load(BootstrapPath, BootstrapKey)) { PacketStream stream = new PacketStream(crypto, network.Protocol, FileAccess.Read); G2Header root = null; while (stream.ReadPacket(ref root)) { if (root.Name == IdentityPacket.LookupCachedIP) { network.Cache.AddSavedContact(CachedIP.Decode(root)); } if (root.Name == IdentityPacket.LookupCachedWeb) { network.Cache.AddWebCache(WebCache.Decode(root)); } } } } catch (Exception ex) { network.UpdateLog("Exception", "LookupSettings::Load " + ex.Message); } } }