1 module dnetd.dlink; 2 3 import dnetd.dconnection; 4 import core.sync.mutex : Mutex; 5 import std.stdio; 6 import std.conv; 7 import dnetd.dserver; 8 9 /** 10 * DLink 11 * 12 * Couples a DConneciton (direct peer) 13 * with information about what this link 14 * knows and can tell us 15 */ 16 public final class DLink 17 { 18 /* The directly attached peer */ 19 private DConnection directPeer; 20 21 /* Servers (by name) this server is aware of */ 22 private string[] knowledgeList; 23 24 this(DConnection directPeer) 25 { 26 this.directPeer = directPeer; 27 } 28 29 /* Call this to update list */ 30 public void updateKB() 31 { 32 /* TODO: Ask DConneciton here for the servers he knows */ 33 } 34 } 35 36 public final class DMeyer 37 { 38 /* List of links (direct peers + additional information) */ 39 private DLink[] links; 40 private Mutex linksMutex; 41 42 private DServer server; 43 44 this(DServer server) 45 { 46 this.server = server; 47 linksMutex = new Mutex(); 48 } 49 50 /* Attach a direct peer */ 51 public void attachDirectPeer(DConnection peer) 52 { 53 /* TODO: Add to `directPeers` */ 54 linksMutex.lock(); 55 56 links ~= new DLink(peer); 57 writeln("Attached direct peer: "~to!(string)(peer)); 58 59 linksMutex.unlock(); 60 } 61 62 /* Get a list of all servers we know of */ 63 64 65 public DLink getLink(DConnection peer) 66 { 67 DLink link; 68 69 linksMutex.lock(); 70 71 72 73 linksMutex.unlock(); 74 75 return link; 76 } 77 78 }