|
1 |
| -use std::{fs::read_to_string, path::PathBuf, time::Duration}; |
| 1 | +use std::{fs::read_to_string, net::SocketAddr, path::PathBuf, sync::Arc, time::Duration}; |
2 | 2 |
|
3 | 3 | use clap::{Args, Parser, ValueEnum};
|
4 | 4 | use eyre::Context;
|
5 | 5 | use sysinfo::{Pid, ProcessExt, ProcessStatus, System, SystemExt};
|
| 6 | +use tokio::net::TcpListener; |
6 | 7 | use tokio::sync::oneshot::{self, error::TryRecvError, Receiver};
|
7 | 8 | use tonic::transport::{Certificate, Identity};
|
8 | 9 |
|
9 | 10 | use post::pow::randomx::RandomXFlag;
|
10 |
| -use post_service::client; |
| 11 | +use post_service::{client, operator}; |
11 | 12 |
|
12 | 13 | /// Post Service
|
13 | 14 | #[derive(Parser, Debug)]
|
@@ -39,6 +40,11 @@ struct Cli {
|
39 | 40 | /// watch PID and exit if it dies
|
40 | 41 | #[arg(long)]
|
41 | 42 | watch_pid: Option<sysinfo::Pid>,
|
| 43 | + |
| 44 | + /// address to listen on for operator service |
| 45 | + /// the operator service is disabled if not specified |
| 46 | + #[arg(long)] |
| 47 | + operator_address: Option<SocketAddr>, |
42 | 48 | }
|
43 | 49 |
|
44 | 50 | #[derive(Args, Debug)]
|
@@ -220,6 +226,13 @@ async fn main() -> eyre::Result<()> {
|
220 | 226 | None
|
221 | 227 | };
|
222 | 228 |
|
| 229 | + let service = Arc::new(service); |
| 230 | + |
| 231 | + if let Some(address) = args.operator_address { |
| 232 | + let listener = TcpListener::bind(address).await?; |
| 233 | + tokio::spawn(operator::run(listener, service.clone())); |
| 234 | + } |
| 235 | + |
223 | 236 | let client = client::ServiceClient::new(args.address, tls, service)?;
|
224 | 237 | let client_handle = tokio::spawn(client.run(args.max_retries, args.reconnect_interval_s));
|
225 | 238 |
|
|
0 commit comments