1
0
mirror of https://github.com/deavminet/dnetd synced 2024-09-21 17:53:39 +02:00
dnetd_old/source/dnetd/dlink.d

81 lines
1.5 KiB
D
Raw Normal View History

2020-10-05 15:59:08 +02:00
module dnetd.dlink;
import dnetd.dconnection;
import core.sync.mutex : Mutex;
import std.stdio;
import std.conv;
import dnetd.dserver;
2021-01-28 23:43:22 +02:00
import dnetd.dconfig;
2020-10-05 15:59:08 +02:00
/**
* DLink
*
* Couples a DConneciton (direct peer)
* with information about what this link
* knows and can tell us
*/
public final class DLink
{
/* The directly attached peer */
private DConnection directPeer;
/* Servers (by name) this server is aware of */
private string[] knowledgeList;
this(DConnection directPeer)
{
this.directPeer = directPeer;
}
/* Call this to update list */
public void updateKB()
{
/* TODO: Ask DConneciton here for the servers he knows */
}
}
public final class DMeyer
{
2021-01-28 23:43:22 +02:00
/* Direct peers */
2020-10-05 15:59:08 +02:00
private DLink[] links;
private Mutex linksMutex;
2021-01-28 23:43:22 +02:00
/* Associated server */
2020-10-05 15:59:08 +02:00
private DServer server;
2021-01-28 23:43:22 +02:00
this(DServer server, DLinkConfig linkConfig)
2020-10-05 15:59:08 +02:00
{
this.server = server;
linksMutex = new Mutex();
}
/* Attach a direct peer */
public void attachDirectPeer(DConnection peer)
{
/* TODO: Add to `directPeers` */
linksMutex.lock();
links ~= new DLink(peer);
writeln("Attached direct peer: "~to!(string)(peer));
linksMutex.unlock();
}
/* Get a list of all servers we know of */
public DLink getLink(DConnection peer)
{
DLink link;
linksMutex.lock();
linksMutex.unlock();
return link;
}
}