Skip to content

Commit

Permalink
rationalise qlog streamer API naming
Browse files Browse the repository at this point in the history
  • Loading branch information
LPardue committed Mar 20, 2020
1 parent 8e8362b commit 26dc338
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ impl Connection {
writer,
);

streamer.write_start().ok();
streamer.start_log().ok();

let ev = self.peer_transport_params.to_qlog(
qlog::TransportOwner::Local,
Expand All @@ -1206,7 +1206,7 @@ impl Connection {
self.handshake.cipher(),
);

streamer.write_event(ev).ok();
streamer.add_event(ev).ok();

self.qlog_streamer = Some(streamer);
}
Expand Down Expand Up @@ -1568,7 +1568,7 @@ impl Connection {
Some(&hdr.dcid),
);

q.write_event(Event::packet_received(
q.add_event(Event::packet_received(
hdr.ty.to_qlog(),
qlog_pkt_hdr,
Some(Vec::new()),
Expand Down Expand Up @@ -1599,7 +1599,7 @@ impl Connection {
let frame = frame::Frame::from_bytes(&mut payload, hdr.ty)?;

qlog_with!(self.qlog_streamer, q, {
q.write_frame(frame.to_qlog(), false).ok();
q.add_frame(frame.to_qlog(), false).ok();
});

if frame.ack_eliciting() {
Expand Down Expand Up @@ -1631,7 +1631,7 @@ impl Connection {
);

if let Some(qlog_streamer) = self.qlog_streamer.as_mut() {
qlog_streamer.write_event(ev).unwrap();
qlog_streamer.add_event(ev).unwrap();
}

self.qlogged_peer_params = true;
Expand Down Expand Up @@ -2244,7 +2244,7 @@ impl Connection {
Some(Vec::new()),
);

q.write_event(packet_sent_ev).ok();
q.add_event(packet_sent_ev).ok();
});

// Encode frames into the output packet.
Expand All @@ -2254,7 +2254,7 @@ impl Connection {
frame.to_bytes(&mut b)?;

qlog_with!(self.qlog_streamer, q, {
q.write_frame(frame.to_qlog(), false).ok();
q.add_frame(frame.to_qlog(), false).ok();
});
}

Expand Down Expand Up @@ -2299,7 +2299,7 @@ impl Connection {

qlog_with!(self.qlog_streamer, q, {
let ev = self.recovery.to_qlog();
q.write_event(ev).ok();
q.add_event(ev).ok();
});

self.pkt_num_spaces[epoch].next_pkt_num += 1;
Expand Down Expand Up @@ -2714,7 +2714,7 @@ impl Connection {
trace!("{} draining timeout expired", self.trace_id);

qlog_with!(self.qlog_streamer, q, {
q.log_finish().ok();
q.finish_log().ok();
});

self.closed = true;
Expand All @@ -2731,7 +2731,7 @@ impl Connection {
trace!("{} idle timeout expired", self.trace_id);

qlog_with!(self.qlog_streamer, q, {
q.log_finish().ok();
q.finish_log().ok();
});

self.closed = true;
Expand All @@ -2751,7 +2751,7 @@ impl Connection {

qlog_with!(self.qlog_streamer, q, {
let ev = self.recovery.to_qlog();
q.write_event(ev).ok();
q.add_event(ev).ok();
});

return;
Expand Down Expand Up @@ -3014,7 +3014,7 @@ impl Connection {

qlog_with!(self.qlog_streamer, q, {
let ev = self.recovery.to_qlog();
q.write_event(ev).ok();
q.add_event(ev).ok();
});

// When we receive an ACK for a 1-RTT packet after handshake
Expand Down
32 changes: 16 additions & 16 deletions tools/qlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ pub enum StreamerState {
/// `Trace`.
///
/// Serialization is progressively driven by method calls; once log streaming is
/// started, `event::Events` can be written using `write_event()`. Some events
/// started, `event::Events` can be written using `add_event()`. Some events
/// can contain an array of `QuicFrame`s, when writing such an event, the
/// streamer enters a frame-serialization mode where frames are be progressively
/// written using `write_frame()`. This mode is concluded using
/// written using `add_frame()`. This mode is concluded using
/// `finished_frames()`. While serializing frames, any attempts to log
/// additional events are ignored.
///
Expand Down Expand Up @@ -367,7 +367,7 @@ impl QlogStreamer {
/// This writes out the JSON-serialized form of all information up to qlog
/// `Trace`'s array of `EventField`s. EventFields are separately appended
/// using functions that accept and `event::Event`.
pub fn write_start(&mut self) -> Result<()> {
pub fn start_log(&mut self) -> Result<()> {
if self.state != StreamerState::Initial {
return Err(Error::Done);
}
Expand Down Expand Up @@ -397,7 +397,7 @@ impl QlogStreamer {
///
/// The JSON-serialized output has remaining close delimiters added.
/// After this is called, no more serialization will occur.
pub fn log_finish(&mut self) -> Result<()> {
pub fn finish_log(&mut self) -> Result<()> {
if self.state == StreamerState::Initial ||
self.state == StreamerState::Finished
{
Expand All @@ -421,7 +421,7 @@ impl QlogStreamer {
/// events are ignored.
///
/// If the event contains no array of `QuicFrames` return `false`.
pub fn write_event(&mut self, event: event::Event) -> Result<bool> {
pub fn add_event(&mut self, event: event::Event) -> Result<bool> {
if self.state != StreamerState::Ready {
return Err(Error::InvalidState);
}
Expand Down Expand Up @@ -497,7 +497,7 @@ impl QlogStreamer {
/// Writes a JSON-serialized `QuicFrame`.
///
/// Only valid while in the frame-serialization mode.
pub fn write_frame(&mut self, frame: QuicFrame, last: bool) -> Result<()> {
pub fn add_frame(&mut self, frame: QuicFrame, last: bool) -> Result<()> {
if self.state != StreamerState::WritingFrames {
return Err(Error::InvalidState);
}
Expand Down Expand Up @@ -2579,29 +2579,29 @@ mod tests {
);

// Before the log is started all other operations should fail.
assert!(match s.write_event(event2.clone()) {
assert!(match s.add_event(event2.clone()) {
Err(Error::InvalidState) => true,
_ => false,
});
assert!(match s.write_frame(frame2.clone(), false) {
assert!(match s.add_frame(frame2.clone(), false) {
Err(Error::InvalidState) => true,
_ => false,
});
assert!(match s.finish_frames() {
Err(Error::InvalidState) => true,
_ => false,
});
assert!(match s.log_finish() {
assert!(match s.finish_log() {
Err(Error::InvalidState) => true,
_ => false,
});

// Once a log is started, can't write frames before an event.
assert!(match s.write_start() {
assert!(match s.start_log() {
Ok(()) => true,
_ => false,
});
assert!(match s.write_frame(frame2.clone(), true) {
assert!(match s.add_frame(frame2.clone(), true) {
Err(Error::InvalidState) => true,
_ => false,
});
Expand All @@ -2612,21 +2612,21 @@ mod tests {

// Some events hold frames, can't write any more events until frame
// writing is concluded.
assert!(match s.write_event(event2.clone()) {
assert!(match s.add_event(event2.clone()) {
Ok(true) => true,
_ => false,
});
assert!(match s.write_event(event2.clone()) {
assert!(match s.add_event(event2.clone()) {
Err(Error::InvalidState) => true,
_ => false,
});

// While writing frames, can't write events.
assert!(match s.write_frame(frame2.clone(), false) {
assert!(match s.add_frame(frame2.clone(), false) {
Ok(()) => true,
_ => false,
});
assert!(match s.write_event(event2.clone()) {
assert!(match s.add_event(event2.clone()) {
Err(Error::InvalidState) => true,
_ => false,
});
Expand All @@ -2636,7 +2636,7 @@ mod tests {
Ok(()) => true,
_ => false,
});
assert!(match s.log_finish() {
assert!(match s.finish_log() {
Ok(()) => true,
_ => false,
});
Expand Down

0 comments on commit 26dc338

Please sign in to comment.