broken
Harald Wolff 2019-03-29 08:55:09 +01:00
parent ed2c104cf7
commit 48585ea3e1
11 changed files with 141 additions and 45 deletions

View File

@ -34,6 +34,8 @@ using Castle.DynamicProxy;
using ln.types.odb;
using System.Net.Sockets;
using ln.skyscanner.entities;
using ln.types.btree;
using ln.types.test;
namespace ln.skyscanner
{
@ -43,8 +45,11 @@ namespace ln.skyscanner
public static void Main(string[] args)
{
new testODB().TestCase();
return;
FileLogger fileLogger = new FileLogger("skyscanner.log");
fileLogger.MaxLogLevel = LogLevel.DEBUG;
fileLogger.MaxLogLevel = LogLevel.INFO;
Logger.Default.Backends.Add(fileLogger);
Logger.ConsoleLogger.MaxLogLevel = LogLevel.INFO;
@ -61,41 +66,41 @@ namespace ln.skyscanner
//using (ODB odb = new ODB("odb"))
//{
//ODBCollection col = odb.GetCollection("test");
//ODBCollection col = odb.GetCollection("test");
//foreach (ODBDocument odoc in col)
//{
// Console.WriteLine("Stored DOC: {0}", odoc);
// if (!odoc.Contains("counter"))
// odoc["counter"] = 0;
// else
// odoc["counter"] = odoc["counter"].AsInt + 1;
//foreach (ODBDocument odoc in col)
//{
// Console.WriteLine("Stored DOC: {0}", odoc);
// if (!odoc.Contains("counter"))
// odoc["counter"] = 0;
// else
// odoc["counter"] = odoc["counter"].AsInt + 1;
// col.Upsert(odoc);
//}
// col.Upsert(odoc);
//}
//ODBDocument doc = new ODBDocument();
//ODBDocument doc = new ODBDocument();
//doc["snmp.msg"] = "Hallo WelT!";
//doc["name"] = "Harald";
//doc["alter"] = 39;
//doc["genauer"] = 34.5;
//ODBDocument ndoc = new ODBDocument();
//doc["keywords"] = ndoc;
//doc["snmp.msg"] = "Hallo WelT!";
//doc["name"] = "Harald";
//doc["alter"] = 39;
//doc["genauer"] = 34.5;
//ODBDocument ndoc = new ODBDocument();
//doc["keywords"] = ndoc;
//ndoc["eins"] = 1;
//ndoc["zwei"] = 2;
//ndoc["drei"] = 3;
//ndoc["eins"] = 1;
//ndoc["zwei"] = 2;
//ndoc["drei"] = 3;
//Console.WriteLine(doc);
//Console.WriteLine(doc);
//col.Insert(doc);
//col.Insert(doc);
//Node node = new Node(CIDR.Parse("1.2.3.4"));
//ODBDocument nodeDoc = ODBMapper.Default.ToODBValue(node).AsDocument;
//Console.WriteLine("Node: {0}", nodeDoc);
//Node node = new Node(CIDR.Parse("1.2.3.4"));
//ODBDocument nodeDoc = ODBMapper.Default.ToODBValue(node).AsDocument;
//Console.WriteLine("Node: {0}", nodeDoc);
//Node node2 = ODBMapper.Default.ToNativeValue<Node>(nodeDoc);
//Node node2 = ODBMapper.Default.ToNativeValue<Node>(nodeDoc);
//}
}

View File

@ -24,6 +24,7 @@ namespace ln.skyscanner
public ODB odDatabase { get; private set; }
public ODBCollection<Node> nodeCollection { get; private set; }
public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
public ODBCollection<IntfIP> intfIPCollection { get; private set; }
public ODBCollection<Subnet> subnetCollection { get; private set; }
public SkyEntities(SkyScanner skyScanner)
@ -33,8 +34,12 @@ namespace ln.skyscanner
odDatabase = new ODB(BasePath);
nodeCollection = odDatabase.GetCollection<Node>();
interfaceCollection = odDatabase.GetCollection<NetworkInterface>();
intfIPCollection = odDatabase.GetCollection<IntfIP>();
subnetCollection = odDatabase.GetCollection<Subnet>();
interfaceCollection.EnsureIndex("NodeID");
intfIPCollection.EnsureIndex("interfaceID");
GlobalNetwork = new GlobalNetwork(this);
}

