Sync IPC interface (#1584)

* chain notify trait

* replaced network service with io service

* fix ethcore crate warnings

* refactored network service without generic

* ethcore fix

* ethsync refactoring

* proper linking of notify

* manage network interface

* rpc crate rebinding

* full rewire

* sync internal io service

* fix deadlock

* fix warnings and removed async io

* sync imported message propagation

* fix rpc warnings

* binart warnings

* test fixes

* rpc mocks and tests

* fix util doctest

* fix message name and removed empty notifier

* pointers mess & dark mode fixed

* fixed sync doctest

* added few warnings

* fix review

* new convention match

* fix error unwraps

* doctest fix

* basic library re-layout

* missing files to relayout

* duplicating network config on sync level

* binary serializers for config

* ipc endpoint for manage

* ipc endpoint for sync

* handshake sorting out

* sorting out the multi-interface dispatch scenario

* fixing tests

* fix doctest
This commit is contained in:
Nikolay Volf
2016-07-14 12:07:33 +02:00
committed by Arkadiy Paronyan
parent 8d0e05adb7
commit 44bc8a08fb
17 changed files with 372 additions and 204 deletions

View File

@@ -574,8 +574,6 @@ fn push_client_implementation(
interface_map: &InterfaceMap,
push: &mut FnMut(Annotatable),
) {
let item_ident = interface_map.ident_map.qualified_ident(builder);
let mut index = -1i32;
let items = interface_map.dispatches.iter()
.map(|_| { index = index + 1; P(implement_client_method(cx, builder, index as u16, interface_map)) })
@@ -584,12 +582,13 @@ fn push_client_implementation(
let generics = client_generics(builder, interface_map);
let client_ident = client_qualified_ident(cx, builder, interface_map);
let where_clause = &generics.where_clause;
let endpoint = interface_map.endpoint;
let handshake_item = quote_impl_item!(cx,
pub fn handshake(&self) -> Result<(), ::ipc::Error> {
let payload = ::ipc::Handshake {
protocol_version: $item_ident::protocol_version(),
api_version: $item_ident::api_version(),
protocol_version: Arc::<$endpoint>::protocol_version(),
api_version: Arc::<$endpoint>::api_version(),
};
::ipc::invoke(
@@ -734,6 +733,7 @@ struct InterfaceMap {
pub generics: Generics,
pub impl_trait: Option<TraitRef>,
pub ident_map: IdentMap,
pub endpoint: Ident,
}
struct IdentMap {
@@ -753,10 +753,6 @@ impl IdentMap {
builder.id(format!("{}Client", self.original_path.segments[0].identifier))
}
}
fn qualified_ident(&self, builder: &aster::AstBuilder) -> Ident {
builder.id(format!("{}", ::syntax::print::pprust::path_to_string(&self.original_path).replace("<", "::<")))
}
}
fn ty_ident_map(original_ty: &P<Ty>) -> IdentMap {
@@ -804,8 +800,13 @@ fn implement_interface(
let (handshake_arm, handshake_arm_buf) = implement_handshake_arm(cx);
let ty = ty_ident_map(&original_ty).ident(builder);
let interface_endpoint = match *impl_trait {
Some(ref trait_) => builder.id(::syntax::print::pprust::path_to_string(&trait_.path)),
None => ty
};
let ipc_item = quote_item!(cx,
impl $impl_generics ::ipc::IpcInterface<$ty> for $ty $where_clause {
impl $impl_generics ::ipc::IpcInterface<$interface_endpoint> for Arc<$interface_endpoint> $where_clause {
fn dispatch<R>(&self, r: &mut R) -> Vec<u8>
where R: ::std::io::Read
{
@@ -844,5 +845,6 @@ fn implement_interface(
dispatches: dispatch_table,
generics: generics.clone(),
impl_trait: impl_trait.clone(),
endpoint: interface_endpoint,
})
}

View File

@@ -68,4 +68,4 @@ impl HypervisorService {
}
}
impl ::ipc::IpcConfig for HypervisorService {}
impl ::ipc::IpcConfig<HypervisorService> for Arc<HypervisorService> {}

View File

@@ -33,7 +33,7 @@ const POLL_TIMEOUT: isize = 100;
const CLIENT_CONNECTION_TIMEOUT: isize = 2500;
/// Generic worker to handle service (binded) sockets
pub struct Worker<S> where S: IpcInterface<S> {
pub struct Worker<S: ?Sized> where Arc<S>: IpcInterface<S> {
service: Arc<S>,
sockets: Vec<(Socket, Endpoint)>,
polls: Vec<PollFd>,
@@ -116,7 +116,7 @@ pub enum SocketError {
RequestLink,
}
impl<S> Worker<S> where S: IpcInterface<S> {
impl<S: ?Sized> Worker<S> where Arc<S>: IpcInterface<S> {
/// New worker over specified `service`
pub fn new(service: &Arc<S>) -> Worker<S> {
Worker::<S> {

View File

@@ -610,6 +610,7 @@ impl From<::semver::Version> for BinVersion {
}
}
binary_fixed_size!(u16);
binary_fixed_size!(u64);
binary_fixed_size!(u32);
binary_fixed_size!(usize);

View File

@@ -29,7 +29,7 @@ pub struct Handshake {
/// Allows to configure custom version and custom handshake response for
/// ipc host
pub trait IpcConfig {
pub trait IpcConfig<I: ?Sized> {
/// Current service api version
/// Should be increased if any of the methods changes signature
fn api_version() -> Version {
@@ -60,7 +60,7 @@ pub enum Error {
/// Allows implementor to be attached to generic worker and dispatch rpc requests
/// over IPC
pub trait IpcInterface<T>: IpcConfig {
pub trait IpcInterface<I :?Sized> : IpcConfig<I> {
/// reads the message from io, dispatches the call and returns serialized result
fn dispatch<R>(&self, r: &mut R) -> Vec<u8> where R: Read;