Much work
This commit is contained in:
		
							
								
								
									
										72
									
								
								src/proto/state.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								src/proto/state.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| use ConnectionError; | ||||
|  | ||||
| /// Represents the state of an H2 stream | ||||
| /// | ||||
| /// ```not_rust | ||||
| ///                              +--------+ | ||||
| ///                      send PP |        | recv PP | ||||
| ///                     ,--------|  idle  |--------. | ||||
| ///                    /         |        |         \ | ||||
| ///                   v          +--------+          v | ||||
| ///            +----------+          |           +----------+ | ||||
| ///            |          |          | send H /  |          | | ||||
| ///     ,------| reserved |          | recv H    | reserved |------. | ||||
| ///     |      | (local)  |          |           | (remote) |      | | ||||
| ///     |      +----------+          v           +----------+      | | ||||
| ///     |          |             +--------+             |          | | ||||
| ///     |          |     recv ES |        | send ES     |          | | ||||
| ///     |   send H |     ,-------|  open  |-------.     | recv H   | | ||||
| ///     |          |    /        |        |        \    |          | | ||||
| ///     |          v   v         +--------+         v   v          | | ||||
| ///     |      +----------+          |           +----------+      | | ||||
| ///     |      |   half   |          |           |   half   |      | | ||||
| ///     |      |  closed  |          | send R /  |  closed  |      | | ||||
| ///     |      | (remote) |          | recv R    | (local)  |      | | ||||
| ///     |      +----------+          |           +----------+      | | ||||
| ///     |           |                |                 |           | | ||||
| ///     |           | send ES /      |       recv ES / |           | | ||||
| ///     |           | send R /       v        send R / |           | | ||||
| ///     |           | recv R     +--------+   recv R   |           | | ||||
| ///     | send R /  `----------->|        |<-----------'  send R / | | ||||
| ///     | recv R                 | closed |               recv R   | | ||||
| ///     `----------------------->|        |<----------------------' | ||||
| ///                              +--------+ | ||||
| /// | ||||
| ///        send:   endpoint sends this frame | ||||
| ///        recv:   endpoint receives this frame | ||||
| /// | ||||
| ///        H:  HEADERS frame (with implied CONTINUATIONs) | ||||
| ///        PP: PUSH_PROMISE frame (with implied CONTINUATIONs) | ||||
| ///        ES: END_STREAM flag | ||||
| ///        R:  RST_STREAM frame | ||||
| /// ``` | ||||
| #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||||
| pub enum State { | ||||
|     Idle, | ||||
|     ReservedLocal, | ||||
|     ReservedRemote, | ||||
|     Open, | ||||
|     HalfClosedLocal, | ||||
|     HalfClosedRemote, | ||||
|     Closed, | ||||
| } | ||||
|  | ||||
| impl State { | ||||
|     /// Transition the state to represent headers being sent. | ||||
|     /// | ||||
|     /// Returns an error if this is an invalid state transition. | ||||
|     pub fn send_headers(&mut self) -> Result<(), ConnectionError> { | ||||
|         if *self != State::Idle { | ||||
|             unimplemented!(); | ||||
|         } | ||||
|  | ||||
|         *self = State::Open; | ||||
|         Ok(()) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Default for State { | ||||
|     fn default() -> State { | ||||
|         State::Idle | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user