ln.skyscanner/entities/NetworkInterface.cs

79 lines
1.8 KiB
C#

// /**
// * File: Router.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 System.Collections.Generic;
using ln.types;
using ln.skyscanner.crawl;
using ln.types.odb;
using Newtonsoft.Json;
using LiteDB;
namespace ln.skyscanner.entities
{
public class NetworkInterface : Persistent
{
[DocumentID]
public readonly Guid ID = Guid.NewGuid();
public Guid NodeID { get; set; }
[JsonIgnoreAttribute]
public Node Node
{
get => SkyScanner.Instance.Entities.nodeCollection[NodeID];
set => NodeID = value.ID;
}
public string Name { get; private set; } = "";
public string HWAddress { get; set; } = "";
public CIDR[] IPs { get; set; } = new CIDR[0];
private NetworkInterface()
{ }
public NetworkInterface(Node node,String name)
{
Node = node;
Name = name;
}
public bool HasIP(CIDR ip)
{
ip = ip.Host;
foreach (CIDR ifip in IPs)
{
if (ifip.Contains(ip))
return true;
}
return false;
}
public override int GetHashCode()
{
return Node.GetHashCode() ^ Name.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj is NetworkInterface)
{
NetworkInterface networkInterface = obj as NetworkInterface;
return Node.Equals(networkInterface.Node) && Name.Equals(networkInterface.Name);
}
return false;
}
}
}