// /** // * File: SkyEntities.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using ln.types.odb; using ln.skyscanner.entities; using System.IO; using ln.http.resources; using System.Linq; using ln.types.odb.mapped; using ln.types.net; using ln.skyscanner.crawl; using ln.skyscanner.checks; using ln.logging; namespace ln.skyscanner { public class SkyEntities { public SkyScanner SkyScanner { get; } public string BasePath => Path.Combine(SkyScanner.BasePath, "entities"); public GlobalNetwork GlobalNetwork { get; private set; } public ODB ODB { get; private set; } public ODBCollection NodeCollection { get; private set; } public ODBCollection SubnetCollection { get; private set; } public ODBCollection PointOfPresenceCollection { get; private set; } public ODBCollection CrawledHosts { get; private set; } public ODBCollection CrawledSubnets { get; private set; } public ODBCollection BlockedNetworks { get; private set; } public ODBCollection SkyCheckStates { get; private set; } public SkyEntities(SkyScanner skyScanner) { SkyScanner = skyScanner; Logging.Log(LogLevel.INFO, "SkyEntities: initializing"); ODB = new ODB(BasePath); NodeCollection = ODB.GetCollection(); NodeCollection.EnableStrongCache(true); NodeCollection.EnsureIndeces( "PrimaryIP", "Interfaces[].ConfiguredIPs[].IP", "Interfaces[].ConfiguredIPs[].Network", "uniqueIdentity" ); Network4 n192 = Network4.Parse("192.168.0.0/16"); /* Preload all nodes to increase load speed*/ foreach (Node node in NodeCollection.ToArray()) { if (n192.Contains(node.PrimaryIP)) NodeCollection.Delete(node); } SubnetCollection = ODB.GetCollection(); SubnetCollection.EnsureIndeces("Network"); PointOfPresenceCollection = ODB.GetCollection(); PointOfPresenceCollection.EnsureIndeces("ForeignName"); CrawledHosts = ODB.GetCollection(); CrawledHosts.EnsureIndeces("PrimaryIP","IPAddresses[]"); CrawledSubnets = ODB.GetCollection(); BlockedNetworks = ODB.GetCollection("blockedNetworks"); SkyCheckStates = ODB.GetCollection(); SkyCheckStates.EnableStrongCache(true); SkyCheckStates.EnsureIndeces("Node"); foreach (SkyCheckState checkState in SkyCheckStates.ToArray()) { if (object.ReferenceEquals(checkState.Node, null)) SkyCheckStates.Delete(checkState); } Logging.Log(LogLevel.INFO, "SkyEntities: initialized"); GlobalNetwork = new GlobalNetwork(); } } }