View File

@ -12,7 +12,7 @@ using ln.types;
using ln.types.odb;
using System.Collections.Generic;
using System.Linq;
namespace ln.skyscanner.entities
namespace ln.skyscanner.crawl
{
public class CrawledSubnet
{

View File

@ -11,6 +11,8 @@ using ln.types.odb;
using ln.types.sync;
using ln.logging;
using System.Globalization;
using ln.types.threads;
using ln.types.odb.values;
namespace ln.skyscanner.entities
{
@ -61,13 +63,16 @@ namespace ln.skyscanner.entities
}
public IEnumerable<Node> FindHostsInSubnet(CIDR network)
{
return SkyEntities.nodeCollection.Select(node => network.Contains(node.IPAdresses));
{
IntfIP[] intfIPs = SkyEntities.intfIPCollection.Select((ip) => ip.IP.In(network)).ToArray();
NetworkInterface[] networkInterfaces = intfIPs.Select((iip) => iip.NetworkInterface).Distinct().ToArray();
Node[] nodes = SkyEntities.nodeCollection.Select(networkInterfaces.Select((ni) => (ODBValue)ni.NodeID).Distinct()).ToArray();
return nodes;
}
public IEnumerable<Node> FindNeighbors(Node node)
{
return node.Interfaces.SelectMany((intf) => intf.IPs).SelectMany((arg) => FindHostsInSubnet(arg)).Distinct();
return node.IPAdresses.SelectMany((ip) => Timing.Meassure("FindHostsInSubnet", () => FindHostsInSubnet(ip)).Distinct().ToArray());
}
public Node FindNodeByIP(IEnumerable<CIDR> ips)
@ -83,7 +88,11 @@ namespace ln.skyscanner.entities
public Node FindNodeByIP(CIDR ip)
{
ip = ip.Host;
return SkyEntities.nodeCollection.Select(node => ip.In(node.IPAdresses) || ip.In(node.PrimaryIP)).FirstOrDefault();
IntfIP _iip = SkyEntities.intfIPCollection.Where((iip) => iip.IP.Host.Equals(ip)).FirstOrDefault();
if (_iip != null)
return _iip.NetworkInterface.Node;
return null;
}
[Unsynced]
@ -146,13 +155,38 @@ namespace ln.skyscanner.entities
networkInterface = new NetworkInterface(node, fields[0]);
networkInterface.HWAddress = fields[1];
networkInterface.IPs = fields[2].Split(',').Where((sip)=> !String.Empty.Equals(sip)).Select((sip) => CIDR.Parse(sip)).ToArray();
SkyEntities.interfaceCollection.Upsert(networkInterface);
foreach (CIDR ip in networkInterface.IPs)
EnsureSubnet(ip);
CIDR[] crawledIPs = fields[2].Split(',').Where((sip) => !String.Empty.Equals(sip)).Select((sip) => CIDR.Parse(sip)).ToArray();
IntfIP[] currentIPs = networkInterface.IPs.ToArray();
foreach (CIDR crawledIP in crawledIPs)
{
int n;
for (n=0; n < currentIPs.Length; n++)
if (currentIPs[n].IP.Equals(crawledIP))
break;
if (n == currentIPs.Length)
{
IntfIP miss = new IntfIP(networkInterface, crawledIP);
SkyEntities.intfIPCollection.Upsert(miss);
}
}
foreach (IntfIP iip in currentIPs)
{
CIDR ip = iip.IP;
if (crawledIPs.Contains(ip))
{
EnsureSubnet(ip.Network);
}
else
{
SkyEntities.intfIPCollection.Delete(iip);
}
}
}
node.RemoveURI("ssh");

View File

@ -20,6 +20,8 @@ namespace ln.skyscanner.entities
public Node Node { get; private set; }
public GlobalNetwork GlobalNetwork => SkyScanner.Instance.Entities.GlobalNetwork;
public int MaxDepth { get; set; } = 2;
Dictionary<Node, int> hops = new Dictionary<Node, int>();
public HopMap()
@ -53,7 +55,8 @@ namespace ln.skyscanner.entities
if (!hops.ContainsKey(node) || (hops[node] > level))
{
hops[node] = level;
AddNodes(GlobalNetwork.FindNeighbors(node), level + 1);
if (level < MaxDepth)
AddNodes(GlobalNetwork.FindNeighbors(node), level + 1);
}
}

41
entities/IntfIP.cs 100644
View File

@ -0,0 +1,41 @@
// /**
// * File: IntfIP.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.types;
using Newtonsoft.Json;
namespace ln.skyscanner.entities
{
public class IntfIP
{
[DocumentID]
public readonly Guid ID = Guid.NewGuid();
Guid interfaceID = Guid.Empty;
[JsonIgnore]
public NetworkInterface NetworkInterface => SkyScanner.Instance.Entities.interfaceCollection.Select(interfaceID);
public CIDR IP { get; private set; }
public IntfIP()
{
}
public IntfIP(NetworkInterface networkInterface,CIDR ip)
{
interfaceID = networkInterface.ID;
IP = ip;
}
}
}

View File

@ -20,7 +20,7 @@ namespace ln.skyscanner.entities
{
[DocumentID]
public readonly Guid ID = Guid.NewGuid();
public Guid NodeID { get; set; }
[JsonIgnoreAttribute]
@ -33,7 +33,8 @@ namespace ln.skyscanner.entities
public string Name { get; private set; } = "";
public string HWAddress { get; set; } = "";
public CIDR[] IPs { get; set; } = new CIDR[0];
//public CIDR[] IPs { get; set; } = new CIDR[0];
public IEnumerable<IntfIP> IPs => SkyScanner.Instance.Entities.intfIPCollection.Select("interfaceID", ID);
private NetworkInterface()
{ }
@ -48,9 +49,9 @@ namespace ln.skyscanner.entities
{
ip = ip.Host;
foreach (CIDR ifip in IPs)
foreach (IntfIP ifip in IPs)
{
if (ifip.Contains(ip))
if (ifip.IP.Host.Equals(ip))
return true;
}
return false;

View File

@ -14,6 +14,7 @@ using System.Linq;
using ln.types.odb;
using Newtonsoft.Json;
using LiteDB;
using ln.types.threads;
namespace ln.skyscanner.entities
{
public class Node
@ -37,8 +38,10 @@ namespace ln.skyscanner.entities
public string ProductLine { get; set; }
public IEnumerable<NetworkInterface> Interfaces => SkyScanner.Instance.Entities.interfaceCollection.Select( intf => intf.NodeID.Equals(ID));
public IEnumerable<CIDR> IPAdresses => Interfaces.SelectMany(intf => intf.IPs);
public IEnumerable<NetworkInterface> Interfaces => Timing.Meassure("Node.Interfaces",
() => SkyScanner.Instance.Entities.interfaceCollection.Select("NodeID", ID)
);
public IEnumerable<CIDR> IPAdresses => Timing.Meassure("Node.IPAddesses", () => Interfaces.SelectMany(intf => intf.IPs).Select((iip)=>iip.IP));
private HashSet<URI> uris = new HashSet<URI>();

View File

@ -29,7 +29,7 @@ namespace ln.skyscanner.entities
public bool AutoScan { get; set; }
public IEnumerable<NetworkInterface> AttachedInterfaces => SkyEntities.interfaceCollection.Where((intf) => Network.Contains(intf.IPs));
public IEnumerable<NetworkInterface> AttachedInterfaces => SkyEntities.interfaceCollection.Where((intf) => Network.Contains(intf.IPs.Select((iip)=>iip.IP)));
public IEnumerable<Node> AttachedNodes => AttachedInterfaces.Select(intf => intf.Node).Distinct();
private Subnet()

View File

@ -48,8 +48,11 @@ namespace ln.skyscanner.http
public HopMap.HopNode[] GetHopTable()
{
HopMap hopMap = new HopMap();
foreach (Node node in GlobalNetwork.Nodes)
hopMap.AddNode(node, 0);
//foreach (Node node in GlobalNetwork.Nodes)
//hopMap.AddNode(node, 0);
hopMap.AddNode(GlobalNetwork.FindNodeByIP(CIDR.Parse("10.10.10.2")),0);
return hopMap.HopNodes;
}

View File

@ -74,6 +74,7 @@
<Compile Include="http\NetworkApi.cs" />
<Compile Include="crawl\service\CrawlService.cs" />
<Compile Include="crawl\service\TCP.cs" />
<Compile Include="entities\IntfIP.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />