Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Factor out fakedls.DlsNode #101

Open
wants to merge 2 commits into
base: v15.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fakedls/DlsNode.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*******************************************************************************/

module fakedls.DlsNode;

version ( none ):
/*******************************************************************************

Imports
Expand Down
6 changes: 3 additions & 3 deletions src/fakedls/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module fakedls.main;

import ocean.transition;

import fakedls.DlsNode;
import turtle.env.Dls;

import dlsproto.client.legacy.DlsConst;

Expand Down Expand Up @@ -55,11 +55,11 @@ else
void main ( )
{
auto epoll = new EpollSelectDispatcher;
auto node = new DlsNode(DlsConst.NodeItem("127.0.0.1".dup, 10000), epoll);
Dls.initialize("127.0.0.1", 10000, epoll);

auto log = Log.lookup("fakedls.main");
log.info("Registering fake node");
node.register(epoll);
dls.register(epoll);

log.info(
"Starting infinite event loop, kill the process if not needed anymore");
Expand Down
125 changes: 65 additions & 60 deletions src/turtle/env/Dls.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ module turtle.env.Dls;
import ocean.transition;
import ocean.core.Verify;

import turtle.env.model.Node;
import turtle.env.model.TestNode;

import ocean.transition;

import fakedls.DlsNode;
import fakedls.Storage;
import fakedls.ConnectionHandler;

/*******************************************************************************

Expand Down Expand Up @@ -68,27 +69,69 @@ private Dls _dls;

*******************************************************************************/

public class Dls : Node!(DlsNode, "dls")
public class Dls : TestNode!(DlsConnectionHandler)
{
import swarm.neo.AddrPort;
public import dlsproto.client.legacy.DlsConst;
static import swarm.util.Hash;
import swarm.node.connection.ConnectionHandler;

import ocean.core.Enforce;
import ocean.text.convert.Formatter;
import ocean.task.Scheduler;
import swarm.Const: NodeItem;

import fakedls.neo.RequestHandlers;
import fakedls.neo.SharedResources;

/***************************************************************************

Prepares DLS singleton for usage from tests

TODO

***************************************************************************/

public static void initialize ( )
public static void initialize ( cstring addr, ushort port,
EpollSelectDispatcher epoll )
{
if ( !_dls )
_dls = new Dls();
{
AddrPort node;
node.setAddress(addr);
node.port = port;
_dls = new Dls(node, epoll);
}
}

/***************************************************************************

Constructor.

Params:
node = node addres & port
TODO

***************************************************************************/

public this ( AddrPort node, EpollSelectDispatcher epoll )
{
auto setup = new ConnectionSetupParams;
setup.epoll = epoll;
setup.node_info = this;

Options options;
options.epoll = epoll;
options.credentials_map["test"] = Key.init;
options.requests = requests;
options.no_delay = true; // favour network turn-around over packet
// efficiency

// TODO: compare with old code in fakedls.DlsNode
ushort neo_port = node.port + 1;
int backlog = 1024;

super(node, neo_port, setup, options, backlog);
}

/***************************************************************************
Expand Down Expand Up @@ -195,94 +238,56 @@ public class Dls : Node!(DlsNode, "dls")

/***************************************************************************

Creates a fake node at the specified address/port.

Params:
node_addrport = address/port

***************************************************************************/

override protected DlsNode createNode ( AddrPort node_addrport )
{
auto epoll = theScheduler.epoll();

auto addr = node_addrport.address_bytes();
auto node_item = NodeItem(
format("{}.{}.{}.{}", addr[0], addr[1], addr[2], addr[3]).dup,
node_addrport.port());

auto node = new DlsNode(node_item, epoll);
node.register(epoll);

return node;
}

/***************************************************************************

Returns:
address/port on which node is listening

***************************************************************************/

override public AddrPort node_addrport ( )
{
verify(this.node !is null);

AddrPort addrport;
addrport.setAddress(this.node.node_item.Address);
addrport.port = cast(ushort)this.node.node_item.Port;

return addrport;
}

/***************************************************************************

Stops the fake DLS service. The node may be started again on the same
port via restart().
Removes all data from the fake node service.

***************************************************************************/

override protected void stopImpl ( )
override public void clear ( )
{
this.node.stopListener(theScheduler.epoll);
this.node.shutdown();
global_storage.clear();
}

/***************************************************************************

Removes all data from the fake node service.
Returns:
identifier string for this node

***************************************************************************/

override public void clear ( )
protected override cstring id ( )
{
global_storage.clear();
return "dls";
}

/***************************************************************************

Suppresses/allows log output from the fake node if used version of node
proto supports it.
Scope allocates a request resource acquirer instance and passes it to
the provided delegate for use in a request.

Params:
log = true to log errors, false to stop logging errors
handle_request_dg = delegate that receives a resources acquirer and
initiates handling of a request

***************************************************************************/

override public void log_errors ( bool log )
override protected void getResourceAcquirer (
void delegate ( Object request_resources ) handle_request_dg )
{
this.node.log_errors = log;
// In the fake node, we don't actually store a shared resources
// instance; a new one is simply passed to each request.
handle_request_dg(new SharedResources);
}
}

version (UnitTest)
{
import ocean.core.Test;
import ocean.io.select.EpollSelectDispatcher;

void initDls ( )
{
global_storage.clear();
Dls.initialize();
Dls.initialize("127.0.0.1", 10000, new EpollSelectDispatcher);
}
}

Expand Down
2 changes: 1 addition & 1 deletion submodules/swarm
Submodule swarm updated 210 files