@@ -4,41 +4,62 @@ use nym_sdk::mixnet;
4
4
async fn main ( ) {
5
5
logging:: setup_logging ( ) ;
6
6
7
- // We can set a few options
8
7
let user_chosen_gateway_id = None ;
9
8
let nym_api_endpoints = vec ! [ "https://validator.nymtech.net/api/" . parse( ) . unwrap( ) ] ;
10
-
11
9
let config = mixnet:: Config :: new ( user_chosen_gateway_id, nym_api_endpoints) ;
12
10
13
- let mut client = mixnet:: MixnetClient :: builder ( Some ( config) , None )
14
- . await
15
- . unwrap ( ) ;
16
-
17
11
// Just some plain data to pretend we have some external storage that the application
18
12
// implementer is using.
19
13
let mut mock_storage = MockStorage :: empty ( ) ;
20
14
21
- // In this we want to provide our own gateway config struct, and handle persisting this info to disk
22
- // ourselves (e.g., as part of our own configuration file).
23
15
let first_run = true ;
24
- if first_run {
25
- client. register_with_gateway ( ) . await . unwrap ( ) ;
16
+
17
+ let client = if first_run {
18
+ // Create a client without a storage backend
19
+ let mut client = mixnet:: MixnetClientBuilder :: new ( )
20
+ . config ( config)
21
+ . build :: < mixnet:: EmptyReplyStorage > ( )
22
+ . await
23
+ . unwrap ( ) ;
24
+
25
+ // In this we want to provide our own gateway config struct, and handle persisting this info to disk
26
+ // ourselves (e.g., as part of our own configuration file).
27
+ client. register_and_authenticate_gateway ( ) . await . unwrap ( ) ;
26
28
mock_storage. write ( client. get_keys ( ) , client. get_gateway_endpoint ( ) . unwrap ( ) ) ;
29
+ client
27
30
} else {
28
31
let ( keys, gateway_config) = mock_storage. read ( ) ;
29
- client. set_keys ( keys) ;
30
- client. set_gateway_endpoint ( gateway_config) ;
31
- }
32
+
33
+ // Create a client without a storage backend, but with explicitly set keys and gateway
34
+ // configuration. This creates the client in a registered state.
35
+ let client = mixnet:: MixnetClientBuilder :: new ( )
36
+ . config ( config)
37
+ . keys ( keys)
38
+ . gateway_config ( gateway_config)
39
+ . build :: < mixnet:: EmptyReplyStorage > ( )
40
+ . await
41
+ . unwrap ( ) ;
42
+ client
43
+ } ;
32
44
33
45
// Connect to the mixnet, now we're listening for incoming
34
- let client = client. connect_to_mixnet ( ) . await . unwrap ( ) ;
46
+ let mut client = client. connect_to_mixnet ( ) . await . unwrap ( ) ;
35
47
36
48
// Be able to get our client address
37
- println ! ( "Our client address is {}" , client. nym_address( ) ) ;
49
+ let our_address = client. nym_address ( ) ;
50
+ println ! ( "Our client nym address is: {our_address}" ) ;
38
51
39
52
// Send important info up the pipe to a buddy
40
- let recipient = mixnet:: Recipient :: try_from_base58_string ( "foo.bar@blah" ) . unwrap ( ) ;
41
- client. send_str ( recipient, "flappappa" ) . await ;
53
+ client. send_str ( * our_address, "hello there" ) . await ;
54
+
55
+ println ! ( "Waiting for message" ) ;
56
+ if let Some ( received) = client. wait_for_messages ( ) . await {
57
+ for r in received {
58
+ println ! ( "Received: {}" , String :: from_utf8_lossy( & r. message) ) ;
59
+ }
60
+ }
61
+
62
+ client. disconnect ( ) . await ;
42
63
}
43
64
44
65
#[ allow( unused) ]
@@ -53,7 +74,7 @@ impl MockStorage {
53
74
}
54
75
55
76
fn write ( & mut self , _keys : mixnet:: KeysArc , _gateway_config : & mixnet:: GatewayEndpointConfig ) {
56
- todo ! ( ) ;
77
+ log :: info! ( "todo" ) ;
57
78
}
58
79
59
80
fn empty ( ) -> Self {
0 commit comments