feat(main): dynamically specify relays
This commit is contained in:
parent
867ba917c0
commit
c2f1f54170
|
@ -1,5 +1,6 @@
|
||||||
/target
|
/target
|
||||||
|
|
||||||
|
relays
|
||||||
keys
|
keys
|
||||||
*.html
|
*.html
|
||||||
/src/bin
|
/src/bin
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -1,7 +1,8 @@
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{stdin, stdout, Write};
|
use std::fs::File;
|
||||||
|
use std::io::{BufRead, BufReader, stdin, stdout, Write};
|
||||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
@ -66,9 +67,25 @@ async fn main() {
|
||||||
let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
|
let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
|
||||||
|
|
||||||
let client = Client::new(MY_KEYS.deref());
|
let client = Client::new(MY_KEYS.deref());
|
||||||
client.add_relay("ws://localhost:4736").await;
|
|
||||||
println!("My public key: {}", MY_KEYS.public_key());
|
println!("My public key: {}", MY_KEYS.public_key());
|
||||||
//client.add_relay("wss://relay.damus.io").await;
|
match File::open("relays").map(|f| BufReader::new(f).lines().flatten()) {
|
||||||
|
Ok(lines) => {
|
||||||
|
for line in lines {
|
||||||
|
or_print(client.add_relay(line).await);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Could not read relays file: {}", e);
|
||||||
|
print!("Relay? ");
|
||||||
|
stdout().flush().unwrap();
|
||||||
|
match stdin().lines().next() {
|
||||||
|
Some(Ok(line)) => {
|
||||||
|
or_print(client.add_relay(if line.contains("://") { line } else { "wss://".to_string() + &line }).await);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
//client
|
//client
|
||||||
// .add_relay_with_opts(
|
// .add_relay_with_opts(
|
||||||
// "wss://relay.nostr.info",
|
// "wss://relay.nostr.info",
|
||||||
|
|
Loading…
Reference in New Issue