Add message forwarding
parent: tbd commit: e4fa992
1 | use Error; |
2 | use ; |
3 | use |
4 | , | AuthenticationTokenGranter
5 | , |
6 | , |
7 | , | InstanceConnections
8 | ; |
9 | use Instance; |
10 | use ; |
11 | use ; |
12 | use |
13 | , | File
14 | , |
15 | , |
16 | , | Mutex
17 | ; |
18 | use ; |
19 | use Table; |
20 | |
21 | |
22 | extern crate tracing; |
23 | |
24 | |
25 | async |
26 | ; | init
27 | let mut listener = bind .await?; |
28 | let connections: = default; |
29 | let instance_connections: = default; |
30 | let config: Table = |
31 | let mut file = open .await?; |
32 | let mut text = String new; |
33 | file.read_to_string .await?; |
34 | text.parse? |
35 | ; |
36 | let db_conn_options = new |
37 | .host |
38 | .port |
39 | .database |
40 | .username |
41 | .password |
42 | .log_statements; |
43 | let db_pool = connect_with .await?; |
44 | |
45 | debug!; |
46 | ! .run .await?; | migrate
47 | info!; |
48 | |
49 | let repository_backend: = |
50 | new |
51 | pg_pool: db_pool.clone, |
52 | repository_folder: String from |
53 | config |
54 | .as_str |
55 | .unwrap, |
56 | , |
57 | instance: from_str .unwrap, |
58 | ; |
59 | |
60 | let token_granter = new |
61 | config: config.clone, |
62 | instance: from_str .unwrap, |
63 | ; |
64 | |
65 | let user_backend: = new |
66 | db_pool.clone, |
67 | & from_str .unwrap, |
68 | token_granter.clone, |
69 | ; |
70 | |
71 | info!; |
72 | |
73 | loop |
74 | let stream = accept_stream .await; |
75 | info!; |
76 | |
77 | let = match stream |
78 | Ok => stream, |
79 | Err => |
80 | error!; |
81 | continue; |
82 | |
83 | ; |
84 | |
85 | info!; |
86 | |
87 | let connection = accept_websocket_connection .await; |
88 | |
89 | let connection = match connection |
90 | Ok => connection, |
91 | Err => |
92 | error! |
93 | "Failed to initiate Websocket connection from {}. {:?}", |
94 | address, err |
95 | ; |
96 | continue; |
97 | |
98 | ; |
99 | |
100 | info!; |
101 | |
102 | let connection = RawConnection |
103 | task: spawn |
104 | connection, |
105 | connections.clone, |
106 | repository_backend.clone, |
107 | user_backend.clone, |
108 | token_granter.clone, |
109 | address, |
110 | unwrap, | from_str .
111 | instance_connections.clone, |
112 | , |
113 | ; |
114 | |
115 | connections.lock .await.connections.push; |
116 | |
117 | |
118 | |
119 | async |
120 | let stream = listener.accept .await?; |
121 | |
122 | Ok |
123 | |
124 | |
125 | async |
126 | stream: S, |
127 | |
128 | let connection = accept_async .await?; |
129 | |
130 | Ok |
131 | |
132 |