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

157 lines
2.9 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;
2021-01-29 14:28:52 +02:00
import std.socket : Address;
import core.thread : Thread;
2020-10-05 15:59:08 +02:00
2021-01-29 19:49:39 +02:00
/**
* Link manager
*
* Given a set of original DLink objects, it will open connections to them
* It also facilitates DConnection making a call to `.addLink` here when an
* inbound peering request comes in
*/
public final class DLinkManager
{
this(DServer server, DLink[] seedLinks)
{
}
}
2021-01-29 14:28:52 +02:00
/**
* Represents a server link
*
* Either used for inbound or outbound
*/
public final class DLink : Thread
{
/* Associated server */
private DServer server;
/* The connection */
private DConnection connection;
/**
* Links details
*/
private string name;
private Address address;
/**
* Constructs a DLink for an outbound peering
*/
this(DServer server, string name, Address address)
{
/* Set the worker thread for outbound connections */
super(&outboundWorker);
2021-01-29 15:04:08 +02:00
2021-01-29 14:28:52 +02:00
/* Create an outbound connection */
/* TODO: Fuuuuuuuuuuuuuuuuuuuck handling of shit here bababooey and not in dconnection.d as we would have done below */
/* Initialize a new outbound connection */
initializeOutboundConnection();
}
/**
* Initializes a new outbound connection
*/
private void initializeOutboundConnection()
{
/* Open a connection to the server */
// connection = new DConnection();
}
private void outboundWorker()
{
/* TODO: Implement me */
2021-01-29 18:29:05 +02:00
while(true)
{
}
}
2021-01-29 14:28:52 +02:00
/**
* Constructs a DLink for an inbound peering
*/
this(DServer server, string name, Address address, DConnection connection)
{
2021-01-29 18:29:05 +02:00
/* Save the server, name and address */
/* Save the active connection */
2021-01-29 14:28:52 +02:00
/* Save name and address */
this(server, name, address);
/* Save connection */
}
}
2020-10-05 15:59:08 +02:00
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-29 16:44:31 +02:00
this(DServer server, DLink[] links)
2020-10-05 15:59:08 +02:00
{
this.server = server;
/* Initialize the locks */
initLocks();
2021-01-29 14:28:52 +02:00
/* Open a connection to the server */
/* TODO: Open connections to all servers we are yet to open a connection to (check the `links` array) */
}
2021-01-29 19:49:39 +02:00
/**
* Locks the link list
*/
private void openAllOutboundConnections()
{
}
/* Initialize locks */
private void initLocks()
{
2020-10-05 15:59:08 +02:00
linksMutex = new Mutex();
}
2021-01-29 19:49:39 +02:00
/**
* Adds a peer to the links list
*/
public void addLink(DLink newLink)
{
/* Lock the list */
linksMutex.lock();
2020-10-05 15:59:08 +02:00
2021-01-29 19:49:39 +02:00
/* Add the link */
links ~= newLink;
2020-10-05 15:59:08 +02:00
2021-01-29 19:49:39 +02:00
/* Unlock the list */
linksMutex.unlock();
}
2020-10-05 15:59:08 +02:00
}