1
1
use corro_types:: {
2
+ agent:: { Agent , Bookie } ,
2
3
broadcast:: { BroadcastV1 , ChangeSource , ChangeV1 , UniPayload , UniPayloadV1 } ,
3
4
channel:: CorroSender ,
4
5
} ;
@@ -12,15 +13,22 @@ use tripwire::Tripwire;
12
13
/// Spawn a task that accepts unidirectional broadcast streams, then
13
14
/// spawns another task for each incoming stream to handle.
14
15
pub fn spawn_unipayload_handler (
16
+ agent : & Agent ,
17
+ bookie : & Bookie ,
15
18
tripwire : & Tripwire ,
16
19
conn : & quinn:: Connection ,
17
20
changes_tx : CorroSender < ( ChangeV1 , ChangeSource ) > ,
18
21
) {
22
+ let agent = agent. clone ( ) ;
23
+ let bookie = bookie. clone ( ) ;
19
24
tokio:: spawn ( {
20
25
let conn = conn. clone ( ) ;
21
26
let mut tripwire = tripwire. clone ( ) ;
27
+
22
28
async move {
23
29
loop {
30
+ let agent = agent. clone ( ) ;
31
+ let bookie = bookie. clone ( ) ;
24
32
let rx = tokio:: select! {
25
33
rx_res = conn. accept_uni( ) => match rx_res {
26
34
Ok ( rx) => rx,
@@ -48,6 +56,9 @@ pub fn spawn_unipayload_handler(
48
56
let mut framed = FramedRead :: new ( rx, LengthDelimitedCodec :: new ( ) ) ;
49
57
50
58
loop {
59
+ let agent = agent. clone ( ) ;
60
+ let bookie = bookie. clone ( ) ;
61
+
51
62
match StreamExt :: next ( & mut framed) . await {
52
63
Some ( Ok ( b) ) => {
53
64
counter ! ( "corro.peer.stream.bytes.recv.total" , "type" => "uni" )
@@ -70,6 +81,23 @@ pub fn spawn_unipayload_handler(
70
81
return ;
71
82
}
72
83
}
84
+ UniPayload :: V1 (
85
+ UniPayloadV1 :: PriorityBroadcast (
86
+ BroadcastV1 :: Change ( change) ,
87
+ ) ,
88
+ ) => {
89
+ // fixme: queue with priority?
90
+ tokio:: spawn ( async move {
91
+ crate :: change:: process_priority_change (
92
+ agent,
93
+ bookie,
94
+ change,
95
+ ChangeSource :: PriorityBroadcast ,
96
+ )
97
+ . await
98
+ . unwrap ( ) ;
99
+ } ) ;
100
+ }
73
101
}
74
102
}
75
103
Err ( e) => {
0 commit comments