mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
p2p: fix for changes in core serialization API
This commit is contained in:
parent
630c4eb6fb
commit
565374bac7
2 changed files with 31 additions and 39 deletions
|
@ -51,7 +51,7 @@ impl Handshake {
|
||||||
// send the first part of the handshake
|
// send the first part of the handshake
|
||||||
let sender_addr = conn.local_addr().unwrap();
|
let sender_addr = conn.local_addr().unwrap();
|
||||||
let receiver_addr = conn.peer_addr().unwrap();
|
let receiver_addr = conn.peer_addr().unwrap();
|
||||||
let opt_err = serialize(&mut conn,
|
try!(serialize(&mut conn,
|
||||||
&Hand {
|
&Hand {
|
||||||
version: PROTOCOL_VERSION,
|
version: PROTOCOL_VERSION,
|
||||||
capabilities: FULL_SYNC,
|
capabilities: FULL_SYNC,
|
||||||
|
@ -59,11 +59,7 @@ impl Handshake {
|
||||||
sender_addr: SockAddr(sender_addr),
|
sender_addr: SockAddr(sender_addr),
|
||||||
receiver_addr: SockAddr(receiver_addr),
|
receiver_addr: SockAddr(receiver_addr),
|
||||||
user_agent: USER_AGENT.to_string(),
|
user_agent: USER_AGENT.to_string(),
|
||||||
});
|
}));
|
||||||
match opt_err {
|
|
||||||
Some(err) => return Err(err),
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// deserialize the handshake response and do version negotiation
|
// deserialize the handshake response and do version negotiation
|
||||||
let shake = try!(deserialize::<Shake>(&mut conn));
|
let shake = try!(deserialize::<Shake>(&mut conn));
|
||||||
|
@ -127,16 +123,12 @@ impl Handshake {
|
||||||
};
|
};
|
||||||
|
|
||||||
// send our reply with our info
|
// send our reply with our info
|
||||||
let opt_err = serialize(&mut conn,
|
try!(serialize(&mut conn,
|
||||||
&Shake {
|
&Shake {
|
||||||
version: PROTOCOL_VERSION,
|
version: PROTOCOL_VERSION,
|
||||||
capabilities: FULL_SYNC,
|
capabilities: FULL_SYNC,
|
||||||
user_agent: USER_AGENT.to_string(),
|
user_agent: USER_AGENT.to_string(),
|
||||||
});
|
}));
|
||||||
match opt_err {
|
|
||||||
Some(err) => return Err(err),
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Received connection from peer {:?}", peer_info);
|
info!("Received connection from peer {:?}", peer_info);
|
||||||
// when more than one protocol version is supported, choosing should go here
|
// when more than one protocol version is supported, choosing should go here
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::net::*;
|
||||||
|
|
||||||
use num::FromPrimitive;
|
use num::FromPrimitive;
|
||||||
|
|
||||||
use core::ser::{self, Writeable, Readable, Writer, Reader, Error};
|
use core::ser::{self, Writeable, Readable, Writer, Reader};
|
||||||
|
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
|
@ -72,12 +72,12 @@ impl MsgHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writeable for MsgHeader {
|
impl Writeable for MsgHeader {
|
||||||
fn write(&self, writer: &mut Writer) -> Option<ser::Error> {
|
fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> {
|
||||||
ser_multiwrite!(writer,
|
ser_multiwrite!(writer,
|
||||||
[write_u8, self.magic[0]],
|
[write_u8, self.magic[0]],
|
||||||
[write_u8, self.magic[1]],
|
[write_u8, self.magic[1]],
|
||||||
[write_u8, self.msg_type as u8]);
|
[write_u8, self.msg_type as u8]);
|
||||||
None
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,14 +111,14 @@ pub struct Hand {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writeable for Hand {
|
impl Writeable for Hand {
|
||||||
fn write(&self, writer: &mut Writer) -> Option<ser::Error> {
|
fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> {
|
||||||
ser_multiwrite!(writer,
|
ser_multiwrite!(writer,
|
||||||
[write_u32, self.version],
|
[write_u32, self.version],
|
||||||
[write_u32, self.capabilities.bits()],
|
[write_u32, self.capabilities.bits()],
|
||||||
[write_u64, self.nonce]);
|
[write_u64, self.nonce]);
|
||||||
self.sender_addr.write(writer);
|
self.sender_addr.write(writer);
|
||||||
self.receiver_addr.write(writer);
|
self.receiver_addr.write(writer);
|
||||||
writer.write_vec(&mut self.user_agent.clone().into_bytes())
|
writer.write_bytes(self.user_agent.as_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,12 +153,12 @@ pub struct Shake {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writeable for Shake {
|
impl Writeable for Shake {
|
||||||
fn write(&self, writer: &mut Writer) -> Option<ser::Error> {
|
fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> {
|
||||||
ser_multiwrite!(writer,
|
ser_multiwrite!(writer,
|
||||||
[write_u32, self.version],
|
[write_u32, self.version],
|
||||||
[write_u32, self.capabilities.bits()],
|
[write_u32, self.capabilities.bits()],
|
||||||
[write_vec, &mut self.user_agent.as_bytes().to_vec()]);
|
[write_bytes, self.user_agent.as_bytes()]);
|
||||||
None
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,11 +233,11 @@ pub struct PeerError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Writeable for PeerError {
|
impl Writeable for PeerError {
|
||||||
fn write(&self, writer: &mut Writer) -> Option<ser::Error> {
|
fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> {
|
||||||
ser_multiwrite!(writer,
|
ser_multiwrite!(writer,
|
||||||
[write_u32, self.code],
|
[write_u32, self.code],
|
||||||
[write_vec, &mut self.message.clone().into_bytes()]);
|
[write_bytes, self.message.as_bytes()]);
|
||||||
None
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ impl Readable<PeerError> for PeerError {
|
||||||
pub struct SockAddr(pub SocketAddr);
|
pub struct SockAddr(pub SocketAddr);
|
||||||
|
|
||||||
impl Writeable for SockAddr {
|
impl Writeable for SockAddr {
|
||||||
fn write(&self, writer: &mut Writer) -> Option<ser::Error> {
|
fn write(&self, writer: &mut Writer) -> Result<(), ser::Error> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
SocketAddr::V4(sav4) => {
|
SocketAddr::V4(sav4) => {
|
||||||
ser_multiwrite!(writer,
|
ser_multiwrite!(writer,
|
||||||
|
@ -267,14 +267,14 @@ impl Writeable for SockAddr {
|
||||||
[write_u16, sav4.port()]);
|
[write_u16, sav4.port()]);
|
||||||
}
|
}
|
||||||
SocketAddr::V6(sav6) => {
|
SocketAddr::V6(sav6) => {
|
||||||
try_o!(writer.write_u8(1));
|
try!(writer.write_u8(1));
|
||||||
for seg in &sav6.ip().segments() {
|
for seg in &sav6.ip().segments() {
|
||||||
try_o!(writer.write_u16(*seg));
|
try!(writer.write_u16(*seg));
|
||||||
}
|
}
|
||||||
try_o!(writer.write_u16(sav6.port()));
|
try!(writer.write_u16(sav6.port()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue