@@ -11,7 +11,6 @@ use std::sync::Arc;
11
11
use std:: time:: Duration ;
12
12
13
13
use anyhow:: Result ;
14
- use gethostname:: gethostname;
15
14
use tokio:: sync:: broadcast;
16
15
use tokio:: sync:: Mutex ;
17
16
use tokio:: task:: JoinSet ;
@@ -53,7 +52,7 @@ struct ManagerState {
53
52
pub struct Manager {
54
53
replica_id : String ,
55
54
lighthouse_addr : String ,
56
- address : String ,
55
+ hostname : String ,
57
56
store_address : String ,
58
57
world_size : u64 ,
59
58
state : Mutex < ManagerState > ,
@@ -80,19 +79,20 @@ impl Manager {
80
79
pub async fn new (
81
80
replica_id : String ,
82
81
lighthouse_addr : String ,
83
- address : String ,
82
+ hostname : String ,
84
83
bind : String ,
85
84
store_addr : String ,
86
85
world_size : u64 ,
87
86
) -> Result < Arc < Self > > {
88
87
let listener = tokio:: net:: TcpListener :: bind ( & bind) . await ?;
88
+ let local_addr = listener. local_addr ( ) ?;
89
89
90
90
let ( should_commit_tx, _) = broadcast:: channel ( 16 ) ;
91
91
92
92
Ok ( Arc :: new ( Self {
93
93
replica_id : replica_id,
94
94
lighthouse_addr : lighthouse_addr,
95
- address : address ,
95
+ hostname : hostname ,
96
96
store_address : store_addr,
97
97
world_size : world_size,
98
98
state : Mutex :: new ( ManagerState {
@@ -103,7 +103,7 @@ impl Manager {
103
103
should_commit_count : HashSet :: new ( ) ,
104
104
should_commit_failures : HashSet :: new ( ) ,
105
105
} ) ,
106
- local_addr : listener . local_addr ( ) ? ,
106
+ local_addr : local_addr,
107
107
listener : Mutex :: new ( Some ( listener) ) ,
108
108
} ) )
109
109
}
@@ -122,11 +122,7 @@ impl Manager {
122
122
}
123
123
124
124
pub fn address ( & self ) -> String {
125
- format ! (
126
- "http://{}:{}" ,
127
- gethostname( ) . into_string( ) . unwrap( ) ,
128
- self . local_addr. port( )
129
- )
125
+ format ! ( "http://{}:{}" , self . hostname, self . local_addr. port( ) )
130
126
}
131
127
132
128
async fn _run_grpc ( self : Arc < Self > ) -> Result < ( ) > {
@@ -228,7 +224,7 @@ impl ManagerService for Arc<Manager> {
228
224
room_id : room_id. clone ( ) ,
229
225
requester : Some ( QuorumMember {
230
226
replica_id : self . replica_id . clone ( ) ,
231
- address : self . address . clone ( ) ,
227
+ address : self . address ( ) ,
232
228
store_address : self . store_address . clone ( ) ,
233
229
step : req. step ,
234
230
world_size : self . world_size ,
@@ -470,7 +466,7 @@ mod tests {
470
466
let manager = Manager :: new (
471
467
"rep_id" . to_string ( ) ,
472
468
lighthouse. address ( ) ,
473
- "addr " . to_string ( ) ,
469
+ "localhost " . to_string ( ) ,
474
470
"[::]:0" . to_string ( ) ,
475
471
"store_addr" . to_string ( ) ,
476
472
1 , // world size
@@ -493,7 +489,7 @@ mod tests {
493
489
lighthouse_fut. abort ( ) ;
494
490
495
491
assert_eq ! ( resp. quorum_id, 1 ) ;
496
- assert_eq ! ( resp. address, "addr" . to_string ( ) ) ;
492
+ assert_eq ! ( resp. address, manager . address ( ) ) ;
497
493
assert_eq ! ( resp. store_address, "store_addr" . to_string( ) ) ;
498
494
assert_eq ! ( resp. max_step, 123 ) ;
499
495
assert_eq ! ( resp. max_rank, Some ( 0 ) ) ;
@@ -525,7 +521,7 @@ mod tests {
525
521
let manager = Manager :: new (
526
522
format ! ( "rep_{}" , replica_id) ,
527
523
lighthouse_addr,
528
- "addr " . to_string ( ) ,
524
+ "localhost " . to_string ( ) ,
529
525
"[::]:0" . to_string ( ) ,
530
526
"store_addr" . to_string ( ) ,
531
527
1 , // world size
0 commit comments