File tree Expand file tree Collapse file tree
other_crates/bones_matchmaker/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use clap:: Parser ;
22use tracing:: metadata:: LevelFilter ;
3+ use tracing:: warn;
34
45pub async fn start ( ) {
56 configure_logging ( ) ;
67
78 let args = crate :: Config :: parse ( ) ;
9+ let secret_key = match std:: env:: var ( "BONES_MATCHMAKER_SECRET_KEY" ) {
10+ Ok ( key) => match key. parse :: < iroh_net:: key:: SecretKey > ( ) {
11+ Ok ( key) => Some ( key) ,
12+ Err ( _) => {
13+ warn ! ( "invalid matchmaker key provided" ) ;
14+ None
15+ }
16+ } ,
17+ Err ( _) => None ,
18+ } ;
819
9- if let Err ( e) = super :: server ( args) . await {
20+ if let Err ( e) = super :: server ( args, secret_key ) . await {
1021 eprintln ! ( "Error: {e}" ) ;
1122 }
1223}
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ extern crate tracing;
88use std:: net:: SocketAddr ;
99
1010use bones_matchmaker_proto:: MATCH_ALPN ;
11+ use iroh_net:: key:: SecretKey ;
1112
1213pub mod cli;
1314
@@ -19,12 +20,29 @@ struct Config {
1920 /// The server address to listen on
2021 #[ clap( short, long = "listen" , default_value = "0.0.0.0:8943" ) ]
2122 listen_addr : SocketAddr ,
23+ /// If enabled, prints the current secret key. Use with caution.
24+ #[ clap( long) ]
25+ print_secret_key : bool ,
2226}
2327
24- async fn server ( args : Config ) -> anyhow:: Result < ( ) > {
28+ async fn server ( args : Config , secret_key : Option < SecretKey > ) -> anyhow:: Result < ( ) > {
2529 let port = args. listen_addr . port ( ) ;
2630
27- let secret_key = iroh_net:: key:: SecretKey :: generate ( ) ;
31+ match secret_key {
32+ Some ( ref key) => {
33+ info ! ( "Using existing key: {}" , key. public( ) ) ;
34+ }
35+ None => {
36+ info ! ( "Generating new key" ) ;
37+ }
38+ }
39+
40+ let secret_key = secret_key. unwrap_or_else ( SecretKey :: generate) ;
41+
42+ if args. print_secret_key {
43+ println ! ( "Secret Key: {}" , secret_key) ;
44+ }
45+
2846 let endpoint = iroh_net:: MagicEndpoint :: builder ( )
2947 . alpns ( vec ! [ MATCH_ALPN . to_vec( ) ] )
3048 . discovery ( Box :: new (
You can’t perform that action at this time.
0 commit comments