# Struct ethcore_light::net::LightProtocol [−] [src]

    pub struct LightProtocol { /* fields omitted */ }

This is an implementation of the light ethereum network protocol, abstracted over a `Provider` of data and a p2p network.

This is simply designed for request-response purposes. Higher level uses of the protocol, such as synchronization, will function as wrappers around this system.

## Methods

### `impl LightProtocol`
[src]

#### `fn new(provider: Arc<Provider>, params: Params) -> Self`

Create a new instance of the protocol manager.

#### `fn peer_status(&self, peer: &PeerId) -> Option<Status>`

Attempt to get peer status.

#### `fn request_from(&self,
io: &IoContext,
peer_id: &PeerId,
request: Request)
-> Result<ReqId, Error>`

Make a request to a peer.

Fails on: nonexistent peer, network error, peer not server, insufficient buffer. Does not check capabilities before sending. On success, returns a request id which can later be coordinated with an event.

#### `fn make_announcement(&self, io: &IoContext, announcement: Announcement)`

Make an announcement of new chain head and capabilities to all peers. The announcement is expected to be valid.

#### `fn add_handler(&mut self, handler: Arc<Handler>)`

Add an event handler.

These are intended to be added when the protocol structure is initialized as a means of customizing its behavior, and dispatching requests immediately upon events.

#### `fn abort(&self)`

Signal to handlers that network activity is being aborted and clear peer data.

#### `fn handle_packet(&self,
io: &IoContext,
peer: &PeerId,
packet_id: u8,
data: &[u8])`

Handle an LES packet using the given io context. Packet data is untrusted, which means that invalid data won't lead to issues.

#### `fn on_connect(&self, peer: &PeerId, io: &IoContext)`

called when a peer connects.

#### `fn on_disconnect(&self, peer: PeerId, io: &IoContext)`

called when a peer disconnects.

#### `fn with_context<F, T>(&self, io: &IoContext, f: F) -> T where F: FnOnce(&BasicContext) -> T`

Execute the given closure with a basic context derived from the I/O context.

## Trait Implementations

### `impl NetworkProtocolHandler for LightProtocol`
[src]

#### `fn initialize(&self, io: &NetworkContext)`

Initialize the handler

#### `fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8])`

Called when new network packet received.

#### `fn connected(&self, io: &NetworkContext, peer: &PeerId)`

Called when new peer is connected. Only called when peer supports the same protocol.

#### `fn disconnected(&self, io: &NetworkContext, peer: &PeerId)`

Called when a previously connected peer disconnects.

#### `fn timeout(&self, io: &NetworkContext, timer: TimerToken)`

Timer function called after a timeout created with `NetworkContext::timeout`.

# 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`)