@@ -88,10 +88,10 @@ impl Worker for Hop {
88
88
/// This handle function takes any incoming message and forwards
89
89
/// it to the next hop in it's onward route
90
90
async fn handle_message (& mut self , ctx : & mut Context , msg : Routed <Any >) -> Result <()> {
91
- println! (" Address: {}, Received: {:?}" , ctx . address (), msg );
91
+ println! (" Address: {}, Received: {:?}" , ctx . primary_address (), msg );
92
92
93
93
// Send the message to the next worker on its onward_route
94
- ctx . forward (msg . into_local_message (). step_forward (& ctx . address ())? )
94
+ ctx . forward (msg . into_local_message (). step_forward (ctx . primary_address () . clone ())? )
95
95
. await
96
96
}
97
97
}
@@ -136,10 +136,10 @@ async fn main(ctx: Context) -> Result<()> {
136
136
let mut node = node (ctx ). await ? ;
137
137
138
138
// Start a worker, of type Echoer, at address "echoer"
139
- node . start_worker (" echoer" , Echoer ). await ? ;
139
+ node . start_worker (" echoer" , Echoer )? ;
140
140
141
141
// Start a worker, of type Hop, at address "h1"
142
- node . start_worker (" h1" , Hop ). await ? ;
142
+ node . start_worker (" h1" , Hop )? ;
143
143
144
144
// Send a message to the worker at address "echoer",
145
145
// via the worker at address "h1"
@@ -150,7 +150,7 @@ async fn main(ctx: Context) -> Result<()> {
150
150
println! (" App Received: {}" , reply . into_body ()? ); // should print "Hello Ockam!"
151
151
152
152
// Stop all workers, stop the node, cleanup and return.
153
- node . stop (). await
153
+ node . shutdown (). await
154
154
}
155
155
156
156
```
@@ -190,12 +190,12 @@ async fn main(ctx: Context) -> Result<()> {
190
190
let mut node = node (ctx ). await ? ;
191
191
192
192
// Start an Echoer worker at address "echoer"
193
- node . start_worker (" echoer" , Echoer ). await ? ;
193
+ node . start_worker (" echoer" , Echoer )? ;
194
194
195
195
// Start 3 hop workers at addresses "h1", "h2" and "h3".
196
- node . start_worker (" h1" , Hop ). await ? ;
197
- node . start_worker (" h2" , Hop ). await ? ;
198
- node . start_worker (" h3" , Hop ). await ? ;
196
+ node . start_worker (" h1" , Hop )? ;
197
+ node . start_worker (" h2" , Hop )? ;
198
+ node . start_worker (" h3" , Hop )? ;
199
199
200
200
// Send a message to the echoer worker via the "h1", "h2", and "h3" workers
201
201
let r = route! [" h1" , " h2" , " h3" , " echoer" ];
@@ -206,7 +206,7 @@ async fn main(ctx: Context) -> Result<()> {
206
206
println! (" App Received: {}" , reply . into_body ()? ); // should print "Hello Ockam!"
207
207
208
208
// Stop all workers, stop the node, cleanup and return.
209
- node . stop (). await
209
+ node . shutdown (). await
210
210
}
211
211
212
212
```
@@ -250,18 +250,19 @@ async fn main(ctx: Context) -> Result<()> {
250
250
let node = node (ctx ). await ? ;
251
251
252
252
// Initialize the TCP Transport
253
- let tcp = node . create_tcp_transport (). await ? ;
253
+ let tcp = node . create_tcp_transport ()? ;
254
254
255
255
// Create an echoer worker
256
- node . start_worker (" echoer" , Echoer ). await ? ;
256
+ node . start_worker (" echoer" , Echoer )? ;
257
257
258
258
// Create a TCP listener and wait for incoming connections.
259
259
let listener = tcp . listen (" 127.0.0.1:4000" , TcpListenerOptions :: new ()). await ? ;
260
260
261
261
// Allow access to the Echoer via TCP connections from the TCP listener
262
- node . flow_controls (). add_consumer (" echoer" , listener . flow_control_id ());
262
+ node . flow_controls ()
263
+ . add_consumer (& " echoer" . into (), listener . flow_control_id ());
263
264
264
- // Don't call node.stop () here so this node runs forever.
265
+ // Don't call node.shutdown () here so this node runs forever.
265
266
Ok (())
266
267
}
267
268
@@ -290,7 +291,7 @@ async fn main(ctx: Context) -> Result<()> {
290
291
let mut node = node (ctx ). await ? ;
291
292
292
293
// Initialize the TCP Transport.
293
- let tcp = node . create_tcp_transport (). await ? ;
294
+ let tcp = node . create_tcp_transport ()? ;
294
295
295
296
// Create a TCP connection to a different node.
296
297
let connection_to_responder = tcp . connect (" localhost:4000" , TcpConnectionOptions :: new ()). await ? ;
@@ -303,7 +304,7 @@ async fn main(ctx: Context) -> Result<()> {
303
304
println! (" App Received: {}" , reply ); // should print "Hello Ockam!"
304
305
305
306
// Stop all workers, stop the node, cleanup and return.
306
- node . stop (). await
307
+ node . shutdown (). await
307
308
}
308
309
309
310
```
@@ -374,28 +375,27 @@ impl Worker for Relay {
374
375
/// This handle function takes any incoming message and forwards
375
376
/// it to the next hop in it's onward route
376
377
async fn handle_message (& mut self , ctx : & mut Context , msg : Routed <Any >) -> Result <()> {
377
- println! (" Address: {}, Received: {:?}" , ctx . address (), msg );
378
+ println! (" Address: {}, Received: {:?}" , ctx . primary_address (), msg );
378
379
379
380
let next_on_route = self . route. next ()? . clone ();
380
381
381
382
// Some type conversion
382
383
let mut local_message = msg . into_local_message ();
383
384
384
385
local_message = local_message . pop_front_onward_route ()? ;
385
- local_message = local_message . prepend_front_onward_route (& self . route); // Prepend predefined route to the onward_route
386
+ local_message = local_message . prepend_front_onward_route (self . route. clone () ); // Prepend predefined route to the onward_route
386
387
387
388
let prev_hop = local_message . return_route (). next ()? . clone ();
388
389
389
390
if let Some (info ) = ctx
390
391
. flow_controls ()
391
392
. find_flow_control_with_producer_address (& next_on_route )
392
393
{
393
- ctx . flow_controls ()
394
- . add_consumer (prev_hop . clone (), info . flow_control_id ());
394
+ ctx . flow_controls (). add_consumer (& prev_hop , info . flow_control_id ());
395
395
}
396
396
397
397
if let Some (info ) = ctx . flow_controls (). find_flow_control_with_producer_address (& prev_hop ) {
398
- ctx . flow_controls (). add_consumer (next_on_route , info . flow_control_id ());
398
+ ctx . flow_controls (). add_consumer (& next_on_route , info . flow_control_id ());
399
399
}
400
400
401
401
// Send the message on its onward_route
@@ -437,18 +437,19 @@ async fn main(ctx: Context) -> Result<()> {
437
437
let node = node (ctx ). await ? ;
438
438
439
439
// Initialize the TCP Transport
440
- let tcp = node . create_tcp_transport (). await ? ;
440
+ let tcp = node . create_tcp_transport ()? ;
441
441
442
442
// Create an echoer worker
443
- node . start_worker (" echoer" , Echoer ). await ? ;
443
+ node . start_worker (" echoer" , Echoer )? ;
444
444
445
445
// Create a TCP listener and wait for incoming connections.
446
446
let listener = tcp . listen (" 127.0.0.1:4000" , TcpListenerOptions :: new ()). await ? ;
447
447
448
448
// Allow access to the Echoer via TCP connections from the TCP listener
449
- node . flow_controls (). add_consumer (" echoer" , listener . flow_control_id ());
449
+ node . flow_controls ()
450
+ . add_consumer (& " echoer" . into (), listener . flow_control_id ());
450
451
451
- // Don't call node.stop () here so this node runs forever.
452
+ // Don't call node.shutdown () here so this node runs forever.
452
453
Ok (())
453
454
}
454
455
@@ -481,23 +482,22 @@ async fn main(ctx: Context) -> Result<()> {
481
482
let node = node (ctx ). await ? ;
482
483
483
484
// Initialize the TCP Transport
484
- let tcp = node . create_tcp_transport (). await ? ;
485
+ let tcp = node . create_tcp_transport ()? ;
485
486
486
487
// Create a TCP connection to the responder node.
487
488
let connection_to_responder = tcp . connect (" 127.0.0.1:4000" , TcpConnectionOptions :: new ()). await ? ;
488
489
489
490
// Create and start a Relay worker
490
- node . start_worker (" forward_to_responder" , Relay :: new (connection_to_responder ))
491
- . await ? ;
491
+ node . start_worker (" forward_to_responder" , Relay :: new (connection_to_responder ))? ;
492
492
493
493
// Create a TCP listener and wait for incoming connections.
494
494
let listener = tcp . listen (" 127.0.0.1:3000" , TcpListenerOptions :: new ()). await ? ;
495
495
496
496
// Allow access to the Relay via TCP connections from the TCP listener
497
497
node . flow_controls ()
498
- . add_consumer (" forward_to_responder" , listener . flow_control_id ());
498
+ . add_consumer (& " forward_to_responder" . into () , listener . flow_control_id ());
499
499
500
- // Don't call node.stop () here so this node runs forever.
500
+ // Don't call node.shutdown () here so this node runs forever.
501
501
Ok (())
502
502
}
503
503
@@ -526,7 +526,7 @@ async fn main(ctx: Context) -> Result<()> {
526
526
let mut node = node (ctx ). await ? ;
527
527
528
528
// Initialize the TCP Transport
529
- let tcp = node . create_tcp_transport (). await ? ;
529
+ let tcp = node . create_tcp_transport ()? ;
530
530
531
531
// Create a TCP connection to the middle node.
532
532
let connection_to_middle_node = tcp . connect (" localhost:3000" , TcpConnectionOptions :: new ()). await ? ;
@@ -538,7 +538,7 @@ async fn main(ctx: Context) -> Result<()> {
538
538
println! (" App Received: {}" , reply ); // should print "Hello Ockam!"
539
539
540
540
// Stop all workers, stop the node, cleanup and return.
541
- node . stop (). await
541
+ node . shutdown (). await
542
542
}
543
543
544
544
```
0 commit comments