1 module libsweatyballs.zwitch.neighbor; 2 3 import std.socket : Address; 4 import std.conv : to; 5 import libsweatyballs.link.core : Link; 6 import std.string : cmp; 7 8 public final class Neighbor 9 { 10 /* IPv6 address and R2R port of router neighbor */ 11 private Address address; 12 13 /* The Link this neighbor is attached on */ 14 private Link link; 15 16 /* Identity of router */ 17 private string identity; 18 19 this(string identity, Address address, Link link) 20 { 21 this.identity = identity; 22 this.address = address; 23 this.link = link; 24 } 25 26 public string getIdentity() 27 { 28 return identity; 29 } 30 31 public Address getAddress() 32 { 33 return address; 34 } 35 36 public Link getLink() 37 { 38 return link; 39 } 40 41 public override string toString() 42 { 43 return "NBR ("~identity~") ["~to!(string)(address)~"]"; 44 } 45 46 /** 47 * Neighbors are considered equal if both their Link 48 * is the same and their identity. There should not 49 * be several neighbors with same identity on one Link 50 */ 51 public override bool opEquals(Object other) 52 { 53 Neighbor otherN = cast(Neighbor)other; 54 55 56 57 return otherN.getLink() == this.getLink() && cmp(otherN.getIdentity(), this.getIdentity()) == 0; 58 } 59 }