Skip to content

Commit 12d4ed6

Browse files
committed
docs(stream): fix some docs
1 parent aaea259 commit 12d4ed6

File tree

5 files changed

+46
-20
lines changed

5 files changed

+46
-20
lines changed

crates/interledger-stream/src/client.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const MAX_TIME_SINCE_LAST_FULFILL: Duration = Duration::from_secs(30);
2828
pub struct StreamDelivery {
2929
/// The sender's ILP Address
3030
pub from: Address,
31-
/// The receivers ILP Address
31+
/// The receiver's ILP Address
3232
pub to: Address,
3333
// StreamDelivery variables which we know ahead of time
3434
/// The amount sent by the sender
@@ -113,6 +113,8 @@ where
113113
last_fulfill_time: Instant::now(),
114114
};
115115

116+
// Fires off STREAM packets until the congestion controller tells us to stop
117+
// or we've sent the total amount or maximum time since last fulfill has elapsed
116118
loop {
117119
if let Some(error) = sender.error.take() {
118120
error!("Send money stopped because of error: {:?}", error);
@@ -175,21 +177,26 @@ struct SendMoneyFuture<S: IncomingService<A>, A: Account> {
175177
destination_account: Address,
176178
/// The shared secret generated by the sender and the receiver
177179
shared_secret: Bytes,
178-
/// The amount sent by the sender
180+
/// The amount (in the sender's units) remaining to be sent by the sender,
181+
/// excluding the in-flight amount
179182
source_amount: u64,
180-
/// The [congestion controller](./../congestion/struct.CongestionController.html) for this stream
183+
/// The [congestion controller](./../congestion/struct.CongestionController.html) for this stream, which is used to send bigger or smaller amounts inside the packets as the stream gets processed
181184
congestion_controller: CongestionController,
182185
/// The [StreamDelivery](./struct.StreamDelivery.html) receipt of this stream
183186
receipt: StreamDelivery,
184187
/// Boolean indicating if the source account should also be sent to the receiver
185188
should_send_source_account: bool,
186-
/// The sequence number of this stream
189+
/// The sequence number of this stream, which is also used for tracking the number of fulfilled packets
187190
sequence: u64,
188-
/// The amount of rejected packets by the stream
191+
/// Number of packets rejected throughout the stream
189192
rejected_packets: u64,
190193
/// The STREAM error for this stream
191194
error: Option<Error>,
192195
/// The last time a packet was fulfilled for this stream.
196+
// TOOD: Seems weird that this is set initially to Instant::now()
197+
// even though no packets have been fulfilled yet. Maybe make it an Option
198+
// which starts as None, and set it to Some(Instant::now()) when we receive the first
199+
// fulfill?
193200
last_fulfill_time: Instant,
194201
}
195202

@@ -199,8 +206,7 @@ where
199206
A: Account,
200207
{
201208
#[inline]
202-
/// Fires off STREAM inside Prepare packets until the congestion controller tells us to stop
203-
/// or we've sent the total amount or maximum time since last fulfill has elapsed
209+
/// Fires off 1 STREAM-inside-Prepare packet
204210
async fn try_send_money(&mut self) -> Result<(), Error> {
205211
let amount = min(
206212
self.source_amount,
@@ -313,8 +319,8 @@ where
313319
/// Parses the provided Fulfill packet.
314320
/// 1. Logs the fulfill in the congestion controller
315321
/// 1. Updates the last fulfill time of the send money future
316-
/// 1. It tries to aprse a Stream Packet inside the fulfill packet's data field
317-
/// If successful, it icnrements the delivered amount by the Stream packet's prepare amount
322+
/// 1. It tries to parse a Stream Packet inside the fulfill packet's data field
323+
/// If successful, it increments the delivered amount by the Stream packet's prepare amount
318324
fn handle_fulfill(&mut self, sequence: u64, amount: u64, fulfill: Fulfill) {
319325
// TODO should we check the fulfillment and expiry or can we assume the plugin does that?
320326
self.congestion_controller.fulfill(amount);

crates/interledger-stream/src/congestion.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ use std::io;
1717
/// control algorithms.
1818
pub struct CongestionController {
1919
state: CongestionState,
20+
/// Amount which is added to `max_in_flight` per fulfill
2021
increase_amount: u64,
22+
/// Divide `max_in_flight` by this factor per reject with code for insufficient liquidity
23+
/// or if there is no `max_packet_amount` specified
2124
decrease_factor: f64,
25+
/// The maximum amount we are allowed to add in a packet. This gets automatically set if
26+
/// we receive a reject packet with a `F08_AMOUNT_TOO_LARGE` error
2227
max_packet_amount: Option<u64>,
28+
/// The current amount in flight
2329
amount_in_flight: u64,
30+
/// The maximum allowed amount to be in flight
2431
max_in_flight: u64,
32+
/// Writer object to write our metrics to a csv
2533
#[cfg(feature = "metrics_csv")]
2634
csv_writer: csv::Writer<io::Stdout>,
2735
}
@@ -33,6 +41,7 @@ enum CongestionState {
3341
}
3442

3543
impl CongestionController {
44+
/// Constructs a new congestion controller
3645
pub fn new(start_amount: u64, increase_amount: u64, decrease_factor: f64) -> Self {
3746
#[cfg(feature = "metrics_csv")]
3847
let mut csv_writer = csv::Writer::from_writer(io::stdout());
@@ -53,6 +62,7 @@ impl CongestionController {
5362
}
5463
}
5564

65+
/// The maximum amount which can be sent is the maximum amount in flight minus the current amount in flight
5666
pub fn get_max_amount(&mut self) -> u64 {
5767
if self.amount_in_flight > self.max_in_flight {
5868
return 0;
@@ -66,6 +76,7 @@ impl CongestionController {
6676
}
6777
}
6878

79+
/// Increments the amount in flight by the provided amount
6980
pub fn prepare(&mut self, amount: u64) {
7081
if amount > 0 {
7182
self.amount_in_flight += amount;
@@ -76,6 +87,8 @@ impl CongestionController {
7687
}
7788
}
7889

90+
/// Decrements the amount in flight by the provided amount
91+
/// Increases the allowed max in flight amount cap
7992
pub fn fulfill(&mut self, prepare_amount: u64) {
8093
self.amount_in_flight -= prepare_amount;
8194

@@ -111,6 +124,8 @@ impl CongestionController {
111124
self.log_stats(prepare_amount);
112125
}
113126

127+
/// Decrements the amount in flight by the provided amount
128+
/// Decreases the allowed max in flight amount cap
114129
pub fn reject(&mut self, prepare_amount: u64, reject: &Reject) {
115130
self.amount_in_flight -= prepare_amount;
116131

crates/interledger-stream/src/crypto.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ fn encrypt_with_nonce(
133133
/// The nonce and auth tag are extracted from the first 12 and 16 bytes
134134
/// of the ciphertext.
135135
pub fn decrypt(shared_secret: &[u8], mut ciphertext: BytesMut) -> Result<BytesMut, ()> {
136-
println!("Got ciphertext with length {:?}", ciphertext.len());
137136
// ciphertext must include at least a nonce and tag,
138137
if ciphertext.len() < AUTH_TAG_LENGTH {
139138
return Err(());

crates/interledger-stream/src/packet.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub struct StreamPacketBuilder<'a> {
1919
pub sequence: u64,
2020
/// The [ILP Packet Type](../interledger_packet/enum.PacketType.html)
2121
pub ilp_packet_type: IlpPacketType,
22-
/// The amount inside the stream packet
22+
/// Destination amount of the ILP Prepare, used for enforcing minimum exchange rates and congestion control.
23+
/// Within an ILP Prepare, represents the minimum amount the recipient needs to receive in order to fulfill the packet.
24+
/// Within an ILP Fulfill or ILP Reject, represents the amount received by the recipient.
2325
pub prepare_amount: u64,
2426
/// The stream frames
2527
pub frames: &'a [Frame<'a>],
@@ -121,7 +123,9 @@ pub struct StreamPacket {
121123
sequence: u64,
122124
/// The [ILP Packet Type](../interledger_packet/enum.PacketType.html)
123125
ilp_packet_type: IlpPacketType,
124-
/// The amount inside the stream packet
126+
/// Destination amount of the ILP Prepare, used for enforcing minimum exchange rates and congestion control.
127+
/// Within an ILP Prepare, represents the minimum amount the recipient needs to receive in order to fulfill the packet.
128+
/// Within an ILP Fulfill or ILP Reject, represents the amount received by the recipient.
125129
prepare_amount: u64,
126130
/// The offset after which frames can be found inside the `buffer_unencrypted` field
127131
frames_offset: usize,
@@ -132,19 +136,21 @@ impl StreamPacket {
132136
/// and a shared secret
133137
///
134138
/// # Errors
139+
/// 1. If the version of the Stream Protocol does not match
135140
/// 1. If the decryption fails
136-
/// 1. If the decrypted bytes cannot be parsed to a unencrypted [Stream Packet](./struct.StreamPacket.html)
141+
/// 1. If the decrypted bytes cannot be parsed to an unencrypted [Stream Packet](./struct.StreamPacket.html)
137142
pub fn from_encrypted(shared_secret: &[u8], ciphertext: BytesMut) -> Result<Self, ParseError> {
138143
// TODO handle decryption failure
139144
let decrypted = decrypt(shared_secret, ciphertext)
140145
.map_err(|_err| ParseError::InvalidPacket(String::from("Unable to decrypt packet")))?;
141146
StreamPacket::from_bytes_unencrypted(decrypted)
142147
}
143148

144-
/// Constructs a [Stream Packet](./struct.StreamPacket.html) from an buffer
149+
/// Constructs a [Stream Packet](./struct.StreamPacket.html) from a buffer
145150
///
146151
/// # Errors
147-
/// 1. If the decrypted bytes cannot be parsed to a unencrypted [Stream Packet](./struct.StreamPacket.html)
152+
/// 1. If the version of the Stream Protocol does not match
153+
/// 1. If the decrypted bytes cannot be parsed to an unencrypted [Stream Packet](./struct.StreamPacket.html)
148154
fn from_bytes_unencrypted(buffer_unencrypted: BytesMut) -> Result<Self, ParseError> {
149155
// TODO don't copy the whole packet again
150156
let mut reader = &buffer_unencrypted[..];
@@ -200,7 +206,7 @@ impl StreamPacket {
200206
self.ilp_packet_type
201207
}
202208

203-
/// The packet's prepare amount
209+
/// Destination amount of the ILP Prepare, used for enforcing minimum exchange rates and congestion control.
204210
pub fn prepare_amount(&self) -> u64 {
205211
self.prepare_amount
206212
}

crates/interledger-stream/src/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ impl ConnectionGenerator {
8585
}
8686
}
8787

88-
/// A payment notification data type to be used by Pubsub API consumers
88+
/// Notification that STREAM fulfilled a packet and received a single Interledger payment, used by Pubsub API consumers
8989
#[derive(Debug, Deserialize, Serialize)]
9090
pub struct PaymentNotification {
91-
/// The username of the receiver of the payment notification
91+
/// The username of the account that received the Interledger payment
9292
pub to_username: Username,
93-
/// The username of the sender of the payment notification
93+
/// The username of the account that routed the Interledger payment to this node
9494
pub from_username: Username,
9595
/// The ILP Address of the receiver of the payment notification
9696
pub destination: Address,
9797
/// The amount received
9898
pub amount: u64,
99-
/// The time this payment notification was fired
99+
/// The time this payment notification was fired in RFC3339 format
100100
pub timestamp: String,
101101
}
102102

0 commit comments

Comments
 (0)