ln.skyscanner/entities/NetworkInterface.cs

78 lines
1.8 KiB
C#
Raw Normal View History

2019-03-21 14:06:36 +01:00
// /**
// * 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;
2019-03-26 12:53:42 +01:00
using ln.types.odb;
using Newtonsoft.Json;
using LiteDB;
2019-03-21 14:06:36 +01:00
namespace ln.skyscanner.entities
{
2019-03-26 12:53:42 +01:00
public class NetworkInterface : Persistent
2019-03-21 14:06:36 +01:00
{
2019-03-26 12:53:42 +01:00
[BsonId]
public Guid ID { get; private set; }
public Guid NodeID { get; set; }
[JsonIgnoreAttribute]
public Node Node
{
get => SkyScanner.Instance.Entities.nodeCollection.FindById(NodeID);
set => NodeID = value.ID;
}
2019-03-21 14:06:36 +01:00
public string Name { get; private set; } = "";
public CIDR[] IPs { get; set; } = new CIDR[0];
private NetworkInterface()
{ }
public NetworkInterface(Node node,String name)
{
Node = node;
Name = name;
}
2019-03-26 12:53:42 +01:00
public bool HasIP(CIDR ip)
{
ip = ip.Host;
foreach (CIDR ifip in IPs)
{
if (ifip.Contains(ip))
return true;
}
return false;
}
2019-03-21 14:06:36 +01:00
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;
}
}
}