Skip to content

Commit

Permalink
NeoNode Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Norman committed Aug 9, 2018
1 parent 651c3a5 commit d04a70a
Showing 1 changed file with 43 additions and 46 deletions.
89 changes: 43 additions & 46 deletions src/swarm/node/model/NeoNode.d
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ public abstract class INodeBase : INode, INodeInfo
***************************************************************************/

public this ( NodeItem node, ConnectionSetupParams conn_setup_params,
lazy ISelectListener listener,
ISelectListener neo_listener = null,
ISelectListener unix_listener = null )
public this ( NodeItem node, ConnectionSetupParams conn_setup_params )
{
this.node_item_ = node;

Expand All @@ -211,19 +208,28 @@ public abstract class INodeBase : INode, INodeInfo

conn_setup_params.error_dg = &this.error;

this.initListeners(listener, neo_listener, unix_listener);
this.listener = this.newListener();
this.neo_listener = this.newNeoListener();
this.unix_listener = this.newUnixSocketListener();

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 )
protected abstract ISelectListener newListener ( );

/// TODO
protected abstract ISelectListener newNeoListener ( );

/// TODO
protected abstract ISelectListener newUnixSocketListener ( );

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

/**************************************************************************
Expand Down Expand Up @@ -824,25 +830,8 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase
options.epoll, options.requests,
no_delay, *credentials, this, &this.getResourceAcquirer);

// Set up unix listener socket, if specified.
UnixListener unix_listener;
if ( options.unix_socket_path.length )
{
BasicCommandHandler.Handler[istring] unix_socket_handlers;
if ( this.credentials_file )
{
unix_socket_handlers =
["update-credentials"[]: &this.handleUpdateCredentials,
"list-credentials": &this.handleListCredentials];
}

unix_listener = new UnixListener(
options.unix_socket_path, options.epoll, unix_socket_handlers);
}

// Super ctor.
super(node, conn_setup_params,
this.newListener(), this.newNeoListener(), unix_listener);
super(node, conn_setup_params);

// Set up stats tracking for all named requests specified.
options.requests.initStats(this.neo_request_stats);
Expand All @@ -856,17 +845,8 @@ 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 ( )
protected override ISelectListener newListener ( )
{
InetAddress!(false) addr;
this.socket = new AddressIPSocket!();
Expand All @@ -876,7 +856,7 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase
}

/// TODO
private NeoListener newNeoListener ( )
protected override ISelectListener newNeoListener ( )
{
InetAddress!(false) neo_addr;
this.neo_socket = new AddressIPSocket!();
Expand All @@ -885,6 +865,24 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase
this.neo_conn_setup_params, this.backlog);
}

/// TODO
protected override ISelectListener newUnixSocketListener ( )
{
if ( !options.unix_socket_path.length )
return null;

BasicCommandHandler.Handler[istring] unix_socket_handlers;
if ( this.credentials_file )
{
unix_socket_handlers =
["update-credentials"[]: &this.handleUpdateCredentials,
"list-credentials": &this.handleListCredentials];
}

return this.unix_listener = new UnixListener(
options.unix_socket_path, options.epoll, unix_socket_handlers);
}

/**************************************************************************
Returns:
Expand Down Expand Up @@ -1040,15 +1038,14 @@ public class NodeBase ( ConnHandler : ISwarmConnectionHandler ) : INodeBase
public this ( NodeItem node, ConnectionSetupParams conn_setup_params,
int backlog )
{
this.node = node;
this.conn_setup_params = conn_setup_params;
this.backlog = backlog;

InetAddress!(false) addr;

this.socket = new AddressIPSocket!();
super(node, conn_setup_params,
this.listener = new Listener(
addr(node.Address, node.Port), this.socket, conn_setup_params,
backlog
)
);
super(node, conn_setup_params);

enforce(this.socket.updateAddress() == 0, "socket.updateAddress() failed!");
}
Expand Down

0 comments on commit d04a70a

Please sign in to comment.