Some tweaks in the network crate (#1108)

* Move Roles to network::config

* Make network::config public

* Move NetworkConfig and NonReservedMode to config

* Move Params to config

* Move node_id() to NetworkManager and fix tests

* Rename Specialization to NetworkSpecialization
This commit is contained in:
Pierre Krieger
2018-11-14 11:25:16 +01:00
committed by Gav Wood
parent 6ad88fc623
commit 74e907f3cb
16 changed files with 117 additions and 109 deletions
+53 -2
View File
@@ -14,9 +14,34 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
pub use service::Roles;
//! Configuration for the networking layer of Substrate.
/// Protocol configuration
pub use network_libp2p::{NonReservedPeerMode, NetworkConfiguration};
use chain::Client;
use codec;
use on_demand::OnDemandService;
use runtime_primitives::traits::{Block as BlockT};
use service::{ExHashT, TransactionPool};
use std::sync::Arc;
/// Service initialization parameters.
pub struct Params<B: BlockT, S, H: ExHashT> {
/// Configuration.
pub config: ProtocolConfig,
/// Network layer configuration.
pub network_config: NetworkConfiguration,
/// Substrate relay chain access point.
pub chain: Arc<Client<B>>,
/// On-demand service reference.
pub on_demand: Option<Arc<OnDemandService<B>>>,
/// Transaction pool.
pub transaction_pool: Arc<TransactionPool<H, B>>,
/// Protocol specialization.
pub specialization: S,
}
/// Configuration for the Substrate-specific part of the networking layer.
#[derive(Clone)]
pub struct ProtocolConfig {
/// Assigned roles.
@@ -30,3 +55,29 @@ impl Default for ProtocolConfig {
}
}
}
bitflags! {
/// Bitmask of the roles that a node fulfills.
pub struct Roles: u8 {
/// No network.
const NONE = 0b00000000;
/// Full node, does not participate in consensus.
const FULL = 0b00000001;
/// Light client node.
const LIGHT = 0b00000010;
/// Act as an authority
const AUTHORITY = 0b00000100;
}
}
impl codec::Encode for Roles {
fn encode_to<T: codec::Output>(&self, dest: &mut T) {
dest.push_byte(self.bits())
}
}
impl codec::Decode for Roles {
fn decode<I: codec::Input>(input: &mut I) -> Option<Self> {
Self::from_bits(input.read_byte()?)
}
}