mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 03:58:04 +00:00
Add DHT key-value behaviour (#2937)
* Add DHT key-value behaviour * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Apply suggestions from code review Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Return which key failed to be inserted
This commit is contained in:
committed by
Pierre Krieger
parent
0ddf4a2a00
commit
e735853ca3
@@ -0,0 +1,41 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Network event types. These are are not the part of the protocol, but rather
|
||||
//! events that happen on the network like DHT get/put results received.
|
||||
|
||||
use libp2p::multihash::Multihash;
|
||||
|
||||
/// Events generated by DHT as a response to get_value and put_value requests.
|
||||
pub enum DhtEvent {
|
||||
/// The value was found.
|
||||
ValueFound(Vec<(Multihash, Vec<u8>)>),
|
||||
|
||||
/// The requested record has not been found in the DHT.
|
||||
ValueNotFound(Multihash),
|
||||
|
||||
/// The record has been successfully inserted into the DHT.
|
||||
ValuePut(Multihash),
|
||||
|
||||
/// An error has occured while putting a record into the DHT.
|
||||
ValuePutFailed(Multihash),
|
||||
}
|
||||
|
||||
/// Type for events generated by networking layer.
|
||||
pub enum Event {
|
||||
/// Event generated by a DHT.
|
||||
Dht(DhtEvent),
|
||||
}
|
||||
@@ -39,6 +39,12 @@ pub trait NetworkSpecialization<B: BlockT>: Send + Sync + 'static {
|
||||
message: &mut Option<crate::message::Message<B>>
|
||||
);
|
||||
|
||||
/// Called when a network-specific event arrives.
|
||||
fn on_event(
|
||||
&mut self,
|
||||
event: crate::protocol::event::Event
|
||||
);
|
||||
|
||||
/// Called on abort.
|
||||
#[deprecated(note = "This method is never called; aborting corresponds to dropping the object")]
|
||||
fn on_abort(&mut self) { }
|
||||
@@ -130,6 +136,13 @@ macro_rules! construct_simple_protocol {
|
||||
$( self.$sub_protocol_name.on_message(_ctx, _who, _message); )*
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
&mut self,
|
||||
_event: $crate::event::Event
|
||||
) {
|
||||
$( self.$sub_protocol_name.on_event(_event); )*
|
||||
}
|
||||
|
||||
fn on_abort(&mut self) {
|
||||
$( self.$sub_protocol_name.on_abort(); )*
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user