@@ -27,7 +27,7 @@ use up_rust::{
27
27
RESOURCE_ID_SUBSCRIBE , RESOURCE_ID_UNSUBSCRIBE , USUBSCRIPTION_TYPE_ID ,
28
28
USUBSCRIPTION_VERSION_MAJOR ,
29
29
} ,
30
- UCode , UPriority , UStatus , UUri , UUID ,
30
+ UCode , UPriority , UStatus , UUri ,
31
31
} ;
32
32
33
33
use crate :: { helpers, usubscription:: UP_REMOTE_TTL } ;
@@ -148,22 +148,21 @@ pub(crate) async fn handle_message(
148
148
respond_to,
149
149
} => {
150
150
// Add new subscriber to topic subscription tracker (create new entries as necessary)
151
- topic_subscribers
151
+ let is_new = topic_subscribers
152
152
. entry ( topic. clone ( ) )
153
153
. or_default ( )
154
154
. insert ( subscriber) ;
155
155
156
- // This really should unwrap() ok, as we just inserted an entry above
157
- let subscribers_count =
158
- topic_subscribers. get ( & topic) . map ( |e| e. len ( ) ) . unwrap_or ( 0 ) ;
159
-
160
156
let mut state = TopicState :: SUBSCRIBED ; // everything in topic_subscribers is considered SUBSCRIBED by default
161
157
162
158
if topic. is_remote_authority ( & own_uri) {
163
- state = TopicState :: SUBSCRIBE_PENDING ; // for remote_topics, we explicitly track state due to the _PENDING scenarios
164
- remote_topics. entry ( topic. clone ( ) ) . or_insert ( state) ;
159
+ // for remote_topics, we explicitly track state due to the _PENDING scenarios
160
+ state = * remote_topics
161
+ . get ( & topic)
162
+ . unwrap_or ( & TopicState :: SUBSCRIBE_PENDING ) ;
165
163
166
- if subscribers_count == 1 {
164
+ remote_topics. entry ( topic. clone ( ) ) . or_insert ( state) ;
165
+ if is_new {
167
166
// this is the first subscriber to this (remote) topic, so perform remote subscription
168
167
let own_uri_clone = own_uri. clone ( ) ;
169
168
let up_client_clone = up_client. clone ( ) ;
@@ -454,12 +453,7 @@ async fn remote_subscribe(
454
453
let subscription_response: SubscriptionResponse = up_client
455
454
. invoke_proto_method (
456
455
make_remote_subscribe_uuri ( & subscription_request. topic ) ,
457
- CallOptions :: for_rpc_request (
458
- UP_REMOTE_TTL ,
459
- Some ( UUID :: new ( ) ) ,
460
- None ,
461
- Some ( UPriority :: UPRIORITY_CS2 ) ,
462
- ) ,
456
+ CallOptions :: for_rpc_request ( UP_REMOTE_TTL , None , None , Some ( UPriority :: UPRIORITY_CS4 ) ) ,
463
457
subscription_request,
464
458
)
465
459
. await
@@ -507,12 +501,7 @@ async fn remote_unsubscribe(
507
501
let unsubscribe_response: UStatus = up_client
508
502
. invoke_proto_method (
509
503
make_remote_unsubscribe_uuri ( & unsubscribe_request. topic ) ,
510
- CallOptions :: for_rpc_request (
511
- UP_REMOTE_TTL ,
512
- Some ( UUID :: new ( ) ) ,
513
- None ,
514
- Some ( UPriority :: UPRIORITY_CS2 ) ,
515
- ) ,
504
+ CallOptions :: for_rpc_request ( UP_REMOTE_TTL , None , None , Some ( UPriority :: UPRIORITY_CS4 ) ) ,
516
505
unsubscribe_request,
517
506
)
518
507
. await
@@ -612,13 +601,8 @@ mod tests {
612
601
let expected_topic = test_lib:: helpers:: remote_topic1_uri ( ) ;
613
602
let expected_method = make_remote_subscribe_uuri ( & expected_topic) ;
614
603
let expected_subscriber = test_lib:: helpers:: local_usubscription_service_uri ( ) ;
615
-
616
- let expected_options = CallOptions :: for_rpc_request (
617
- UP_REMOTE_TTL ,
618
- Some ( UUID :: new ( ) ) ,
619
- None ,
620
- Some ( UPriority :: UPRIORITY_CS2 ) ,
621
- ) ;
604
+ let expected_options =
605
+ CallOptions :: for_rpc_request ( UP_REMOTE_TTL , None , None , Some ( UPriority :: UPRIORITY_CS4 ) ) ;
622
606
let expected_request = SubscriptionRequest {
623
607
topic : Some ( expected_topic. clone ( ) ) . into ( ) ,
624
608
subscriber : Some ( SubscriberInfo {
@@ -675,12 +659,8 @@ mod tests {
675
659
let expected_method = make_remote_unsubscribe_uuri ( & expected_topic) ;
676
660
let expected_subscriber = test_lib:: helpers:: local_usubscription_service_uri ( ) ;
677
661
678
- let expected_options = CallOptions :: for_rpc_request (
679
- UP_REMOTE_TTL ,
680
- Some ( UUID :: new ( ) ) ,
681
- None ,
682
- Some ( UPriority :: UPRIORITY_CS2 ) ,
683
- ) ;
662
+ let expected_options =
663
+ CallOptions :: for_rpc_request ( UP_REMOTE_TTL , None , None , Some ( UPriority :: UPRIORITY_CS4 ) ) ;
684
664
let expected_request = UnsubscribeRequest {
685
665
topic : Some ( expected_topic. clone ( ) ) . into ( ) ,
686
666
subscriber : Some ( SubscriberInfo {
@@ -732,6 +712,7 @@ mod tests {
732
712
resource_id : RESOURCE_ID_SUBSCRIBE as u32 ,
733
713
..Default :: default ( )
734
714
} ;
715
+
735
716
let remote_method = make_remote_subscribe_uuri ( & test_lib:: helpers:: remote_topic1_uri ( ) ) ;
736
717
737
718
assert_eq ! ( expected_uri, remote_method) ;
0 commit comments