@@ -337,9 +337,15 @@ impl ProxyState {
337337 id : & str ,
338338 app_id : & str ,
339339 public_key : & str ,
340- ) -> Option < InstanceInfo > {
341- if id. is_empty ( ) || public_key. is_empty ( ) || app_id. is_empty ( ) {
342- return None ;
340+ ) -> Result < InstanceInfo > {
341+ if id. is_empty ( ) {
342+ bail ! ( "instance_id is empty (no_instance_id is set?)" ) ;
343+ }
344+ if app_id. is_empty ( ) {
345+ bail ! ( "app_id is empty" ) ;
346+ }
347+ if public_key. is_empty ( ) {
348+ bail ! ( "public_key is empty" ) ;
343349 }
344350 if let Some ( existing) = self . state . instances . get_mut ( id) {
345351 if existing. public_key != public_key {
@@ -348,12 +354,14 @@ impl ProxyState {
348354 }
349355 let existing = existing. clone ( ) ;
350356 if self . valid_ip ( existing. ip ) {
351- return Some ( existing) ;
357+ return Ok ( existing) ;
352358 }
353359 info ! ( "ip {} is invalid, removing" , existing. ip) ;
354360 self . state . allocated_addresses . remove ( & existing. ip ) ;
355361 }
356- let ip = self . alloc_ip ( ) ?;
362+ let ip = self
363+ . alloc_ip ( )
364+ . context ( "IP pool exhausted, no available addresses in client_ip_range" ) ?;
357365 let host_info = InstanceInfo {
358366 id : id. to_string ( ) ,
359367 app_id : app_id. to_string ( ) ,
@@ -364,7 +372,7 @@ impl ProxyState {
364372 connections : Default :: default ( ) ,
365373 } ;
366374 self . add_instance ( host_info. clone ( ) ) ;
367- Some ( host_info)
375+ Ok ( host_info)
368376 }
369377
370378 fn add_instance ( & mut self , info : InstanceInfo ) {
@@ -755,7 +763,7 @@ impl GatewayRpc for RpcHandler {
755763 }
756764 let client_info = state
757765 . new_client_by_id ( & instance_id, & app_id, & request. client_public_key )
758- . context ( "failed to allocate IP address for client" ) ?;
766+ . context ( "failed to register client" ) ?;
759767 if let Err ( err) = state. reconfigure ( ) {
760768 error ! ( "failed to reconfigure: {}" , err) ;
761769 }
0 commit comments