@@ -9,19 +9,30 @@ use ts_tunnel::NodeKeyPair;
99
1010use crate :: { EventResult , InboundResult , OutboundResult } ;
1111
12- /// Queue for packets leaving the data plane "up" into an overlay transport.
13- pub type DataplaneToOverlay = mpsc:: UnboundedSender < Vec < PacketMut > > ;
14-
15- /// Queue for packets entering the data plane "down" from an overlay transport.
16- pub type DataplaneFromOverlay = mpsc:: UnboundedReceiver < Vec < PacketMut > > ;
17-
18- /// Queue for packets leaving the data plane "down" into an underlay transport.
19- pub type DataplaneToUnderlay = mpsc:: UnboundedSender < ( PeerId , Vec < PacketMut > ) > ;
20-
21- /// Queue for packets entering the data plane "up" from an underlay transport.
22- pub type DataplaneFromUnderlay = mpsc:: UnboundedReceiver < ( PeerId , Vec < PacketMut > ) > ;
23-
24- // TODO: wire in overlay/underlay transport traits
12+ // NOTE(npry): this used to have unique types for each queue, but the names got confusing due to
13+ // having to think about the cartesian product of PacketType x QueueDirection x Network
14+ // (this is a "sender handle for receive packets on the overlay", vs. "receive handle for sender
15+ // packets on the overlay", etc.). It wasn't always clear to distinguish what referred to the
16+ // channel direction (sender/receiver) and what referred to the actual traffic kind (packets
17+ // received _from_ the underlay are different from packets sent _to_ the underlay). So now we name
18+ // the packet type here (to/from overlay/underlay) and use separate helper types to make the channel
19+ // directions easier to name.
20+
21+ /// Packet batches sent to an overlay.
22+ pub type ToOverlay = Vec < PacketMut > ;
23+ /// Packet batches received from an overlay.
24+ pub type FromOverlay = Vec < PacketMut > ;
25+
26+ /// Packet batches sent to an underlay.
27+ pub type ToUnderlay = ( PeerId , Vec < PacketMut > ) ;
28+ /// Packet batches received from an underlay.
29+ pub type FromUnderlay = Vec < PacketMut > ;
30+
31+ /// Shorthand for a sender channel.
32+ pub type Tx < T > = mpsc:: UnboundedSender < T > ;
33+
34+ /// Shorthand for a receiver channel.
35+ pub type Rx < T > = mpsc:: UnboundedReceiver < T > ;
2536
2637/// Transforms packets to make tailscale happen.
2738pub struct DataPlane {
@@ -30,8 +41,10 @@ pub struct DataPlane {
3041
3142 transports_changed : tokio:: sync:: Notify ,
3243
33- underlay_down : DataplaneToUnderlay ,
34- overlay_up : DataplaneToOverlay ,
44+ // These are the senders handed out in new_*_transport, just held here so we can clone them, we
45+ // never send to them.
46+ underlay_down : Tx < FromUnderlay > ,
47+ overlay_up : Tx < FromOverlay > ,
3548
3649 next_underlay_transport : AtomicU32 ,
3750 next_overlay_transport : AtomicU32 ,
@@ -42,17 +55,17 @@ struct CoreState {
4255 sync : crate :: DataPlane ,
4356
4457 /// Queues to write packets to overlay transports.
45- overlay_transports : HashMap < OverlayTransportId , DataplaneToOverlay > ,
58+ overlay_transports : HashMap < OverlayTransportId , Tx < ToOverlay > > ,
4659 /// Queues to write packets to underlay transports.
47- underlay_transports : HashMap < UnderlayTransportId , DataplaneToUnderlay > ,
60+ underlay_transports : HashMap < UnderlayTransportId , Tx < ToUnderlay > > ,
4861}
4962
5063/// State that must be held during async polling.
5164struct PollState {
5265 /// Queue for packets entering the data plane ("coming down") from overlay transports.
53- from_overlay : DataplaneFromOverlay ,
66+ from_overlay : Rx < FromOverlay > ,
5467 /// Queue for packets entering the data plane ("coming up") from underlay transports.
55- from_underlay : DataplaneFromUnderlay ,
68+ from_underlay : Rx < FromUnderlay > ,
5669}
5770
5871impl DataPlane {
@@ -91,11 +104,7 @@ impl DataPlane {
91104 /// Allocate a new underlay transport.
92105 pub async fn new_underlay_transport (
93106 & self ,
94- ) -> (
95- UnderlayTransportId ,
96- DataplaneFromUnderlay ,
97- DataplaneToUnderlay ,
98- ) {
107+ ) -> ( UnderlayTransportId , Rx < ToUnderlay > , Tx < FromUnderlay > ) {
99108 let id = self
100109 . next_underlay_transport
101110 . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed )
@@ -116,7 +125,7 @@ impl DataPlane {
116125 /// Allocate a new overlay transport.
117126 pub async fn new_overlay_transport (
118127 & self ,
119- ) -> ( OverlayTransportId , DataplaneToOverlay , DataplaneFromOverlay ) {
128+ ) -> ( OverlayTransportId , Tx < FromOverlay > , Rx < ToOverlay > ) {
120129 let id = self
121130 . next_overlay_transport
122131 . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed )
@@ -146,7 +155,7 @@ impl DataPlane {
146155 pub async fn step ( & self ) {
147156 enum SelectResult {
148157 OverlayDown ( Vec < PacketMut > ) ,
149- UnderlayUp ( PeerId , Vec < PacketMut > ) ,
158+ UnderlayUp ( Vec < PacketMut > ) ,
150159 TransportsChanged ,
151160 Event ,
152161 }
@@ -185,10 +194,10 @@ impl DataPlane {
185194 }
186195
187196 underlay_pkts = underlay_up. recv( ) => {
188- let ( peer_id , underlay_pkts) = underlay_pkts. unwrap( ) ;
189- tracing:: trace!( %peer_id , n_underlay_pkts = underlay_pkts. len( ) ) ;
197+ let underlay_pkts = underlay_pkts. unwrap( ) ;
198+ tracing:: trace!( n_underlay_pkts = underlay_pkts. len( ) ) ;
190199
191- SelectResult :: UnderlayUp ( peer_id , underlay_pkts)
200+ SelectResult :: UnderlayUp ( underlay_pkts)
192201 }
193202
194203 _ = self . transports_changed. notified( ) => {
@@ -214,7 +223,7 @@ impl DataPlane {
214223
215224 ( Some ( to_peers) , Some ( loopback) )
216225 }
217- SelectResult :: UnderlayUp ( _peer_id , underlay_up) => {
226+ SelectResult :: UnderlayUp ( underlay_up) => {
218227 let InboundResult { to_local, to_peers } = core. sync . process_inbound ( underlay_up) ;
219228
220229 ( Some ( to_peers) , Some ( to_local) )
0 commit comments