66extern crate tracing;
77
88use std:: net:: { Ipv4Addr , SocketAddr , SocketAddrV4 } ;
9+ use std:: sync:: Arc ;
910
1011use bones_matchmaker_proto:: MATCH_ALPN ;
11- use iroh_net:: key:: SecretKey ;
12+ use iroh:: key:: SecretKey ;
13+ use matchmaker:: Matchmaker ;
1214
1315pub mod cli;
1416mod helpers;
@@ -27,7 +29,7 @@ struct Config {
2729 print_secret_key : bool ,
2830 /// Use this secret key for the node
2931 #[ clap( short, long, env = "BONES_MATCHMAKER_SECRET_KEY" ) ]
30- secret_key : Option < iroh_net :: key:: SecretKey > ,
32+ secret_key : Option < iroh :: key:: SecretKey > ,
3133}
3234
3335async fn server ( args : Config ) -> anyhow:: Result < ( ) > {
@@ -48,17 +50,17 @@ async fn server(args: Config) -> anyhow::Result<()> {
4850 println ! ( "Secret Key: {}" , secret_key) ;
4951 }
5052
51- let endpoint = iroh_net :: Endpoint :: builder ( )
53+ let endpoint = iroh :: Endpoint :: builder ( )
5254 . alpns ( vec ! [ MATCH_ALPN . to_vec( ) ] )
5355 . discovery ( Box :: new (
54- iroh_net :: discovery:: ConcurrentDiscovery :: from_services ( vec ! [
56+ iroh :: discovery:: ConcurrentDiscovery :: from_services ( vec ! [
5557 Box :: new(
56- iroh_net :: discovery:: local_swarm_discovery:: LocalSwarmDiscovery :: new(
58+ iroh :: discovery:: local_swarm_discovery:: LocalSwarmDiscovery :: new(
5759 secret_key. public( ) ,
5860 ) ?,
5961 ) ,
60- Box :: new( iroh_net :: discovery:: dns:: DnsDiscovery :: n0_dns( ) ) ,
61- Box :: new( iroh_net :: discovery:: pkarr:: PkarrPublisher :: n0_dns(
62+ Box :: new( iroh :: discovery:: dns:: DnsDiscovery :: n0_dns( ) ) ,
63+ Box :: new( iroh :: discovery:: pkarr:: PkarrPublisher :: n0_dns(
6264 secret_key. clone( ) ,
6365 ) ) ,
6466 ] ) ,
@@ -74,24 +76,16 @@ async fn server(args: Config) -> anyhow::Result<()> {
7476
7577 println ! ( "Node ID: {}" , my_addr. node_id) ;
7678
77- // Listen for incomming connections
78- while let Some ( connecting) = endpoint. accept ( ) . await {
79- let connection = connecting. await ;
80-
81- match connection {
82- Ok ( conn) => {
83- info ! (
84- connection_id = conn. stable_id( ) ,
85- addr = ?conn. remote_address( ) ,
86- "Accepted connection from client"
87- ) ;
88-
89- // Spawn a task to handle the new connection
90- tokio:: task:: spawn ( matchmaker:: handle_connection ( endpoint. clone ( ) , conn) ) ;
91- }
92- Err ( e) => error ! ( "Error opening client connection: {e:?}" ) ,
93- }
94- }
79+ let matchmaker = Matchmaker :: new ( endpoint. clone ( ) ) ;
80+ let router = iroh:: protocol:: Router :: builder ( endpoint)
81+ . accept ( MATCH_ALPN , Arc :: new ( matchmaker) )
82+ . spawn ( )
83+ . await ?;
84+
85+ // wait for shutdown
86+ tokio:: signal:: ctrl_c ( ) . await ?;
87+
88+ router. shutdown ( ) . await ?;
9589
9690 info ! ( "Server shutdown" ) ;
9791
0 commit comments