@@ -24,12 +24,13 @@ module turtle.env.Dls;
2424import ocean.transition;
2525import ocean.core.Verify ;
2626
27- import turtle.env.model.Node ;
27+ import turtle.env.model.TestNode ;
2828
2929import ocean.transition;
3030
3131import fakedls.DlsNode;
3232import fakedls.Storage;
33+ import fakedls.ConnectionHandler;
3334
3435/* ******************************************************************************
3536
@@ -68,27 +69,69 @@ private Dls _dls;
6869
6970*******************************************************************************/
7071
71- public class Dls : Node !(DlsNode, "dls" )
72+ public class Dls : TestNode !(DlsConnectionHandler )
7273{
7374 import swarm.neo.AddrPort;
7475 public import dlsproto.client.legacy.DlsConst;
7576 static import swarm.util.Hash;
77+ import swarm.node.connection.ConnectionHandler;
7678
7779 import ocean.core.Enforce ;
7880 import ocean.text.convert.Formatter;
7981 import ocean.task.Scheduler;
8082 import swarm.Const: NodeItem;
8183
84+ import fakedls.neo.RequestHandlers;
85+ import fakedls.neo.SharedResources;
86+
8287 /* **************************************************************************
8388
8489 Prepares DLS singleton for usage from tests
8590
91+ TODO
92+
8693 ***************************************************************************/
8794
88- public static void initialize ( )
95+ public static void initialize ( cstring addr, ushort port,
96+ EpollSelectDispatcher epoll )
8997 {
9098 if ( ! _dls )
91- _dls = new Dls();
99+ {
100+ AddrPort node;
101+ node.setAddress(addr);
102+ node.port = port;
103+ _dls = new Dls(node, epoll);
104+ }
105+ }
106+
107+ /* **************************************************************************
108+
109+ Constructor.
110+
111+ Params:
112+ node = node addres & port
113+ TODO
114+
115+ ***************************************************************************/
116+
117+ public this ( AddrPort node, EpollSelectDispatcher epoll )
118+ {
119+ auto setup = new ConnectionSetupParams;
120+ setup.epoll = epoll;
121+ setup.node_info = this ;
122+
123+ Options options;
124+ options.epoll = epoll;
125+ options.credentials_map[" test" ] = Key.init;
126+ options.requests = requests;
127+ options.no_delay = true ; // favour network turn-around over packet
128+ // efficiency
129+
130+ // TODO: compare with old code in fakedls.DlsNode
131+ ushort neo_port = node.port + 1 ;
132+ int backlog = 1024 ;
133+
134+ super (node, neo_port, setup, options, backlog);
92135 }
93136
94137 /* **************************************************************************
@@ -195,94 +238,56 @@ public class Dls : Node!(DlsNode, "dls")
195238
196239 /* **************************************************************************
197240
198- Creates a fake node at the specified address/port.
199-
200- Params:
201- node_addrport = address/port
202-
203- ***************************************************************************/
204-
205- override protected DlsNode createNode ( AddrPort node_addrport )
206- {
207- auto epoll = theScheduler.epoll();
208-
209- auto addr = node_addrport.address_bytes();
210- auto node_item = NodeItem(
211- format(" {}.{}.{}.{}" , addr[0 ], addr[1 ], addr[2 ], addr[3 ]).dup ,
212- node_addrport.port());
213-
214- auto node = new DlsNode(node_item, epoll);
215- node.register(epoll);
216-
217- return node;
218- }
219-
220- /* **************************************************************************
221-
222- Returns:
223- address/port on which node is listening
224-
225- ***************************************************************************/
226-
227- override public AddrPort node_addrport ( )
228- {
229- verify(this .node ! is null );
230-
231- AddrPort addrport;
232- addrport.setAddress(this .node.node_item.Address);
233- addrport.port = cast (ushort )this .node.node_item.Port;
234-
235- return addrport;
236- }
237-
238- /* **************************************************************************
239-
240- Stops the fake DLS service. The node may be started again on the same
241- port via restart().
241+ Removes all data from the fake node service.
242242
243243 ***************************************************************************/
244244
245- override protected void stopImpl ( )
245+ override public void clear ( )
246246 {
247- this .node.stopListener(theScheduler.epoll);
248- this .node.shutdown();
247+ global_storage.clear();
249248 }
250249
251250 /* **************************************************************************
252251
253- Removes all data from the fake node service.
252+ Returns:
253+ identifier string for this node
254254
255255 ***************************************************************************/
256256
257- override public void clear ( )
257+ protected override cstring id ( )
258258 {
259- global_storage.clear() ;
259+ return " dls " ;
260260 }
261261
262262 /* **************************************************************************
263263
264- Suppresses/allows log output from the fake node if used version of node
265- proto supports it .
264+ Scope allocates a request resource acquirer instance and passes it to
265+ the provided delegate for use in a request .
266266
267267 Params:
268- log = true to log errors, false to stop logging errors
268+ handle_request_dg = delegate that receives a resources acquirer and
269+ initiates handling of a request
269270
270271 ***************************************************************************/
271272
272- override public void log_errors ( bool log )
273+ override protected void getResourceAcquirer (
274+ void delegate ( Object request_resources ) handle_request_dg )
273275 {
274- this .node.log_errors = log;
276+ // In the fake node, we don't actually store a shared resources
277+ // instance; a new one is simply passed to each request.
278+ handle_request_dg(new SharedResources);
275279 }
276280}
277281
278282version (UnitTest)
279283{
280284 import ocean.core.Test ;
285+ import ocean.io.select.EpollSelectDispatcher;
281286
282287 void initDls ( )
283288 {
284289 global_storage.clear();
285- Dls.initialize();
290+ Dls.initialize(" 127.0.0.1 " , 10000 , new EpollSelectDispatcher );
286291 }
287292}
288293
0 commit comments