@@ -47,7 +47,7 @@ impl ClientMessage {
|
|||||||
format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str)
|
format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str)
|
||||||
} else {
|
} else {
|
||||||
let filters_json_str: Result<Vec<String>, Error> = filters
|
let filters_json_str: Result<Vec<String>, Error> = filters
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|f| f.json().map_err(Into::<Error>::into))
|
.map(|f| f.json().map_err(Into::<Error>::into))
|
||||||
.collect();
|
.collect();
|
||||||
format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str?.join(","))
|
format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str?.join(","))
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//use nostr::prelude::secp256k1;
|
//use nostr::prelude::secp256k1;
|
||||||
use serde_json;
|
|
||||||
use std::array::TryFromSliceError;
|
use std::array::TryFromSliceError;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl FullKeypair {
|
|||||||
let secret_key = nostr::SecretKey::from(*secret_key);
|
let secret_key = nostr::SecretKey::from(*secret_key);
|
||||||
FullKeypair {
|
FullKeypair {
|
||||||
pubkey: Pubkey::new(&xopk.serialize()),
|
pubkey: Pubkey::new(&xopk.serialize()),
|
||||||
secret_key: SecretKey::from(secret_key),
|
secret_key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,11 +90,7 @@ impl std::fmt::Display for Keypair {
|
|||||||
|
|
||||||
impl std::fmt::Display for FullKeypair {
|
impl std::fmt::Display for FullKeypair {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(
|
write!(f, "Keypair:\n\tpublic: {}\n\tsecret: <hidden>", self.pubkey)
|
||||||
f,
|
|
||||||
"Keypair:\n\tpublic: {}\n\tsecret: {}",
|
|
||||||
self.pubkey, "<hidden>"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,14 +104,9 @@ impl SerializableKeypair {
|
|||||||
pub fn from_keypair(kp: &Keypair, pass: &str, log_n: u8) -> Self {
|
pub fn from_keypair(kp: &Keypair, pass: &str, log_n: u8) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pubkey: kp.pubkey.clone(),
|
pubkey: kp.pubkey.clone(),
|
||||||
encrypted_secret_key: kp
|
encrypted_secret_key: kp.secret_key.clone().and_then(|s| {
|
||||||
.secret_key
|
EncryptedSecretKey::new(&s, pass, log_n, nostr::nips::nip49::KeySecurity::Weak).ok()
|
||||||
.clone()
|
}),
|
||||||
.map(|s| {
|
|
||||||
EncryptedSecretKey::new(&s, pass, log_n, nostr::nips::nip49::KeySecurity::Weak)
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.flatten(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +114,7 @@ impl SerializableKeypair {
|
|||||||
Keypair::new(
|
Keypair::new(
|
||||||
self.pubkey.clone(),
|
self.pubkey.clone(),
|
||||||
self.encrypted_secret_key
|
self.encrypted_secret_key
|
||||||
.map(|e| e.to_secret_key(pass).ok())
|
.and_then(|e| e.to_secret_key(pass).ok()),
|
||||||
.flatten(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ impl Note {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify(&self) -> Result<Self, Error> {
|
pub fn verify(&self) -> Result<Self, Error> {
|
||||||
return Err(Error::InvalidSignature);
|
Err(Error::InvalidSignature)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is just for serde sanity checking
|
/// This is just for serde sanity checking
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl<'a> From<&'a WsEvent> for RelayEvent<'a> {
|
|||||||
impl<'a> From<&'a WsMessage> for RelayEvent<'a> {
|
impl<'a> From<&'a WsMessage> for RelayEvent<'a> {
|
||||||
fn from(wsmsg: &'a WsMessage) -> RelayEvent<'a> {
|
fn from(wsmsg: &'a WsMessage) -> RelayEvent<'a> {
|
||||||
match wsmsg {
|
match wsmsg {
|
||||||
WsMessage::Text(ref s) => match RelayMessage::from_json(&s).map(RelayEvent::Message) {
|
WsMessage::Text(s) => match RelayMessage::from_json(s).map(RelayEvent::Message) {
|
||||||
Ok(msg) => msg,
|
Ok(msg) => msg,
|
||||||
Err(err) => RelayEvent::Error(err),
|
Err(err) => RelayEvent::Error(err),
|
||||||
},
|
},
|
||||||
@@ -59,9 +59,9 @@ impl<'a> RelayMessage<'a> {
|
|||||||
|
|
||||||
pub fn ok(event_id: &'a str, status: bool, message: &'a str) -> Self {
|
pub fn ok(event_id: &'a str, status: bool, message: &'a str) -> Self {
|
||||||
RelayMessage::OK(CommandResult {
|
RelayMessage::OK(CommandResult {
|
||||||
event_id: event_id,
|
event_id,
|
||||||
status,
|
status,
|
||||||
message: message,
|
message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ impl<'a> RelayMessage<'a> {
|
|||||||
// Relay response format: ["NOTICE", <message>]
|
// Relay response format: ["NOTICE", <message>]
|
||||||
if &msg[0..=9] == "[\"NOTICE\"," {
|
if &msg[0..=9] == "[\"NOTICE\"," {
|
||||||
// TODO: there could be more than one space, whatever
|
// TODO: there could be more than one space, whatever
|
||||||
let start = if msg.bytes().nth(10) == Some(b' ') {
|
let start = if msg.as_bytes().get(10).copied() == Some(b' ') {
|
||||||
12
|
12
|
||||||
} else {
|
} else {
|
||||||
11
|
11
|
||||||
@@ -96,7 +96,7 @@ impl<'a> RelayMessage<'a> {
|
|||||||
// EOSE (NIP-15)
|
// EOSE (NIP-15)
|
||||||
// Relay response format: ["EOSE", <subscription_id>]
|
// Relay response format: ["EOSE", <subscription_id>]
|
||||||
if &msg[0..=7] == "[\"EOSE\"," {
|
if &msg[0..=7] == "[\"EOSE\"," {
|
||||||
let start = if msg.bytes().nth(8) == Some(b' ') {
|
let start = if msg.as_bytes().get(8).copied() == Some(b' ') {
|
||||||
10
|
10
|
||||||
} else {
|
} else {
|
||||||
9
|
9
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub struct PoolRelay {
|
|||||||
impl PoolRelay {
|
impl PoolRelay {
|
||||||
pub fn new(relay: Relay) -> PoolRelay {
|
pub fn new(relay: Relay) -> PoolRelay {
|
||||||
PoolRelay {
|
PoolRelay {
|
||||||
relay: relay,
|
relay,
|
||||||
last_ping: Instant::now(),
|
last_ping: Instant::now(),
|
||||||
last_connect_attempt: Instant::now(),
|
last_connect_attempt: Instant::now(),
|
||||||
retry_connect_after: Self::initial_reconnect_duration(),
|
retry_connect_after: Self::initial_reconnect_duration(),
|
||||||
@@ -43,6 +43,12 @@ pub struct RelayPool {
|
|||||||
pub ping_rate: Duration,
|
pub ping_rate: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for RelayPool {
|
||||||
|
fn default() -> Self {
|
||||||
|
RelayPool::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RelayPool {
|
impl RelayPool {
|
||||||
// Constructs a new, empty RelayPool.
|
// Constructs a new, empty RelayPool.
|
||||||
pub fn new() -> RelayPool {
|
pub fn new() -> RelayPool {
|
||||||
@@ -59,11 +65,12 @@ impl RelayPool {
|
|||||||
|
|
||||||
pub fn has(&self, url: &str) -> bool {
|
pub fn has(&self, url: &str) -> bool {
|
||||||
for relay in &self.relays {
|
for relay in &self.relays {
|
||||||
if &relay.relay.url == url {
|
if relay.relay.url == url {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&mut self, cmd: &ClientMessage) {
|
pub fn send(&mut self, cmd: &ClientMessage) {
|
||||||
@@ -157,7 +164,7 @@ impl RelayPool {
|
|||||||
/// function searches each relay in the list in order, attempting to
|
/// function searches each relay in the list in order, attempting to
|
||||||
/// receive a message from each. If a message is received, return it.
|
/// receive a message from each. If a message is received, return it.
|
||||||
/// If no message is received from any relays, None is returned.
|
/// If no message is received from any relays, None is returned.
|
||||||
pub fn try_recv<'a>(&'a mut self) -> Option<PoolEvent<'a>> {
|
pub fn try_recv(&mut self) -> Option<PoolEvent<'_>> {
|
||||||
for relay in &mut self.relays {
|
for relay in &mut self.relays {
|
||||||
let relay = &mut relay.relay;
|
let relay = &mut relay.relay;
|
||||||
if let Some(event) = relay.receiver.try_recv() {
|
if let Some(event) = relay.receiver.try_recv() {
|
||||||
@@ -176,12 +183,9 @@ impl RelayPool {
|
|||||||
// let's just handle pongs here.
|
// let's just handle pongs here.
|
||||||
// We only need to do this natively.
|
// We only need to do this natively.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
match &ev {
|
if let WsMessage::Ping(ref bs) = ev {
|
||||||
WsMessage::Ping(ref bs) => {
|
debug!("pong {}", &relay.url);
|
||||||
debug!("pong {}", &relay.url);
|
relay.sender.send(WsMessage::Pong(bs.to_owned()));
|
||||||
relay.sender.send(WsMessage::Pong(bs.to_owned()));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ fn mention_ui(
|
|||||||
pk: &[u8; 32],
|
pk: &[u8; 32],
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
size: f32,
|
size: f32,
|
||||||
selectable: bool
|
selectable: bool,
|
||||||
) -> egui::Response {
|
) -> egui::Response {
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
|
|||||||
Reference in New Issue
Block a user