Skip to content

Commit

Permalink
WIP works! (code is a mess)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Norman committed Aug 9, 2018
1 parent a7ea0a5 commit 651c3a5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
4 changes: 4 additions & 0 deletions integrationtest/turtleenv/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ class Tests : Task
this.node.restart();
Stdout.formatln("Restarted node");

client.blocking.waitAllNodesConnected();
ok = this.testNode();
enforce(ok);

// TODO:
// run tests (see below)
// wait(2);
Expand Down
73 changes: 55 additions & 18 deletions src/swarm/node/model/NeoNode.d
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,20 @@ public abstract class INodeBase : INode, INodeInfo

conn_setup_params.error_dg = &this.error;

this.listener = listener;
this.neo_listener = neo_listener;
this.unix_listener = unix_listener;
this.initListeners(listener, neo_listener, unix_listener);

this.record_action_counters_ = new RecordActionCounters(this.record_action_counter_ids);
}

/// TODO
protected void initListeners ( lazy ISelectListener listener,
ISelectListener neo_listener = null,
ISelectListener unix_listener = null )
{
this.listener = listener;
this.neo_listener = neo_listener;
this.unix_listener = unix_listener;
}

/**************************************************************************
Expand Down Expand Up @@ -764,19 +771,29 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase
***************************************************************************/


private NodeItem node;
private ushort neo_port;
private ConnectionSetupParams conn_setup_params;
private Neo.ConnectionHandler.SharedParams neo_conn_setup_params;
private Options options;
private int backlog;

public this ( NodeItem node, ushort neo_port,
ConnectionSetupParams conn_setup_params, Options options,
int backlog )
{
this.node = node;
this.neo_port = neo_port;
this.conn_setup_params = conn_setup_params;
this.options = options;
this.backlog = backlog;

verify(options.epoll !is null);

this.shared_resources = options.shared_resources;

InetAddress!(false) addr, neo_addr;

// Create listener sockets.
this.socket = new AddressIPSocket!();
this.neo_socket = new AddressIPSocket!();

// Load credentials from specified file.
Const!(Key[istring])* credentials;
Expand All @@ -803,7 +820,7 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase
auto no_delay = true;

// Instantiate params object shared by all neo connection handlers.
auto neo_conn_setup_params = new Neo.ConnectionHandler.SharedParams(
this.neo_conn_setup_params = new Neo.ConnectionHandler.SharedParams(
options.epoll, options.requests,
no_delay, *credentials, this, &this.getResourceAcquirer);

Expand All @@ -825,16 +842,7 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase

// Super ctor.
super(node, conn_setup_params,
this.listener = new Listener(
addr(node.Address, node.Port), this.socket, conn_setup_params,
backlog
),
this.neo_listener = new NeoListener(
neo_addr(node.Address, neo_port), this.neo_socket,
neo_conn_setup_params, backlog
),
unix_listener
);
this.newListener(), this.newNeoListener(), unix_listener);

// Set up stats tracking for all named requests specified.
options.requests.initStats(this.neo_request_stats);
Expand All @@ -848,6 +856,35 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase
this.neo_address_.port(this.neo_socket.port());
}


/// TODO
public void restartListeners ( )
{
this.newListener();
this.newNeoListener();
this.initListeners(this.listener, this.neo_listener, this.unix_listener);
}

/// TODO
private Listener newListener ( )
{
InetAddress!(false) addr;
this.socket = new AddressIPSocket!();
return this.listener = new Listener(
addr(this.node.Address, this.node.Port), this.socket,
this.conn_setup_params, this.backlog);
}

/// TODO
private NeoListener newNeoListener ( )
{
InetAddress!(false) neo_addr;
this.neo_socket = new AddressIPSocket!();
return this.neo_listener = new NeoListener(
neo_addr(this.node.Address, this.neo_port), this.neo_socket,
this.neo_conn_setup_params, this.backlog);
}

/**************************************************************************
Returns:
Expand Down
5 changes: 2 additions & 3 deletions src/turtle/env/model/TestNode.d
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,14 @@ import ocean.task.Task;
2. You must call stop() first, before calling restart().
***************************************************************************/

// TODO: this is untested! -- the old version worked by creating a new node instance
// TODO: make this work without requiring stop first
public void restart ( )
{
verify(this.state == State.Stopped, "Node has not been stopped");

this.restartListeners();
this.register(theScheduler.epoll);
// TODO: do we need to do anything to restart the listeners? (they've been shut down)
turtle_env_registry.register(this);

this.state = State.Running;
}
Expand Down

0 comments on commit 651c3a5

Please sign in to comment.