Skip to content

Commit b0d5662

Browse files
authored
Fix rustdoc comments for turn (#487)
1 parent 4d96e5e commit b0d5662

32 files changed

+305
-302
lines changed

turn/src/allocation/allocation_manager.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use super::*;
1212
use crate::error::*;
1313
use crate::relay::*;
1414

15-
// ManagerConfig a bag of config params for Manager.
15+
/// `ManagerConfig` a bag of config params for `Manager`.
1616
pub struct ManagerConfig {
1717
pub relay_addr_generator: Box<dyn RelayAddressGenerator + Send + Sync>,
1818
pub alloc_close_notify: Option<mpsc::Sender<AllocationInfo>>,
1919
}
2020

21-
// Manager is used to hold active allocations
21+
/// `Manager` is used to hold active allocations.
2222
pub struct Manager {
2323
allocations: AllocationMap,
2424
reservations: Arc<Mutex<HashMap<String, u16>>>,
@@ -27,7 +27,7 @@ pub struct Manager {
2727
}
2828

2929
impl Manager {
30-
// creates a new instance of Manager.
30+
/// Creates a new [`Manager`].
3131
pub fn new(config: ManagerConfig) -> Self {
3232
Manager {
3333
allocations: Arc::new(Mutex::new(HashMap::new())),
@@ -37,7 +37,7 @@ impl Manager {
3737
}
3838
}
3939

40-
// Close closes the manager and closes all allocations it manages
40+
/// Closes this [`manager`] and closes all [`Allocation`]s it manages.
4141
pub async fn close(&self) -> Result<()> {
4242
let allocations = self.allocations.lock().await;
4343
for a in allocations.values() {
@@ -46,8 +46,8 @@ impl Manager {
4646
Ok(())
4747
}
4848

49-
// Returns the information about the all [`Allocation`]s associated with
50-
// the specified [`FiveTuple`]s.
49+
/// Returns the information about the all [`Allocation`]s associated with
50+
/// the specified [`FiveTuple`]s.
5151
pub async fn get_allocations_info(
5252
&self,
5353
five_tuples: Option<Vec<FiveTuple>>,
@@ -73,13 +73,13 @@ impl Manager {
7373
infos
7474
}
7575

76-
// get_allocation fetches the allocation matching the passed FiveTuple
76+
/// Fetches the [`Allocation`] matching the passed [`FiveTuple`].
7777
pub async fn get_allocation(&self, five_tuple: &FiveTuple) -> Option<Arc<Allocation>> {
7878
let allocations = self.allocations.lock().await;
7979
allocations.get(five_tuple).map(Arc::clone)
8080
}
8181

82-
// create_allocation creates a new allocation and starts relaying
82+
/// Creates a new [`Allocation`] and starts relaying.
8383
pub async fn create_allocation(
8484
&self,
8585
five_tuple: FiveTuple,
@@ -123,7 +123,7 @@ impl Manager {
123123
Ok(a)
124124
}
125125

126-
// delete_allocation removes an allocation
126+
/// Removes an [`Allocation`].
127127
pub async fn delete_allocation(&self, five_tuple: &FiveTuple) {
128128
let allocation = self.allocations.lock().await.remove(five_tuple);
129129

@@ -134,7 +134,7 @@ impl Manager {
134134
}
135135
}
136136

137-
/// Deletes the [`Allocation`]s according to the specified `username`.
137+
/// Deletes the [`Allocation`]s according to the specified username `name`.
138138
pub async fn delete_allocations_by_username(&self, name: &str) {
139139
let to_delete = {
140140
let mut allocations = self.allocations.lock().await;
@@ -163,7 +163,7 @@ impl Manager {
163163
.await;
164164
}
165165

166-
// create_reservation stores the reservation for the token+port
166+
/// Stores the reservation for the token+port.
167167
pub async fn create_reservation(&self, reservation_token: String, port: u16) {
168168
let reservations = Arc::clone(&self.reservations);
169169
let reservation_token2 = reservation_token.clone();
@@ -183,13 +183,13 @@ impl Manager {
183183
reservations.insert(reservation_token, port);
184184
}
185185

186-
// get_reservation returns the port for a given reservation if it exists
186+
/// Returns the port for a given reservation if it exists.
187187
pub async fn get_reservation(&self, reservation_token: &str) -> Option<u16> {
188188
let reservations = self.reservations.lock().await;
189189
reservations.get(reservation_token).copied()
190190
}
191191

192-
// get_random_even_port returns a random un-allocated udp4 port
192+
/// Returns a random un-allocated udp4 port.
193193
pub async fn get_random_even_port(&self) -> Result<u16> {
194194
let (_, addr) = self.relay_addr_generator.allocate_conn(true, 0).await?;
195195
Ok(addr.port())

turn/src/allocation/channel_bind.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use tokio::time::{Duration, Instant};
1010
use super::*;
1111
use crate::proto::channum::*;
1212

13-
// ChannelBind represents a TURN Channel
14-
// https://tools.ietf.org/html/rfc5766#section-2.5
13+
/// `ChannelBind` represents a TURN Channel.
14+
///
15+
/// https://tools.ietf.org/html/rfc5766#section-2.5.
1516
#[derive(Clone)]
1617
pub struct ChannelBind {
1718
pub(crate) peer: SocketAddr,
@@ -22,7 +23,7 @@ pub struct ChannelBind {
2223
}
2324

2425
impl ChannelBind {
25-
// NewChannelBind creates a new ChannelBind
26+
/// Creates a new [`ChannelBind`]
2627
pub fn new(number: ChannelNumber, peer: SocketAddr) -> Self {
2728
ChannelBind {
2829
number,

turn/src/allocation/five_tuple.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use std::net::{Ipv4Addr, SocketAddr};
66

77
use crate::proto::*;
88

9-
// FiveTuple is the combination (client IP address and port, server IP
10-
// address and port, and transport protocol (currently one of UDP,
11-
// TCP, or TLS)) used to communicate between the client and the
12-
// server. The 5-tuple uniquely identifies this communication
13-
// stream. The 5-tuple also uniquely identifies the Allocation on
14-
// the server.
9+
/// `FiveTuple` is the combination (client IP address and port, server IP
10+
/// address and port, and transport protocol (currently one of UDP,
11+
/// TCP, or TLS)) used to communicate between the client and the
12+
/// server. The 5-tuple uniquely identifies this communication
13+
/// stream. The 5-tuple also uniquely identifies the Allocation on
14+
/// the server.
1515
#[derive(PartialEq, Eq, Clone, Copy, Hash)]
1616
pub struct FiveTuple {
1717
pub protocol: Protocol,

turn/src/allocation/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct AllocationInfo {
5050
}
5151

5252
impl AllocationInfo {
53-
// Creates a new `AllocationInfo`
53+
/// Creates a new [`AllocationInfo`].
5454
pub fn new(
5555
five_tuple: FiveTuple,
5656
username: String,
@@ -65,8 +65,8 @@ impl AllocationInfo {
6565
}
6666
}
6767

68-
// Allocation is tied to a FiveTuple and relays traffic
69-
// use create_allocation and get_allocation to operate
68+
/// `Allocation` is tied to a FiveTuple and relays traffic
69+
/// use create_allocation and get_allocation to operate.
7070
pub struct Allocation {
7171
protocol: Protocol,
7272
turn_socket: Arc<dyn Conn + Send + Sync>,
@@ -90,7 +90,7 @@ fn addr2ipfingerprint(addr: &SocketAddr) -> String {
9090
}
9191

9292
impl Allocation {
93-
// creates a new instance of NewAllocation.
93+
/// Creates a new [`Allocation`].
9494
pub fn new(
9595
turn_socket: Arc<dyn Conn + Send + Sync>,
9696
relay_socket: Arc<dyn Conn + Send + Sync>,
@@ -118,13 +118,13 @@ impl Allocation {
118118
}
119119
}
120120

121-
// has_permission gets the Permission from the allocation
121+
/// Checks the Permission for the `addr`.
122122
pub async fn has_permission(&self, addr: &SocketAddr) -> bool {
123123
let permissions = self.permissions.lock().await;
124124
permissions.get(&addr2ipfingerprint(addr)).is_some()
125125
}
126126

127-
// add_permission adds a new permission to the allocation
127+
/// Adds a new [`Permission`] to this [`Allocation`].
128128
pub async fn add_permission(&self, mut p: Permission) {
129129
let fingerprint = addr2ipfingerprint(&p.addr);
130130

@@ -145,14 +145,14 @@ impl Allocation {
145145
}
146146
}
147147

148-
// remove_permission removes the net.Addr's fingerprint from the allocation's permissions
148+
/// Removes the `addr`'s fingerprint from this [`Allocation`]'s permissions.
149149
pub async fn remove_permission(&self, addr: &SocketAddr) -> bool {
150150
let mut permissions = self.permissions.lock().await;
151151
permissions.remove(&addr2ipfingerprint(addr)).is_some()
152152
}
153153

154-
// add_channel_bind adds a new ChannelBind to the allocation, it also updates the
155-
// permissions needed for this ChannelBind
154+
/// Adds a new [`ChannelBind`] to this [`Allocation`], it also updates the
155+
/// permissions needed for this [`ChannelBind`].
156156
pub async fn add_channel_bind(&self, mut c: ChannelBind, lifetime: Duration) -> Result<()> {
157157
{
158158
if let Some(addr) = self.get_channel_addr(&c.number).await {
@@ -197,19 +197,19 @@ impl Allocation {
197197
Ok(())
198198
}
199199

200-
// remove_channel_bind removes the ChannelBind from this allocation by id
200+
/// Removes the [`ChannelBind`] from this [`Allocation`] by `number`.
201201
pub async fn remove_channel_bind(&self, number: ChannelNumber) -> bool {
202202
let mut channel_bindings = self.channel_bindings.lock().await;
203203
channel_bindings.remove(&number).is_some()
204204
}
205205

206-
// get_channel_addr gets the ChannelBind's addr
206+
/// Gets the [`ChannelBind`]'s address by `number`.
207207
pub async fn get_channel_addr(&self, number: &ChannelNumber) -> Option<SocketAddr> {
208208
let channel_bindings = self.channel_bindings.lock().await;
209209
channel_bindings.get(number).map(|cb| cb.peer)
210210
}
211211

212-
// GetChannelByAddr gets the ChannelBind's number from this allocation by net.Addr
212+
/// Gets the [`ChannelBind`]'s number from this [`Allocation`] by `addr`.
213213
pub async fn get_channel_number(&self, addr: &SocketAddr) -> Option<ChannelNumber> {
214214
let channel_bindings = self.channel_bindings.lock().await;
215215
for cb in channel_bindings.values() {
@@ -220,7 +220,7 @@ impl Allocation {
220220
None
221221
}
222222

223-
// Close closes the allocation
223+
/// Closes the [`Allocation`].
224224
pub async fn close(&self) -> Result<()> {
225225
if self.closed.load(Ordering::Acquire) {
226226
return Err(Error::ErrClosed);
@@ -305,7 +305,7 @@ impl Allocation {
305305
reset_tx.is_none() || self.timer_expired.load(Ordering::SeqCst)
306306
}
307307

308-
// Refresh updates the allocations lifetime
308+
/// Updates the allocations lifetime.
309309
pub async fn refresh(&self, lifetime: Duration) {
310310
let reset_tx = self.reset_tx.lock().clone();
311311
if let Some(tx) = reset_tx {

turn/src/allocation/permission.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use super::*;
88

99
pub(crate) const PERMISSION_TIMEOUT: Duration = Duration::from_secs(5 * 60);
1010

11-
// Permission represents a TURN permission. TURN permissions mimic the address-restricted
12-
// filtering mechanism of NATs that comply with [RFC4787].
13-
// https://tools.ietf.org/html/rfc5766#section-2.3
11+
/// `Permission` represents a TURN permission. TURN permissions mimic the address-restricted
12+
/// filtering mechanism of NATs that comply with [RFC4787].
13+
///
14+
/// https://tools.ietf.org/html/rfc5766#section-2.3
1415
pub struct Permission {
1516
pub(crate) addr: SocketAddr,
1617
pub(crate) permissions: Option<Arc<Mutex<HashMap<String, Permission>>>>,
@@ -19,7 +20,7 @@ pub struct Permission {
1920
}
2021

2122
impl Permission {
22-
// NewPermission create a new Permission
23+
/// Creates a new [`Permission`].
2324
pub fn new(addr: SocketAddr) -> Self {
2425
Permission {
2526
addr,

turn/src/auth/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait AuthHandler {
1515
fn auth_handle(&self, username: &str, realm: &str, src_addr: SocketAddr) -> Result<Vec<u8>>;
1616
}
1717

18-
// generate_long_term_credentials can be used to create credentials valid for [duration] time
18+
/// `generate_long_term_credentials()` can be used to create credentials valid for `duration` time/
1919
pub fn generate_long_term_credentials(
2020
shared_secret: &str,
2121
duration: Duration,
@@ -35,7 +35,7 @@ fn long_term_credentials(username: &str, shared_secret: &str) -> String {
3535
BASE64_STANDARD.encode(password)
3636
}
3737

38-
// generate_auth_key is a convenience function to easily generate keys in the format used by AuthHandler
38+
/// A convenience function to easily generate keys in the format used by [`AuthHandler`].
3939
pub fn generate_auth_key(username: &str, realm: &str, password: &str) -> Vec<u8> {
4040
let s = format!("{username}:{realm}:{password}");
4141

@@ -70,7 +70,7 @@ impl AuthHandler for LongTermAuthHandler {
7070
}
7171

7272
impl LongTermAuthHandler {
73-
// https://tools.ietf.org/search/rfc5389#section-10.2
73+
/// https://tools.ietf.org/search/rfc5389#section-10.2
7474
pub fn new(shared_secret: String) -> Self {
7575
LongTermAuthHandler { shared_secret }
7676
}

turn/src/client/binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Binding {
4848
self.refreshed_at
4949
}
5050
}
51-
// Thread-safe Binding map
51+
/// Thread-safe Binding map.
5252
#[derive(Default)]
5353
pub(crate) struct BindingManager {
5454
chan_map: HashMap<u16, String>,

0 commit comments

Comments
 (0)