# Trait ethcore_light::net::Handler [−] [src]

    pub trait Handler: Send + Sync {
        fn on_connect(&self,
                  _ctx: &EventContext,
                  _status: &Status,
                  _capabilities: &Capabilities) { ... }
        fn on_disconnect(&self, _ctx: &EventContext, _unfulfilled: &[ReqId]) { ... }
        fn on_announcement(&self, _ctx: &EventContext, _announcement: &Announcement) { ... }
        fn on_transactions(&self, _ctx: &EventContext, _relay: &[UnverifiedTransaction]) { ... }
        fn on_block_bodies(&self,
                       _ctx: &EventContext,
                       _req_id: ReqId,
                       _bodies: &[Bytes]) { ... }
        fn on_block_headers(&self,
                        _ctx: &EventContext,
                        _req_id: ReqId,
                        _headers: &[Bytes]) { ... }
        fn on_receipts(&self,
                   _ctx: &EventContext,
                   _req_id: ReqId,
                   _receipts: &[Vec<Receipt>]) { ... }
        fn on_state_proofs(&self,
                       _ctx: &EventContext,
                       _req_id: ReqId,
                       _proofs: &[Vec<Bytes>]) { ... }
        fn on_code(&self, _ctx: &EventContext, _req_id: ReqId, _codes: &[Bytes]) { ... }
        fn on_header_proofs(&self,
                        _ctx: &EventContext,
                        _req_id: ReqId,
                        _proofs: &[(Bytes, Vec<Bytes>)]) { ... }
        fn tick(&self, _ctx: &BasicContext) { ... }
        fn on_abort(&self) { ... }
    }

An LES event handler.

Each handler function takes a context which describes the relevant peer and gives references to the IO layer and protocol structure so new messages can be dispatched immediately.

Request responses are not guaranteed to be complete or valid, but passed IDs will be correct. Response handlers are not given a copy of the original request; it is assumed that relevant data will be stored by interested handlers.

## Provided Methods

### `fn on_connect(&self,
_ctx: &EventContext,
_status: &Status,
_capabilities: &Capabilities)`

Called when a peer connects.

### `fn on_disconnect(&self, _ctx: &EventContext, _unfulfilled: &[ReqId])`

Called when a peer disconnects, with a list of unfulfilled request IDs as of yet.

### `fn on_announcement(&self, _ctx: &EventContext, _announcement: &Announcement)`

Called when a peer makes an announcement.

### `fn on_transactions(&self, _ctx: &EventContext, _relay: &[UnverifiedTransaction])`

Called when a peer requests relay of some transactions.

### `fn on_block_bodies(&self,
_ctx: &EventContext,
_req_id: ReqId,
_bodies: &[Bytes])`

Called when a peer responds with block bodies.

### `fn on_block_headers(&self,
_ctx: &EventContext,
_req_id: ReqId,
_headers: &[Bytes])`

Called when a peer responds with block headers.

### `fn on_receipts(&self,
_ctx: &EventContext,
_req_id: ReqId,
_receipts: &[Vec<Receipt>])`

Called when a peer responds with block receipts.

### `fn on_state_proofs(&self,
_ctx: &EventContext,
_req_id: ReqId,
_proofs: &[Vec<Bytes>])`

Called when a peer responds with state proofs. Each proof should be a series of trie nodes in ascending order by distance from the root.

### `fn on_code(&self, _ctx: &EventContext, _req_id: ReqId, _codes: &[Bytes])`

Called when a peer responds with contract code.

### `fn on_header_proofs(&self,
_ctx: &EventContext,
_req_id: ReqId,
_proofs: &[(Bytes, Vec<Bytes>)])`

Called when a peer responds with header proofs. Each proof should be a block header coupled with a series of trie nodes is ascending order by distance from the root.

### `fn tick(&self, _ctx: &BasicContext)`

Called to "tick" the handler periodically.

### `fn on_abort(&self)`

Called on abort. This signals to handlers that they should clean up and ignore peers.

## Implementors

- `impl Handler for OnDemand`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)