@@ -16,6 +16,18 @@ use crate::DriaP2PProtocol;
16
16
use super :: commands:: DriaP2PCommand ;
17
17
use super :: DriaP2PCommander ;
18
18
19
+ /// Number of seconds before an idle connection is closed.
20
+ const IDLE_CONNECTION_TIMEOUT_SECS : u64 = 240 ;
21
+ /// Buffer size for command channel.
22
+ const COMMAND_CHANNEL_BUFSIZE : usize = 1024 ;
23
+ /// Buffer size for events channel.
24
+ const MSG_CHANNEL_BUFSIZE : usize = 1024 ;
25
+
26
+ /// Request-response message type for Dria protocol, accepts bytes as both request and response.
27
+ ///
28
+ /// The additional parsing must be done by the application itself (for now).
29
+ pub type DriaReqResMessage = request_response:: Message < Vec < u8 > , Vec < u8 > > ;
30
+
19
31
/// Peer-to-peer client for Dria Knowledge Network.
20
32
pub struct DriaP2PClient {
21
33
pub peer_id : PeerId ,
@@ -24,25 +36,19 @@ pub struct DriaP2PClient {
24
36
/// Dria protocol, used for identifying the client.
25
37
protocol : DriaP2PProtocol ,
26
38
/// Request-response protocol messages.
27
- reqres_tx : mpsc:: Sender < ( PeerId , request_response :: Message < Vec < u8 > , Vec < u8 > > ) > ,
39
+ reqres_tx : mpsc:: Sender < ( PeerId , DriaReqResMessage ) > ,
28
40
/// Command receiver.
29
41
cmd_rx : mpsc:: Receiver < DriaP2PCommand > ,
30
42
}
31
43
32
- /// Number of seconds before an idle connection is closed.
33
- const IDLE_CONNECTION_TIMEOUT_SECS : u64 = 240 ;
34
- /// Buffer size for command channel.
35
- const COMMAND_CHANNEL_BUFSIZE : usize = 1024 ;
36
- /// Buffer size for events channel.
37
- const MSG_CHANNEL_BUFSIZE : usize = 1024 ;
38
-
39
44
impl DriaP2PClient {
40
45
/// Creates a new P2P client with the given keypair and listen address.
41
46
///
42
47
/// The `version` is used to create the protocol strings for the client, and its very important that
43
48
/// they match with the clients existing within the network.
44
49
///
45
50
/// If for any reason the given `listen_addr` is not available, it will try to listen on a random port on `localhost`.
51
+ #[ allow( clippy:: type_complexity) ]
46
52
pub fn new (
47
53
keypair : Keypair ,
48
54
listen_addr : Multiaddr ,
@@ -51,7 +57,7 @@ impl DriaP2PClient {
51
57
) -> Result < (
52
58
DriaP2PClient ,
53
59
DriaP2PCommander ,
54
- mpsc:: Receiver < ( PeerId , request_response :: Message < Vec < u8 > , Vec < u8 > > ) > ,
60
+ mpsc:: Receiver < ( PeerId , DriaReqResMessage ) > ,
55
61
) > {
56
62
let peer_id = keypair. public ( ) . to_peer_id ( ) ;
57
63
0 commit comments