Snapshot fixes and optimizations (#2863)

This commit is contained in:
Arkadiy Paronyan
2016-10-25 18:40:01 +02:00
committed by GitHub
parent 2d2e9c4d6e
commit 135d5d0e4c
8 changed files with 84 additions and 52 deletions

View File

@@ -241,9 +241,14 @@ impl<'s> NetworkContext<'s> {
/// Send a packet over the network to another peer.
pub fn send(&self, peer: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
self.send_protocol(self.protocol, peer, packet_id, data)
}
/// Send a packet over the network to another peer using specified protocol.
pub fn send_protocol(&self, protocol: ProtocolId, peer: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
let session = self.resolve_session(peer);
if let Some(session) = session {
try!(session.lock().send_packet(self.io, self.protocol, packet_id as u8, &data));
try!(session.lock().send_packet(self.io, protocol, packet_id as u8, &data));
} else {
trace!(target: "network", "Send: Peer no longer exist")
}
@@ -911,7 +916,7 @@ impl Host {
}
}
fn update_nodes(&self, io: &IoContext<NetworkIoMessage>, node_changes: TableUpdates) {
fn update_nodes(&self, _io: &IoContext<NetworkIoMessage>, node_changes: TableUpdates) {
let mut to_remove: Vec<PeerId> = Vec::new();
{
let sessions = self.sessions.write();
@@ -926,7 +931,6 @@ impl Host {
}
for i in to_remove {
trace!(target: "network", "Removed from node table: {}", i);
self.kill_connection(i, io, false);
}
self.nodes.write().update(node_changes, &*self.reserved_nodes.read());
}

View File

@@ -395,7 +395,7 @@ impl Session {
PACKET_PEERS => Ok(SessionData::None),
PACKET_USER ... PACKET_LAST => {
let mut i = 0usize;
while packet_id < self.info.capabilities[i].id_offset {
while packet_id > self.info.capabilities[i].id_offset + self.info.capabilities[i].packet_count {
i += 1;
if i == self.info.capabilities.len() {
debug!(target: "network", "Unknown packet: {:?}", packet_id);
@@ -469,7 +469,7 @@ impl Session {
offset += caps[i].packet_count;
i += 1;
}
trace!(target: "network", "Hello: {} v{} {} {:?}", client_version, protocol, id, caps);
debug!(target: "network", "Hello: {} v{} {} {:?}", client_version, protocol, id, caps);
self.info.protocol_version = protocol;
self.info.client_version = client_version;
self.info.capabilities = caps;

View File

@@ -348,13 +348,13 @@ impl JournalDB for OverlayRecentDB {
match rc {
0 => {}
1 => {
if try!(self.backing.get(self.column, &key)).is_some() {
if cfg!(debug_assertions) && try!(self.backing.get(self.column, &key)).is_some() {
return Err(BaseDataError::AlreadyExists(key).into());
}
batch.put(self.column, &key, &value)
}
-1 => {
if try!(self.backing.get(self.column, &key)).is_none() {
if cfg!(debug_assertions) && try!(self.backing.get(self.column, &key)).is_none() {
return Err(BaseDataError::NegativelyReferencedHash(key).into());
}
batch.delete(self.column, &key)