pub trait Handler {
    fn handle(
        &self,
        local: SocketAddr,
        remote: SocketAddr,
        packet: Packet<'_>
    ) -> Option<Packet<'_>> { ... } fn handle_rrq(
        &self,
        _local: SocketAddr,
        _remote: SocketAddr,
        _filename: Filename,
        _txmode: TransferMode,
        _options: Options
    ) -> Option<Packet<'_>> { ... } fn handle_wrq(
        &self,
        _local: SocketAddr,
        _remote: SocketAddr,
        _filename: Filename,
        _txmode: TransferMode,
        _options: Options
    ) -> Option<Packet<'_>> { ... } fn handle_other(
        &self,
        _local: SocketAddr,
        _remote: SocketAddr,
        _packet: Packet<'_>
    ) -> Option<Packet<'_>> { ... } }
Expand description

A TFTP handler to which requests are passed once they’ve been parsed. A handler can choose to ignore, reject (with an error), or serve each request that comes in.

Provided Methods

Handle a new, well-formed, TFTP request.

The default implementation calls handle_rrq for a read request and handle_wrq for a write request, and handle_other for everything else.

In case of an error, this can return a Packet representing the error to be sent to the other side. For example:

Some(packet::Packet::Error(
    packet::ErrorCode::AccessViolation,
    packet::ErrorMessage("read not supported".to_owned()),
));

Use this when the error occurs prior the commencing the transfer; once the transfer has begin, send errors via the channel created for the transfer.

Handle a read request (RRQ).

By default this is rejected as an access violation. Implementors can define something more interesting.

Handle a write request (WRQ).

By default this is rejected as an access violation. Implementors can define something more interesting.

Handle all other requests.

By default these are completely ignored. The TFTP specs do not define request types other than RRQ and WRQ so this might be a misdirected or corrupted packet. Implementors may want to log this.

Implementors