Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
0b606613
Commit
0b606613
authored
5 years ago
by
Pierre Krieger
Committed by
Bastian Köcher
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ServerToWorkerMsg -> ServiceToWorkerMsg (#4519)
parent
4a9697db
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/client/network/src/service.rs
+28
-28
28 additions, 28 deletions
substrate/client/network/src/service.rs
with
28 additions
and
28 deletions
substrate/client/network/src/service.rs
+
28
−
28
View file @
0b606613
...
...
@@ -114,7 +114,7 @@ pub struct NetworkService<B: BlockT + 'static, S: NetworkSpecialization<B>, H: E
/// nodes it should be connected to or not.
peerset
:
PeersetHandle
,
/// Channel that sends messages to the actual worker.
to_worker
:
mpsc
::
UnboundedSender
<
Serve
r
ToWorkerMsg
<
B
,
S
>>
,
to_worker
:
mpsc
::
UnboundedSender
<
Serv
ic
eToWorkerMsg
<
B
,
S
>>
,
/// Marker to pin the `H` generic. Serves no purpose except to not break backwards
/// compatibility.
_marker
:
PhantomData
<
H
>
,
...
...
@@ -434,7 +434,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
/// The protocol must have been registered with `register_notifications_protocol`.
///
pub
fn
write_notification
(
&
self
,
target
:
PeerId
,
engine_id
:
ConsensusEngineId
,
message
:
Vec
<
u8
>
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
WriteNotification
{
let
_
=
self
.to_worker
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
WriteNotification
{
target
,
engine_id
,
message
,
...
...
@@ -449,7 +449,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
pub
fn
event_stream
(
&
self
)
->
impl
Stream
<
Item
=
Event
,
Error
=
()
>
{
// Note: when transitioning to stable futures, remove the `Error` entirely
let
(
tx
,
rx
)
=
mpsc
::
unbounded
();
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
EventStream
(
tx
));
let
_
=
self
.to_worker
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
EventStream
(
tx
));
rx
}
...
...
@@ -466,7 +466,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
&
self
,
engine_id
:
ConsensusEngineId
,
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
RegisterNotifProtocol
{
let
_
=
self
.to_worker
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
RegisterNotifProtocol
{
engine_id
,
});
}
...
...
@@ -476,7 +476,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
/// The latest transactions will be fetched from the `TransactionPool` that was passed at
/// initialization as part of the configuration.
pub
fn
trigger_repropagate
(
&
self
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
PropagateExtrinsics
);
let
_
=
self
.to_worker
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
PropagateExtrinsics
);
}
/// Make sure an important block is propagated to peers.
...
...
@@ -484,7 +484,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
/// In chain-based consensus, we often need to make sure non-best forks are
/// at least temporarily synced. This function forces such an announcement.
pub
fn
announce_block
(
&
self
,
hash
:
B
::
Hash
,
data
:
Vec
<
u8
>
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
AnnounceBlock
(
hash
,
data
));
let
_
=
self
.to_worker
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
AnnounceBlock
(
hash
,
data
));
}
/// Report a given peer as either beneficial (+) or costly (-) according to the
...
...
@@ -497,7 +497,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
///
/// This triggers the same effects as if the connection had closed itself spontaneously.
pub
fn
disconnect_peer
(
&
self
,
who
:
PeerId
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
DisconnectPeer
(
who
));
let
_
=
self
.to_worker
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
DisconnectPeer
(
who
));
}
/// Request a justification for the given block from the network.
...
...
@@ -507,7 +507,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
pub
fn
request_justification
(
&
self
,
hash
:
&
B
::
Hash
,
number
:
NumberFor
<
B
>
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
RequestJustification
(
hash
.clone
(),
number
));
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
RequestJustification
(
hash
.clone
(),
number
));
}
/// Execute a closure with the chain-specific network specialization.
...
...
@@ -516,7 +516,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
ExecuteWithSpec
(
Box
::
new
(
f
)));
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
ExecuteWithSpec
(
Box
::
new
(
f
)));
}
/// Are we in the process of downloading the chain?
...
...
@@ -531,7 +531,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
pub
fn
get_value
(
&
self
,
key
:
&
record
::
Key
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
GetValue
(
key
.clone
()));
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
GetValue
(
key
.clone
()));
}
/// Start putting a value in the DHT.
...
...
@@ -541,7 +541,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
pub
fn
put_value
(
&
self
,
key
:
record
::
Key
,
value
:
Vec
<
u8
>
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
PutValue
(
key
,
value
));
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
PutValue
(
key
,
value
));
}
/// Connect to unreserved peers and allow unreserved peers to connect.
...
...
@@ -566,7 +566,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
self
.peerset
.add_reserved_peer
(
peer_id
.clone
());
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
AddKnownAddress
(
peer_id
,
addr
));
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
AddKnownAddress
(
peer_id
,
addr
));
Ok
(())
}
...
...
@@ -579,7 +579,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
pub
fn
set_sync_fork_request
(
&
self
,
peers
:
Vec
<
PeerId
>
,
hash
:
B
::
Hash
,
number
:
NumberFor
<
B
>
)
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
SyncFork
(
peers
,
hash
,
number
));
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
SyncFork
(
peers
,
hash
,
number
));
}
/// Modify a peerset priority group.
...
...
@@ -594,7 +594,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
for
(
peer_id
,
addr
)
in
peers
.into_iter
()
{
let
_
=
self
.to_worker
.unbounded_send
(
Serve
r
ToWorkerMsg
::
AddKnownAddress
(
peer_id
,
addr
));
.unbounded_send
(
Serv
ic
eToWorkerMsg
::
AddKnownAddress
(
peer_id
,
addr
));
}
Ok
(())
...
...
@@ -659,7 +659,7 @@ impl<B, S, H> NetworkStateInfo for NetworkService<B, S, H>
/// Messages sent from the `NetworkService` to the `NetworkWorker`.
///
/// Each entry corresponds to a method of `NetworkService`.
enum
Serve
r
ToWorkerMsg
<
B
:
BlockT
,
S
:
NetworkSpecialization
<
B
>>
{
enum
Serv
ic
eToWorkerMsg
<
B
:
BlockT
,
S
:
NetworkSpecialization
<
B
>>
{
PropagateExtrinsics
,
RequestJustification
(
B
::
Hash
,
NumberFor
<
B
>
),
AnnounceBlock
(
B
::
Hash
,
Vec
<
u8
>
),
...
...
@@ -698,7 +698,7 @@ pub struct NetworkWorker<B: BlockT + 'static, S: NetworkSpecialization<B>, H: Ex
/// The import queue that was passed as initialization.
import_queue
:
Box
<
dyn
ImportQueue
<
B
>>
,
/// Messages from the `NetworkService` and that must be processed.
from_worker
:
mpsc
::
UnboundedReceiver
<
Serve
r
ToWorkerMsg
<
B
,
S
>>
,
from_worker
:
mpsc
::
UnboundedReceiver
<
Serv
ic
eToWorkerMsg
<
B
,
S
>>
,
/// Receiver for queries from the light client that must be processed.
light_client_rqs
:
Option
<
mpsc
::
UnboundedReceiver
<
RequestData
<
B
>>>
,
/// Senders for events that happen on the network.
...
...
@@ -734,36 +734,36 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> Future for Ne
};
match
msg
{
Serve
r
ToWorkerMsg
::
ExecuteWithSpec
(
task
)
=>
{
Serv
ic
eToWorkerMsg
::
ExecuteWithSpec
(
task
)
=>
{
let
protocol
=
self
.network_service
.user_protocol_mut
();
let
(
mut
context
,
spec
)
=
protocol
.specialization_lock
();
task
(
spec
,
&
mut
context
);
},
Serve
r
ToWorkerMsg
::
AnnounceBlock
(
hash
,
data
)
=>
Serv
ic
eToWorkerMsg
::
AnnounceBlock
(
hash
,
data
)
=>
self
.network_service
.user_protocol_mut
()
.announce_block
(
hash
,
data
),
Serve
r
ToWorkerMsg
::
RequestJustification
(
hash
,
number
)
=>
Serv
ic
eToWorkerMsg
::
RequestJustification
(
hash
,
number
)
=>
self
.network_service
.user_protocol_mut
()
.request_justification
(
&
hash
,
number
),
Serve
r
ToWorkerMsg
::
PropagateExtrinsics
=>
Serv
ic
eToWorkerMsg
::
PropagateExtrinsics
=>
self
.network_service
.user_protocol_mut
()
.propagate_extrinsics
(),
Serve
r
ToWorkerMsg
::
GetValue
(
key
)
=>
Serv
ic
eToWorkerMsg
::
GetValue
(
key
)
=>
self
.network_service
.get_value
(
&
key
),
Serve
r
ToWorkerMsg
::
PutValue
(
key
,
value
)
=>
Serv
ic
eToWorkerMsg
::
PutValue
(
key
,
value
)
=>
self
.network_service
.put_value
(
key
,
value
),
Serve
r
ToWorkerMsg
::
AddKnownAddress
(
peer_id
,
addr
)
=>
Serv
ic
eToWorkerMsg
::
AddKnownAddress
(
peer_id
,
addr
)
=>
self
.network_service
.add_known_address
(
peer_id
,
addr
),
Serve
r
ToWorkerMsg
::
SyncFork
(
peer_ids
,
hash
,
number
)
=>
Serv
ic
eToWorkerMsg
::
SyncFork
(
peer_ids
,
hash
,
number
)
=>
self
.network_service
.user_protocol_mut
()
.set_sync_fork_request
(
peer_ids
,
&
hash
,
number
),
Serve
r
ToWorkerMsg
::
EventStream
(
sender
)
=>
Serv
ic
eToWorkerMsg
::
EventStream
(
sender
)
=>
self
.event_streams
.push
(
sender
),
Serve
r
ToWorkerMsg
::
WriteNotification
{
message
,
engine_id
,
target
}
=>
Serv
ic
eToWorkerMsg
::
WriteNotification
{
message
,
engine_id
,
target
}
=>
self
.network_service
.user_protocol_mut
()
.write_notification
(
target
,
engine_id
,
message
),
Serve
r
ToWorkerMsg
::
RegisterNotifProtocol
{
engine_id
}
=>
{
Serv
ic
eToWorkerMsg
::
RegisterNotifProtocol
{
engine_id
}
=>
{
let
events
=
self
.network_service
.user_protocol_mut
()
.register_notifications_protocol
(
engine_id
);
for
event
in
events
{
self
.event_streams
.retain
(|
sender
|
sender
.unbounded_send
(
event
.clone
())
.is_ok
());
}
},
Serve
r
ToWorkerMsg
::
DisconnectPeer
(
who
)
=>
Serv
ic
eToWorkerMsg
::
DisconnectPeer
(
who
)
=>
self
.network_service
.user_protocol_mut
()
.disconnect_peer
(
&
who
),
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment