Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
95th committed Jul 31, 2020
1 parent 1180199 commit ba0e6d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
27 changes: 15 additions & 12 deletions utp/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,20 @@ macro_rules! make_setter {

#[derive(PartialEq, Eq, Debug)]
pub enum PacketType {
Data, // packet carries a data payload
Fin, // signals the end of a connection
State, // signals acknowledgment of a packet
Reset, // forcibly terminates a connection
Syn, // initiates a new connection with a peer
/// packet carries a data payload
Data,

/// signals the end of a connection
Fin,

/// signals acknowledgment of a packet
State,

/// forcibly terminates a connection
Reset,

/// initiates a new connection with a peer
Syn,
}

impl TryFrom<u8> for PacketType {
Expand All @@ -58,13 +67,7 @@ impl TryFrom<u8> for PacketType {

impl From<PacketType> for u8 {
fn from(original: PacketType) -> u8 {
match original {
PacketType::Data => 0,
PacketType::Fin => 1,
PacketType::State => 2,
PacketType::Reset => 3,
PacketType::Syn => 4,
}
original as u8
}
}

Expand Down
19 changes: 9 additions & 10 deletions utp/src/socket.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::error::SocketError;
use crate::packet::*;
use crate::time::*;
use crate::util::*;
use std::cmp::{max, min};
use std::collections::VecDeque;
use std::convert::TryFrom;
use std::io::Result;
use std::net::SocketAddr;
use std::time::{Duration, Instant};
use crate::{error::SocketError, packet::*, time::*, util::*};
use std::{
cmp::{max, min},
collections::VecDeque,
convert::TryFrom,
io::Result,
net::SocketAddr,
time::{Duration, Instant},
};
use tokio::net::{ToSocketAddrs, UdpSocket};

// For simplicity's sake, let us assume no packet will ever exceed the
Expand Down
3 changes: 1 addition & 2 deletions utp/src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::socket::UtpSocket;
use std::io::Result;
use std::net::SocketAddr;
use std::{io::Result, net::SocketAddr};
use tokio::net::ToSocketAddrs;

/// A structure that represents a uTP (Micro Transport Protocol) stream between a local socket and a
Expand Down

0 comments on commit ba0e6d0

Please sign in to comment.