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