Преглед на файлове

Prepare websocket client types.

Mathias Gottschlag преди 5 години
родител
ревизия
44458514a4
променени са 3 файла, в които са добавени 68 реда и са изтрити 0 реда
  1. 1
    0
      Cargo.lock
  2. 1
    0
      Cargo.toml
  3. 66
    0
      src/network/client.rs

+ 1
- 0
Cargo.lock Целия файл

@@ -958,6 +958,7 @@ dependencies = [
958 958
  "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
959 959
  "structopt 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
960 960
  "tokio 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
961
+ "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
961 962
 ]
962 963
 
963 964
 [[package]]

+ 1
- 0
Cargo.toml Целия файл

@@ -17,3 +17,4 @@ env_logger = "0.7"
17 17
 log = "0.4"
18 18
 rmp-serde = "0.14"
19 19
 fswatcher = { git = "https://github.com/mgottschlag/fswatcher-rs.git" }
20
+url = "*"

+ 66
- 0
src/network/client.rs Целия файл

@@ -1,5 +1,9 @@
1 1
 use futures::Future;
2
+use futures::task::{Context, Poll};
3
+use core::pin::Pin;
2 4
 use tokio::stream::Stream;
5
+use async_tungstenite::{tokio::connect_async, tungstenite::Message, WebSocketStream};
6
+use url::Url;
3 7
 
4 8
 use super::packet_connection::IncomingPacket;
5 9
 
@@ -19,6 +23,68 @@ pub trait RPC: Future {
19 23
 
20 24
 pub trait ServerEventStream<PacketType>: Stream<Item = PacketType> {}
21 25
 
26
+pub struct WSRPCInterface<PacketType, Stream> {
27
+    // TODO
28
+    _unused: PacketType,
29
+    stream: WebSocketStream<Stream>,
30
+}
31
+
32
+impl<P, S> WSRPCInterface<P, S> {
33
+    fn create<P2, S2>(ws_stream: WebSocketStream<S2>) -> (Self, WSServerEventStream<P2>) {
34
+        // TODO
35
+        panic!("Not yet implemented.");
36
+    }
37
+}
38
+
39
+impl<P, S> RPCInterface for WSRPCInterface<P, S> {
40
+    type PacketType = P;
41
+    type NetworkError = String; // TODO
42
+
43
+    type Call = WSRPC<Self::PacketType>;
44
+
45
+    fn call(call: &Self::PacketType) -> Self::Call {
46
+        // TODO
47
+        panic!("Not yet implemented.");
48
+    }
49
+}
50
+
51
+pub struct WSRPC<PacketType> {
52
+    // TODO
53
+    _unused: PacketType,
54
+}
55
+
56
+impl<P> Future for WSRPC<P> {
57
+    type Output = Result<IncomingPacket<P>, String>;
58
+
59
+    fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
60
+        // TODO
61
+        panic!("Not yet implemented.");
62
+    }
63
+}
64
+
65
+impl<P> RPC for WSRPC<P> {
66
+    fn with_timeout(self, timeout: Duration) -> Self {
67
+        // TODO
68
+        panic!("Not yet implemented.");
69
+    }
70
+}
71
+
72
+struct WSServerEventStream<PacketType> {
73
+    _unused: PacketType,
74
+}
75
+
76
+impl<P> Stream for WSServerEventStream<P> {
77
+    type Item = P;
78
+
79
+    fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
80
+        // TODO
81
+        panic!("Not yet implemented.");
82
+    }
83
+}
84
+
85
+
22 86
 pub async fn low_level_integration_test_client(address: String) {
87
+    let url = Url::parse(&address).unwrap();
88
+    let (mut ws_stream, _) = connect_async(url).await.unwrap();
23 89
     // TODO
24 90
 }

Loading…
Отказ
Запис