Change ProtocolId to U64. yolo3x spec (#271)
* Change ProtocolId to U64 and make it support variable subprotocol names* * Add yolo3x testnet
This commit is contained in:
@@ -95,7 +95,7 @@ pub struct CapabilityInfo {
|
||||
impl Encodable for CapabilityInfo {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.begin_list(2);
|
||||
s.append(&&self.protocol[..]);
|
||||
s.append(&self.protocol.as_u64());
|
||||
s.append(&self.version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,27 +21,29 @@
|
||||
//! ```rust
|
||||
//! extern crate ethcore_network as net;
|
||||
//! extern crate ethcore_network_devp2p as devp2p;
|
||||
//! extern crate ethereum_types as types;
|
||||
//! use net::*;
|
||||
//! use devp2p::NetworkService;
|
||||
//! use std::sync::Arc;
|
||||
//! use std::time::Duration;
|
||||
//! use types::U64;
|
||||
//!
|
||||
//! struct MyHandler;
|
||||
//!
|
||||
//! impl NetworkProtocolHandler for MyHandler {
|
||||
//! fn initialize(&self, io: &NetworkContext) {
|
||||
//! fn initialize(&self, io: &dyn NetworkContext) {
|
||||
//! io.register_timer(0, Duration::from_secs(1));
|
||||
//! }
|
||||
//!
|
||||
//! fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
|
||||
//! fn read(&self, io: &dyn NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
|
||||
//! println!("Received {} ({} bytes) from {}", packet_id, data.len(), peer);
|
||||
//! }
|
||||
//!
|
||||
//! fn connected(&self, io: &NetworkContext, peer: &PeerId) {
|
||||
//! fn connected(&self, io: &dyn NetworkContext, peer: &PeerId) {
|
||||
//! println!("Connected {}", peer);
|
||||
//! }
|
||||
//!
|
||||
//! fn disconnected(&self, io: &NetworkContext, peer: &PeerId) {
|
||||
//! fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId) {
|
||||
//! println!("Disconnected {}", peer);
|
||||
//! }
|
||||
//! }
|
||||
@@ -49,7 +51,7 @@
|
||||
//! fn main () {
|
||||
//! let mut service = NetworkService::new(NetworkConfiguration::new_local(), None).expect("Error creating network service");
|
||||
//! service.start().expect("Error starting service");
|
||||
//! service.register_protocol(Arc::new(MyHandler), *b"myp", &[(1u8, 1u8)]);
|
||||
//! service.register_protocol(Arc::new(MyHandler), U64::from(0x000aaa00), &[(1u8, 1u8)]);
|
||||
//!
|
||||
//! // Wait for quit condition
|
||||
//! // ...
|
||||
|
||||
@@ -87,7 +87,7 @@ pub enum SessionData {
|
||||
/// Packet data
|
||||
data: Vec<u8>,
|
||||
/// Packet protocol ID
|
||||
protocol: [u8; 3],
|
||||
protocol: ProtocolId,
|
||||
/// Zero based packet ID
|
||||
packet_id: u8,
|
||||
},
|
||||
@@ -255,7 +255,7 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Checks if peer supports given capability
|
||||
pub fn have_capability(&self, protocol: [u8; 3]) -> bool {
|
||||
pub fn have_capability(&self, protocol: ProtocolId) -> bool {
|
||||
self.info
|
||||
.capabilities
|
||||
.iter()
|
||||
@@ -263,7 +263,7 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Checks if peer supports given capability
|
||||
pub fn capability_version(&self, protocol: [u8; 3]) -> Option<u8> {
|
||||
pub fn capability_version(&self, protocol: ProtocolId) -> Option<u8> {
|
||||
self.info
|
||||
.capabilities
|
||||
.iter()
|
||||
@@ -313,7 +313,7 @@ impl Session {
|
||||
pub fn send_packet<Message>(
|
||||
&mut self,
|
||||
io: &IoContext<Message>,
|
||||
protocol: Option<[u8; 3]>,
|
||||
protocol: Option<ProtocolId>,
|
||||
packet_id: u8,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error>
|
||||
@@ -321,7 +321,7 @@ impl Session {
|
||||
Message: Send + Sync + Clone,
|
||||
{
|
||||
if protocol.is_some() && (self.info.capabilities.is_empty() || !self.had_hello) {
|
||||
debug!(target: "network", "Sending to unconfirmed session {}, protocol: {:?}, packet: {}", self.token(), protocol.as_ref().map(|p| str::from_utf8(&p[..]).unwrap_or("??")), packet_id);
|
||||
debug!(target: "network", "Sending to unconfirmed session {}, protocol: {:?}, packet: {}", self.token(), protocol.map(|p| str::from_utf8(&p.as_u64().to_ne_bytes()).unwrap_or("??").to_string()), packet_id);
|
||||
bail!(ErrorKind::BadProtocol);
|
||||
}
|
||||
if self.expired() {
|
||||
|
||||
Reference in New Issue
Block a user