Returning persistent node id
This commit is contained in:
parent
e66157f922
commit
aaf6da4c00
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//! I/O and event context generalizations.
|
//! I/O and event context generalizations.
|
||||||
|
|
||||||
use network::{NetworkContext, PeerId};
|
use network::{NetworkContext, PeerId, NodeId};
|
||||||
|
|
||||||
use super::{Announcement, LightProtocol, ReqId};
|
use super::{Announcement, LightProtocol, ReqId};
|
||||||
use super::error::Error;
|
use super::error::Error;
|
||||||
@ -41,6 +41,9 @@ pub trait IoContext {
|
|||||||
|
|
||||||
/// Get a peer's protocol version.
|
/// Get a peer's protocol version.
|
||||||
fn protocol_version(&self, peer: PeerId) -> Option<u8>;
|
fn protocol_version(&self, peer: PeerId) -> Option<u8>;
|
||||||
|
|
||||||
|
/// Persistent peer id
|
||||||
|
fn persistent_peer_id(&self, peer: PeerId) -> Option<NodeId>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IoContext for NetworkContext<'a> {
|
impl<'a> IoContext for NetworkContext<'a> {
|
||||||
@ -67,6 +70,10 @@ impl<'a> IoContext for NetworkContext<'a> {
|
|||||||
fn protocol_version(&self, peer: PeerId) -> Option<u8> {
|
fn protocol_version(&self, peer: PeerId) -> Option<u8> {
|
||||||
self.protocol_version(self.subprotocol_name(), peer)
|
self.protocol_version(self.subprotocol_name(), peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn persistent_peer_id(&self, peer: PeerId) -> Option<NodeId> {
|
||||||
|
self.session_info(peer).and_then(|info| info.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Context for a protocol event.
|
/// Context for a protocol event.
|
||||||
@ -75,6 +82,9 @@ pub trait EventContext {
|
|||||||
/// disconnected/connected peer.
|
/// disconnected/connected peer.
|
||||||
fn peer(&self) -> PeerId;
|
fn peer(&self) -> PeerId;
|
||||||
|
|
||||||
|
/// Returns the relevant's peer persistent Id (aka NodeId).
|
||||||
|
fn persistent_peer_id(&self) -> Option<NodeId>;
|
||||||
|
|
||||||
/// Make a request from a peer.
|
/// Make a request from a peer.
|
||||||
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error>;
|
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error>;
|
||||||
|
|
||||||
@ -101,7 +111,14 @@ pub struct Ctx<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> EventContext for Ctx<'a> {
|
impl<'a> EventContext for Ctx<'a> {
|
||||||
fn peer(&self) -> PeerId { self.peer }
|
|
||||||
|
fn peer(&self) -> PeerId {
|
||||||
|
self.peer
|
||||||
|
}
|
||||||
|
|
||||||
|
fn persistent_peer_id(&self) -> Option<NodeId> {
|
||||||
|
self.io.persistent_peer_id(self.peer)
|
||||||
|
}
|
||||||
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error> {
|
fn request_from(&self, peer: PeerId, request: Request) -> Result<ReqId, Error> {
|
||||||
self.proto.request_from(self.io, &peer, request)
|
self.proto.request_from(self.io, &peer, request)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ use ethcore::blockchain_info::BlockChainInfo;
|
|||||||
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient};
|
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient};
|
||||||
use ethcore::ids::BlockId;
|
use ethcore::ids::BlockId;
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
use network::PeerId;
|
use network::{PeerId, NodeId};
|
||||||
|
|
||||||
use net::buffer_flow::FlowParams;
|
use net::buffer_flow::FlowParams;
|
||||||
use net::context::IoContext;
|
use net::context::IoContext;
|
||||||
@ -68,6 +68,10 @@ impl IoContext for Expect {
|
|||||||
fn protocol_version(&self, _peer: PeerId) -> Option<u8> {
|
fn protocol_version(&self, _peer: PeerId) -> Option<u8> {
|
||||||
Some(super::MAX_PROTOCOL_VERSION)
|
Some(super::MAX_PROTOCOL_VERSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn persistent_peer_id(&self, _peer: PeerId) -> Option<NodeId> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// can't implement directly for Arc due to cross-crate orphan rules.
|
// can't implement directly for Arc due to cross-crate orphan rules.
|
||||||
|
@ -351,8 +351,7 @@ struct TxRelay(Arc<BlockChainClient>);
|
|||||||
impl LightHandler for TxRelay {
|
impl LightHandler for TxRelay {
|
||||||
fn on_transactions(&self, ctx: &EventContext, relay: &[::ethcore::transaction::SignedTransaction]) {
|
fn on_transactions(&self, ctx: &EventContext, relay: &[::ethcore::transaction::SignedTransaction]) {
|
||||||
trace!(target: "les", "Relaying {} transactions from peer {}", relay.len(), ctx.peer());
|
trace!(target: "les", "Relaying {} transactions from peer {}", relay.len(), ctx.peer());
|
||||||
// TODO [ToDr] Can we get a peer enode somehow?
|
self.0.queue_transactions(relay.iter().map(|tx| ::rlp::encode(tx).to_vec()).collect(), ctx.persistent_peer_id())
|
||||||
self.0.queue_transactions(relay.iter().map(|tx| ::rlp::encode(tx).to_vec()).collect(), None)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ pub use stats::NetworkStats;
|
|||||||
pub use session::SessionInfo;
|
pub use session::SessionInfo;
|
||||||
|
|
||||||
use io::TimerToken;
|
use io::TimerToken;
|
||||||
pub use node_table::is_valid_node_url;
|
pub use node_table::{is_valid_node_url, NodeId};
|
||||||
|
|
||||||
const PROTOCOL_VERSION: u32 = 4;
|
const PROTOCOL_VERSION: u32 = 4;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user