pub struct StreamEvent {
pub id: StreamId,
pub status: StreamStatus,
pub circuit_id: Option<CircuitId>,
pub target_host: String,
pub target_port: u16,
pub reason: Option<StreamClosureReason>,
pub remote_reason: Option<StreamClosureReason>,
pub source: Option<StreamSource>,
pub source_addr: Option<String>,
pub purpose: Option<StreamPurpose>,
/* private fields */
}Expand description
Event indicating that a stream’s status has changed.
Stream events track the lifecycle of TCP connections made through Tor. Each stream is associated with a circuit and connects to a specific target host and port.
§Stream Lifecycle
Streams progress through these states:
StreamStatus::New- New stream request receivedStreamStatus::SentConnect- CONNECT sent to exit relayStreamStatus::Remap- Address remapped (e.g., DNS resolution)StreamStatus::Succeeded- Connection establishedStreamStatus::ClosedorStreamStatus::Failed- Stream terminated
§Circuit Association
The circuit_id field indicates which circuit carries this stream.
A value of None (circuit ID “0”) means the stream is not yet
attached to a circuit.
§Example
use stem_rs::events::StreamEvent;
use stem_rs::StreamStatus;
fn handle_stream(event: &StreamEvent) {
match event.status {
StreamStatus::New => {
println!("New stream {} to {}:{}",
event.id, event.target_host, event.target_port);
}
StreamStatus::Succeeded => {
println!("Stream {} connected via circuit {:?}",
event.id, event.circuit_id);
}
StreamStatus::Closed | StreamStatus::Failed => {
println!("Stream {} ended: {:?}", event.id, event.reason);
}
_ => {}
}
}§See Also
StreamStatus- Stream status valuesStreamPurpose- Stream purpose typesStreamClosureReason- Closure reasons
Fields§
§id: StreamIdUnique identifier for this stream.
status: StreamStatusCurrent status of the stream.
circuit_id: Option<CircuitId>Circuit carrying this stream, or None if unattached.
target_host: StringTarget hostname or IP address.
target_port: u16Target port number.
reason: Option<StreamClosureReason>Reason for stream closure (local).
remote_reason: Option<StreamClosureReason>Reason for stream closure (from remote side).
source: Option<StreamSource>Source of address resolution (cache or exit).
source_addr: Option<String>Source address of the client connection.
purpose: Option<StreamPurpose>Purpose of this stream.
Implementations§
Source§impl StreamEvent
impl StreamEvent
Sourcepub fn parse(content: &str) -> Result<Self, Error>
pub fn parse(content: &str) -> Result<Self, Error>
Parses a stream event from raw control protocol content.
§Arguments
content- The event content after the event type
§Event Format
StreamID StreamStatus CircuitID Target [REASON=...] [REMOTE_REASON=...]
[SOURCE=...] [SOURCE_ADDR=...] [PURPOSE=...]§Errors
Returns Error::Protocol if:
- Required fields are missing
- The status is not a recognized value
- The target format is invalid
Trait Implementations§
Source§impl Clone for StreamEvent
impl Clone for StreamEvent
Source§fn clone(&self) -> StreamEvent
fn clone(&self) -> StreamEvent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more