This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into txqueue-gc
Conflicts: ethcore/src/miner/miner.rs
- Loading branch information
Showing
203 changed files
with
4,500 additions
and
1,636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,18 @@ authors = ["Ethcore <[email protected]>"] | |
build = "build.rs" | ||
|
||
[build-dependencies] | ||
"ethcore-ipc-codegen" = { path = "../../ipc/codegen" } | ||
"ethcore-ipc-codegen" = { path = "../../ipc/codegen", optional = true } | ||
|
||
[dependencies] | ||
log = "0.3" | ||
ethcore = { path = ".." } | ||
ethcore = { path = ".."} | ||
ethcore-util = { path = "../../util" } | ||
ethcore-network = { path = "../../util/network" } | ||
ethcore-io = { path = "../../util/io" } | ||
ethcore-ipc = { path = "../../ipc/rpc" } | ||
ethcore-ipc = { path = "../../ipc/rpc", optional = true } | ||
rlp = { path = "../../util/rlp" } | ||
time = "0.1" | ||
time = "0.1" | ||
|
||
[features] | ||
default = [] | ||
ipc = ["ethcore-ipc", "ethcore-ipc-codegen"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright 2015, 2016 Ethcore (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! I/O and event context generalizations. | ||
use network::{NetworkContext, PeerId}; | ||
|
||
use super::{Announcement, LightProtocol, ReqId}; | ||
use super::error::Error; | ||
use request::Request; | ||
|
||
/// An I/O context which allows sending and receiving packets as well as | ||
/// disconnecting peers. This is used as a generalization of the portions | ||
/// of a p2p network which the light protocol structure makes use of. | ||
pub trait IoContext { | ||
/// Send a packet to a specific peer. | ||
fn send(&self, peer: PeerId, packet_id: u8, packet_body: Vec<u8>); | ||
|
||
/// Respond to a peer's message. Only works if this context is a byproduct | ||
/// of a packet handler. | ||
fn respond(&self, packet_id: u8, packet_body: Vec<u8>); | ||
|
||
/// Disconnect a peer. | ||
fn disconnect_peer(&self, peer: PeerId); | ||
|
||
/// Disable a peer -- this is a disconnect + a time-out. | ||
fn disable_peer(&self, peer: PeerId); | ||
|
||
/// Get a peer's protocol version. | ||
fn protocol_version(&self, peer: PeerId) -> Option<u8>; | ||
} | ||
|
||
impl<'a> IoContext for NetworkContext<'a> { | ||
fn send(&self, peer: PeerId, packet_id: u8, packet_body: Vec<u8>) { | ||
if let Err(e) = self.send(peer, packet_id, packet_body) { | ||
debug!(target: "les", "Error sending packet to peer {}: {}", peer, e); | ||
} | ||
} | ||
|
||
fn respond(&self, packet_id: u8, packet_body: Vec<u8>) { | ||
if let Err(e) = self.respond(packet_id, packet_body) { | ||
debug!(target: "les", "Error responding to peer message: {}", e); | ||
} | ||
} | ||
|
||
fn disconnect_peer(&self, peer: PeerId) { | ||
NetworkContext::disconnect_peer(self, peer); | ||
} | ||
|
||
fn disable_peer(&self, peer: PeerId) { | ||
NetworkContext::disable_peer(self, peer); | ||
} | ||
|
||
fn protocol_version(&self, peer: PeerId) -> Option<u8> { | ||
self.protocol_version(self.subprotocol_name(), peer) | ||
} | ||
} | ||
|
||
/// Context for a protocol event. | ||
pub trait EventContext { | ||
/// Get the peer relevant to the event e.g. message sender, | ||
/// disconnected/connected peer. | ||
fn peer(&self) -> PeerId; | ||
|
||
/// Make a request from a peer. | ||
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error>; | ||
|
||
/// Make an announcement of new capabilities to the rest of the peers. | ||
// TODO: maybe just put this on a timer in LightProtocol? | ||
fn make_announcement(&self, announcement: Announcement); | ||
|
||
/// Disconnect a peer. | ||
fn disconnect_peer(&self, peer: PeerId); | ||
|
||
/// Disable a peer. | ||
fn disable_peer(&self, peer: PeerId); | ||
} | ||
|
||
/// Concrete implementation of `EventContext` over the light protocol struct and | ||
/// an io context. | ||
pub struct Ctx<'a> { | ||
/// Io context to enable immediate response to events. | ||
pub io: &'a IoContext, | ||
/// Protocol implementation. | ||
pub proto: &'a LightProtocol, | ||
/// Relevant peer for event. | ||
pub peer: PeerId, | ||
} | ||
|
||
impl<'a> EventContext for Ctx<'a> { | ||
fn peer(&self) -> PeerId { self.peer } | ||
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error> { | ||
self.proto.request_from(self.io, &peer, request) | ||
} | ||
|
||
fn make_announcement(&self, announcement: Announcement) { | ||
self.proto.make_announcement(self.io, announcement); | ||
} | ||
|
||
fn disconnect_peer(&self, peer: PeerId) { | ||
self.io.disconnect_peer(peer); | ||
} | ||
|
||
fn disable_peer(&self, peer: PeerId) { | ||
self.io.disable_peer(peer); | ||
} | ||
} |
Oops, something went wrong.