71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Net;
|
|
using TorControlLibrary.Responses;
|
|
using TorControlLibrary;
|
|
|
|
namespace Hermes.Objects
|
|
{
|
|
public class Router : IEquatable<Router>
|
|
{
|
|
public Router()
|
|
{ }
|
|
public Router(RouterStatusResponse resp)
|
|
{
|
|
Address = resp.Address;
|
|
Digest = resp.Digest;
|
|
Identity = resp.Identity;
|
|
NickName = resp.NickName;
|
|
Publication = resp.Publication;
|
|
Flags = new List<String>(resp.Flags);
|
|
}
|
|
public static List<Router> ParseRouterStatusResponses(List<RouterStatusResponse> responses)
|
|
{
|
|
List<Router> routers = new List<Router>();
|
|
foreach (RouterStatusResponse resp in responses)
|
|
routers.Add(new Router(resp));
|
|
return routers;
|
|
}
|
|
public void AddDescription(RouterDescription desc)
|
|
{
|
|
BandwidthObserved = desc.BandwidthObserved;
|
|
BandwidthAverage = desc.BandwidthAverage;
|
|
BandwidthBurst = desc.BandwidthBurst;
|
|
Uptime = desc.Uptime;
|
|
ExitPolicy = desc.ExitPolicy;
|
|
}
|
|
|
|
#region IEquatable<Router> Members
|
|
public bool Equals(Router other)
|
|
{
|
|
return this.Digest.Equals(other.Digest) || this.NickName.Equals(other.NickName) || this.Identity.Equals(other.Identity);
|
|
}
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj == null || !(obj is Router))
|
|
return false;
|
|
return Equals((Router)obj);
|
|
}
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
public String NickName { get; set; }
|
|
public String Identity { get; set; }
|
|
public String Digest { get; set; }
|
|
public DateTime Publication { get; set; }
|
|
public IPAddress Address { get; set; }
|
|
public List<String> Flags { get; set; }
|
|
//Extended information properties gathered from router description command
|
|
public Int32 BandwidthObserved { get; set; }
|
|
public Int32 BandwidthAverage { get; set; }
|
|
public Int32 BandwidthBurst { get; set; }
|
|
public TimeSpan Uptime { get; set; }
|
|
public ExitPolicy ExitPolicy { get; set; }
|
|
}
|
|
}
|