@@ -31,6 +31,7 @@ use tokio::task::JoinHandle;
31
31
use tracing:: { debug, error, info, trace, warn} ;
32
32
33
33
use iroh_bitswap:: { BitswapEvent , Block } ;
34
+ use iroh_rpc_client:: Lookup ;
34
35
35
36
use crate :: keys:: { Keychain , Storage } ;
36
37
use crate :: providers:: Providers ;
@@ -953,6 +954,29 @@ impl<KeyStorage: Storage> Node<KeyStorage> {
953
954
response_channel. send ( None ) . ok ( ) ;
954
955
}
955
956
}
957
+ RpcMessage :: LookupLocalPeerInfo ( response_channel) => {
958
+ let peer_id = self . swarm . local_peer_id ( ) ;
959
+ let listen_addrs = self . swarm . listeners ( ) . cloned ( ) . collect ( ) ;
960
+ let observed_addrs = self
961
+ . swarm
962
+ . external_addresses ( )
963
+ . map ( |a| a. addr . clone ( ) )
964
+ . collect ( ) ;
965
+ let protocol_version = String :: from ( crate :: behaviour:: PROTOCOL_VERSION ) ;
966
+ let agent_version = String :: from ( crate :: behaviour:: AGENT_VERSION ) ;
967
+ let protocols = self . swarm . behaviour ( ) . peer_manager . supported_protocols ( ) ;
968
+
969
+ response_channel
970
+ . send ( Lookup {
971
+ peer_id : * peer_id,
972
+ listen_addrs,
973
+ observed_addrs,
974
+ agent_version,
975
+ protocol_version,
976
+ protocols,
977
+ } )
978
+ . ok ( ) ;
979
+ }
956
980
RpcMessage :: CancelListenForIdentify ( response_channel, peer_id) => {
957
981
self . lookup_queries . remove ( & peer_id) ;
958
982
response_channel. send ( ( ) ) . ok ( ) ;
@@ -1312,6 +1336,12 @@ mod tests {
1312
1336
let peer_id_b = test_runner_b. client . local_peer_id ( ) . await ?;
1313
1337
assert_eq ! ( test_runner_b. peer_id, peer_id_b) ;
1314
1338
1339
+ let lookup_a = test_runner_a. client . lookup_local ( ) . await ?;
1340
+ // since we aren't connected to any other nodes, we should not
1341
+ // have any information about our observed addresses
1342
+ assert ! ( lookup_a. observed_addrs. is_empty( ) ) ;
1343
+ assert_lookup ( lookup_a, test_runner_a. peer_id , & test_runner_a. addr ) ?;
1344
+
1315
1345
// connect
1316
1346
test_runner_a. client . connect ( peer_id_b, addrs_b) . await ?;
1317
1347
// Make sure we have exchanged identity information
@@ -1323,8 +1353,7 @@ mod tests {
1323
1353
1324
1354
// lookup
1325
1355
let lookup_b = test_runner_a. client . lookup ( peer_id_b, None ) . await ?;
1326
- assert_eq ! ( peer_id_b, lookup_b. peer_id) ;
1327
-
1356
+ assert_lookup ( lookup_b, test_runner_b. peer_id , & test_runner_b. addr ) ?;
1328
1357
// now that we are connected & have exchanged identity information,
1329
1358
// we should now be able to view the node's external addrs
1330
1359
// these are the addresses that other nodes tell you "this is the address I see for you"
@@ -1339,6 +1368,39 @@ mod tests {
1339
1368
Ok ( ( ) )
1340
1369
}
1341
1370
1371
+ // assert_lookup ensures each part of the lookup is equal
1372
+ fn assert_lookup (
1373
+ got : Lookup ,
1374
+ expected_peer_id : PeerId ,
1375
+ expected_addr : & Multiaddr ,
1376
+ ) -> Result < ( ) > {
1377
+ let expected_protocols = vec ! [
1378
+ "/ipfs/ping/1.0.0" ,
1379
+ "/ipfs/id/1.0.0" ,
1380
+ "/ipfs/id/push/1.0.0" ,
1381
+ "/ipfs/bitswap/1.2.0" ,
1382
+ "/ipfs/bitswap/1.1.0" ,
1383
+ "/ipfs/bitswap/1.0.0" ,
1384
+ "/ipfs/bitswap" ,
1385
+ "/ipfs/kad/1.0.0" ,
1386
+ "/libp2p/autonat/1.0.0" ,
1387
+ "/libp2p/circuit/relay/0.2.0/hop" ,
1388
+ "/libp2p/circuit/relay/0.2.0/stop" ,
1389
+ "/libp2p/dcutr" ,
1390
+ "/meshsub/1.1.0" ,
1391
+ "/meshsub/1.0.0" ,
1392
+ ] ;
1393
+ let expected_protocol_version = "ipfs/0.1.0" ;
1394
+ let expected_agent_version = "iroh/0.1.0" ;
1395
+
1396
+ assert_eq ! ( expected_peer_id, got. peer_id) ;
1397
+ assert ! ( got. listen_addrs. contains( expected_addr) ) ;
1398
+ assert_eq ! ( expected_protocols, got. protocols) ;
1399
+ assert_eq ! ( expected_protocol_version, got. protocol_version) ;
1400
+ assert_eq ! ( expected_agent_version, got. agent_version) ;
1401
+ Ok ( ( ) )
1402
+ }
1403
+
1342
1404
#[ tokio:: test]
1343
1405
async fn test_gossipsub ( ) -> Result < ( ) > {
1344
1406
let mut test_runner_a = TestRunnerBuilder :: new ( ) . no_bootstrap ( ) . build ( ) . await ?;
0 commit comments