more clippy
This commit is contained in:
parent
f596b3ce05
commit
20451af880
@ -69,14 +69,11 @@ impl ProtectedStore {
|
|||||||
|
|
||||||
let vkey = self.browser_key_name(key.as_ref());
|
let vkey = self.browser_key_name(key.as_ref());
|
||||||
|
|
||||||
let prev = match ls
|
let prev = ls
|
||||||
.get_item(&vkey)
|
.get_item(&vkey)
|
||||||
.map_err(map_jsvalue_error)
|
.map_err(map_jsvalue_error)
|
||||||
.wrap_err("exception_thrown")?
|
.wrap_err("exception_thrown")?
|
||||||
{
|
.is_some();
|
||||||
Some(_) => true,
|
|
||||||
None => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
ls.set_item(&vkey, value.as_ref())
|
ls.set_item(&vkey, value.as_ref())
|
||||||
.map_err(map_jsvalue_error)
|
.map_err(map_jsvalue_error)
|
||||||
|
@ -249,7 +249,7 @@ impl ConnectionManager {
|
|||||||
&self,
|
&self,
|
||||||
dial_info: DialInfo,
|
dial_info: DialInfo,
|
||||||
) -> EyreResult<NetworkResult<ConnectionHandle>> {
|
) -> EyreResult<NetworkResult<ConnectionHandle>> {
|
||||||
let peer_address = dial_info.to_peer_address();
|
let peer_address = dial_info.peer_address();
|
||||||
let remote_addr = peer_address.socket_addr();
|
let remote_addr = peer_address.socket_addr();
|
||||||
let mut preferred_local_address = self
|
let mut preferred_local_address = self
|
||||||
.network_manager()
|
.network_manager()
|
||||||
@ -301,26 +301,6 @@ impl ConnectionManager {
|
|||||||
.await;
|
.await;
|
||||||
match result_net_res {
|
match result_net_res {
|
||||||
Ok(net_res) => {
|
Ok(net_res) => {
|
||||||
// // If the connection 'already exists', then try one last time to return a connection from the table, in case
|
|
||||||
// // an 'accept' happened at literally the same time as our connect. A preferred local address must have been
|
|
||||||
// // specified otherwise we would have picked a different ephemeral port and this could not have happened
|
|
||||||
// if net_res.is_already_exists() && preferred_local_address.is_some() {
|
|
||||||
// // Make 'already existing' connection descriptor
|
|
||||||
// let conn_desc = ConnectionDescriptor::new(
|
|
||||||
// dial_info.to_peer_address(),
|
|
||||||
// SocketAddress::from_socket_addr(preferred_local_address.unwrap()),
|
|
||||||
// );
|
|
||||||
// // Return the connection for this if we have it
|
|
||||||
// if let Some(conn) = self
|
|
||||||
// .arc
|
|
||||||
// .connection_table
|
|
||||||
// .get_connection_by_descriptor(conn_desc)
|
|
||||||
// {
|
|
||||||
// // Should not really happen, lets make sure we see this if it does
|
|
||||||
// log_net!(warn "== Returning existing connection in race: {:?}", conn_desc);
|
|
||||||
// return Ok(NetworkResult::Value(conn));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if net_res.is_value() || retry_count == 0 {
|
if net_res.is_value() || retry_count == 0 {
|
||||||
// Successful new connection, return it
|
// Successful new connection, return it
|
||||||
break net_res;
|
break net_res;
|
||||||
|
@ -46,7 +46,7 @@ use storage_manager::*;
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm::*;
|
use wasm::*;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub use wasm::{LOCAL_NETWORK_CAPABILITIES, MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES};
|
pub use wasm::{/* LOCAL_NETWORK_CAPABILITIES, */ MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES,};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -462,7 +462,7 @@ impl Network {
|
|||||||
}
|
}
|
||||||
// Network accounting
|
// Network accounting
|
||||||
self.network_manager()
|
self.network_manager()
|
||||||
.stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64));
|
.stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64));
|
||||||
|
|
||||||
Ok(NetworkResult::Value(()))
|
Ok(NetworkResult::Value(()))
|
||||||
})
|
})
|
||||||
@ -507,7 +507,7 @@ impl Network {
|
|||||||
.await
|
.await
|
||||||
.wrap_err("send message failure")?);
|
.wrap_err("send message failure")?);
|
||||||
self.network_manager()
|
self.network_manager()
|
||||||
.stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64));
|
.stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64));
|
||||||
|
|
||||||
// receive single response
|
// receive single response
|
||||||
let mut out = vec![0u8; MAX_MESSAGE_SIZE];
|
let mut out = vec![0u8; MAX_MESSAGE_SIZE];
|
||||||
@ -552,7 +552,7 @@ impl Network {
|
|||||||
|
|
||||||
network_result_try!(pnc.send(data).await.wrap_err("send failure")?);
|
network_result_try!(pnc.send(data).await.wrap_err("send failure")?);
|
||||||
self.network_manager()
|
self.network_manager()
|
||||||
.stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64));
|
.stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64));
|
||||||
|
|
||||||
let out =
|
let out =
|
||||||
network_result_try!(network_result_try!(timeout(timeout_ms, pnc.recv())
|
network_result_try!(network_result_try!(timeout(timeout_ms, pnc.recv())
|
||||||
@ -560,10 +560,8 @@ impl Network {
|
|||||||
.into_network_result())
|
.into_network_result())
|
||||||
.wrap_err("recv failure")?);
|
.wrap_err("recv failure")?);
|
||||||
|
|
||||||
self.network_manager().stats_packet_rcvd(
|
self.network_manager()
|
||||||
dial_info.to_ip_addr(),
|
.stats_packet_rcvd(dial_info.ip_addr(), ByteCount::new(out.len() as u64));
|
||||||
ByteCount::new(out.len() as u64),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(NetworkResult::Value(out))
|
Ok(NetworkResult::Value(out))
|
||||||
}
|
}
|
||||||
@ -676,7 +674,7 @@ impl Network {
|
|||||||
|
|
||||||
// Network accounting
|
// Network accounting
|
||||||
self.network_manager()
|
self.network_manager()
|
||||||
.stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64));
|
.stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64));
|
||||||
|
|
||||||
Ok(NetworkResult::value(connection_descriptor))
|
Ok(NetworkResult::value(connection_descriptor))
|
||||||
})
|
})
|
||||||
|
@ -20,7 +20,7 @@ const MAX_WS_BEFORE_BODY: usize = 2048;
|
|||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature="rt-async-std")] {
|
if #[cfg(feature="rt-async-std")] {
|
||||||
pub type WebsocketNetworkConnectionWSS =
|
pub type WebsocketNetworkConnectionWSS =
|
||||||
DialInfo::WS { field1: _ }ketNetworkConnection<async_tls::client::TlsStream<TcpStream>>;
|
WebsocketNetworkConnection<async_tls::client::TlsStream<TcpStream>>;
|
||||||
pub type WebsocketNetworkConnectionWS = WebsocketNetworkConnection<TcpStream>;
|
pub type WebsocketNetworkConnectionWS = WebsocketNetworkConnection<TcpStream>;
|
||||||
} else if #[cfg(feature="rt-tokio")] {
|
} else if #[cfg(feature="rt-tokio")] {
|
||||||
pub type WebsocketNetworkConnectionWSS =
|
pub type WebsocketNetworkConnectionWSS =
|
||||||
@ -306,7 +306,7 @@ impl WebsocketProtocolHandler {
|
|||||||
|
|
||||||
// Make our connection descriptor
|
// Make our connection descriptor
|
||||||
let descriptor = ConnectionDescriptor::new(
|
let descriptor = ConnectionDescriptor::new(
|
||||||
dial_info.to_peer_address(),
|
dial_info.peer_address(),
|
||||||
SocketAddress::from_socket_addr(actual_local_addr),
|
SocketAddress::from_socket_addr(actual_local_addr),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ impl DialInfo {
|
|||||||
Self::WSS(di) => di.socket_address,
|
Self::WSS(di) => di.socket_address,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn to_ip_addr(&self) -> IpAddr {
|
pub fn ip_addr(&self) -> IpAddr {
|
||||||
match self {
|
match self {
|
||||||
Self::UDP(di) => di.socket_address.ip_addr(),
|
Self::UDP(di) => di.socket_address.ip_addr(),
|
||||||
Self::TCP(di) => di.socket_address.ip_addr(),
|
Self::TCP(di) => di.socket_address.ip_addr(),
|
||||||
@ -274,7 +274,7 @@ impl DialInfo {
|
|||||||
Self::WSS(di) => di.socket_address.socket_addr(),
|
Self::WSS(di) => di.socket_address.socket_addr(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn to_peer_address(&self) -> PeerAddress {
|
pub fn peer_address(&self) -> PeerAddress {
|
||||||
match self {
|
match self {
|
||||||
Self::UDP(di) => PeerAddress::new(di.socket_address, ProtocolType::UDP),
|
Self::UDP(di) => PeerAddress::new(di.socket_address, ProtocolType::UDP),
|
||||||
Self::TCP(di) => PeerAddress::new(di.socket_address, ProtocolType::TCP),
|
Self::TCP(di) => PeerAddress::new(di.socket_address, ProtocolType::TCP),
|
||||||
|
@ -32,18 +32,18 @@ pub const PUBLIC_INTERNET_CAPABILITIES: [Capability; PUBLIC_INTERNET_CAPABILITIE
|
|||||||
CAP_BLOCKSTORE,
|
CAP_BLOCKSTORE,
|
||||||
];
|
];
|
||||||
|
|
||||||
#[cfg(feature = "unstable-blockstore")]
|
// #[cfg(feature = "unstable-blockstore")]
|
||||||
const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 3;
|
// const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 3;
|
||||||
#[cfg(not(feature = "unstable-blockstore"))]
|
// #[cfg(not(feature = "unstable-blockstore"))]
|
||||||
const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 2;
|
// const LOCAL_NETWORK_CAPABILITIES_LEN: usize = 2;
|
||||||
|
|
||||||
pub const LOCAL_NETWORK_CAPABILITIES: [Capability; LOCAL_NETWORK_CAPABILITIES_LEN] = [
|
// pub const LOCAL_NETWORK_CAPABILITIES: [Capability; LOCAL_NETWORK_CAPABILITIES_LEN] = [
|
||||||
//CAP_RELAY,
|
// //CAP_RELAY,
|
||||||
CAP_DHT,
|
// CAP_DHT,
|
||||||
CAP_APPMESSAGE,
|
// CAP_APPMESSAGE,
|
||||||
#[cfg(feature = "unstable-blockstore")]
|
// #[cfg(feature = "unstable-blockstore")]
|
||||||
CAP_BLOCKSTORE,
|
// CAP_BLOCKSTORE,
|
||||||
];
|
// ];
|
||||||
|
|
||||||
pub const MAX_CAPABILITIES: usize = 64;
|
pub const MAX_CAPABILITIES: usize = 64;
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ impl Network {
|
|||||||
if self
|
if self
|
||||||
.network_manager()
|
.network_manager()
|
||||||
.address_filter()
|
.address_filter()
|
||||||
.is_ip_addr_punished(dial_info.address().to_ip_addr())
|
.is_ip_addr_punished(dial_info.address().ip_addr())
|
||||||
{
|
{
|
||||||
return Ok(NetworkResult::no_connection_other("punished"));
|
return Ok(NetworkResult::no_connection_other("punished"));
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ impl Network {
|
|||||||
|
|
||||||
// Network accounting
|
// Network accounting
|
||||||
self.network_manager()
|
self.network_manager()
|
||||||
.stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64));
|
.stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64));
|
||||||
|
|
||||||
Ok(NetworkResult::Value(()))
|
Ok(NetworkResult::Value(()))
|
||||||
})
|
})
|
||||||
@ -202,7 +202,7 @@ impl Network {
|
|||||||
if self
|
if self
|
||||||
.network_manager()
|
.network_manager()
|
||||||
.address_filter()
|
.address_filter()
|
||||||
.is_ip_addr_punished(dial_info.address().to_ip_addr())
|
.is_ip_addr_punished(dial_info.address().ip_addr())
|
||||||
{
|
{
|
||||||
return Ok(NetworkResult::no_connection_other("punished"));
|
return Ok(NetworkResult::no_connection_other("punished"));
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ impl Network {
|
|||||||
|
|
||||||
network_result_try!(pnc.send(data).await.wrap_err("send failure")?);
|
network_result_try!(pnc.send(data).await.wrap_err("send failure")?);
|
||||||
self.network_manager()
|
self.network_manager()
|
||||||
.stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64));
|
.stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64));
|
||||||
|
|
||||||
let out =
|
let out =
|
||||||
network_result_try!(network_result_try!(timeout(timeout_ms, pnc.recv())
|
network_result_try!(network_result_try!(timeout(timeout_ms, pnc.recv())
|
||||||
@ -235,10 +235,8 @@ impl Network {
|
|||||||
.into_network_result())
|
.into_network_result())
|
||||||
.wrap_err("recv failure")?);
|
.wrap_err("recv failure")?);
|
||||||
|
|
||||||
self.network_manager().stats_packet_rcvd(
|
self.network_manager()
|
||||||
dial_info.to_ip_addr(),
|
.stats_packet_rcvd(dial_info.ip_addr(), ByteCount::new(out.len() as u64));
|
||||||
ByteCount::new(out.len() as u64),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(NetworkResult::Value(out))
|
Ok(NetworkResult::Value(out))
|
||||||
}
|
}
|
||||||
@ -273,7 +271,7 @@ impl Network {
|
|||||||
ConnectionHandleSendResult::Sent => {
|
ConnectionHandleSendResult::Sent => {
|
||||||
// Network accounting
|
// Network accounting
|
||||||
self.network_manager().stats_packet_sent(
|
self.network_manager().stats_packet_sent(
|
||||||
descriptor.remote().to_socket_addr().ip(),
|
descriptor.remote().socket_addr().ip(),
|
||||||
ByteCount::new(data_len as u64),
|
ByteCount::new(data_len as u64),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -324,7 +322,7 @@ impl Network {
|
|||||||
|
|
||||||
// Network accounting
|
// Network accounting
|
||||||
self.network_manager()
|
self.network_manager()
|
||||||
.stats_packet_sent(dial_info.to_ip_addr(), ByteCount::new(data_len as u64));
|
.stats_packet_sent(dial_info.ip_addr(), ByteCount::new(data_len as u64));
|
||||||
|
|
||||||
Ok(NetworkResult::value(connection_descriptor))
|
Ok(NetworkResult::value(connection_descriptor))
|
||||||
})
|
})
|
||||||
@ -434,11 +432,11 @@ impl Network {
|
|||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_local_port(&self, protocol_type: ProtocolType) -> Option<u16> {
|
pub fn get_local_port(&self, _protocol_type: ProtocolType) -> Option<u16> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_preferred_local_address(&self, dial_info: &DialInfo) -> Option<SocketAddr> {
|
pub fn get_preferred_local_address(&self, _dial_info: &DialInfo) -> Option<SocketAddr> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,7 +454,7 @@ impl Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_protocol_config(&self) -> ProtocolConfig {
|
pub fn get_protocol_config(&self) -> ProtocolConfig {
|
||||||
self.inner.lock().protocol_config.clone()
|
self.inner.lock().protocol_config
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
@ -19,7 +19,7 @@ impl ProtocolNetworkConnection {
|
|||||||
timeout_ms: u32,
|
timeout_ms: u32,
|
||||||
address_filter: AddressFilter,
|
address_filter: AddressFilter,
|
||||||
) -> io::Result<NetworkResult<ProtocolNetworkConnection>> {
|
) -> io::Result<NetworkResult<ProtocolNetworkConnection>> {
|
||||||
if address_filter.is_ip_addr_punished(dial_info.address().to_ip_addr()) {
|
if address_filter.is_ip_addr_punished(dial_info.address().ip_addr()) {
|
||||||
return Ok(NetworkResult::no_connection_other("punished"));
|
return Ok(NetworkResult::no_connection_other("punished"));
|
||||||
}
|
}
|
||||||
match dial_info.protocol_type() {
|
match dial_info.protocol_type() {
|
||||||
|
@ -56,7 +56,7 @@ impl WebsocketNetworkConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn descriptor(&self) -> ConnectionDescriptor {
|
pub fn descriptor(&self) -> ConnectionDescriptor {
|
||||||
self.descriptor.clone()
|
self.descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[instrument(level = "trace", err, skip(self))]
|
// #[instrument(level = "trace", err, skip(self))]
|
||||||
@ -144,7 +144,7 @@ impl WebsocketProtocolHandler {
|
|||||||
|
|
||||||
// Make our connection descriptor
|
// Make our connection descriptor
|
||||||
let wnc = WebsocketNetworkConnection::new(
|
let wnc = WebsocketNetworkConnection::new(
|
||||||
ConnectionDescriptor::new_no_local(dial_info.to_peer_address()),
|
ConnectionDescriptor::new_no_local(dial_info.peer_address()),
|
||||||
wsmeta,
|
wsmeta,
|
||||||
wsio,
|
wsio,
|
||||||
);
|
);
|
||||||
|
@ -399,8 +399,8 @@ impl RoutingDomainDetail for PublicInternetRoutingDomainDetail {
|
|||||||
dif_sort.clone()
|
dif_sort.clone()
|
||||||
) {
|
) {
|
||||||
// Ensure we aren't on the same public IP address (no hairpin nat)
|
// Ensure we aren't on the same public IP address (no hairpin nat)
|
||||||
if reverse_did.dial_info.to_ip_addr()
|
if reverse_did.dial_info.ip_addr()
|
||||||
!= target_did.dial_info.to_ip_addr()
|
!= target_did.dial_info.ip_addr()
|
||||||
{
|
{
|
||||||
// Can we receive a direct reverse connection?
|
// Can we receive a direct reverse connection?
|
||||||
if !reverse_did.class.requires_signal() {
|
if !reverse_did.class.requires_signal() {
|
||||||
@ -433,8 +433,8 @@ impl RoutingDomainDetail for PublicInternetRoutingDomainDetail {
|
|||||||
dif_sort.clone(),
|
dif_sort.clone(),
|
||||||
) {
|
) {
|
||||||
// Ensure we aren't on the same public IP address (no hairpin nat)
|
// Ensure we aren't on the same public IP address (no hairpin nat)
|
||||||
if reverse_udp_did.dial_info.to_ip_addr()
|
if reverse_udp_did.dial_info.ip_addr()
|
||||||
!= target_udp_did.dial_info.to_ip_addr()
|
!= target_udp_did.dial_info.ip_addr()
|
||||||
{
|
{
|
||||||
// The target and ourselves have a udp dialinfo that they can reach
|
// The target and ourselves have a udp dialinfo that they can reach
|
||||||
return ContactMethod::SignalHolePunch(
|
return ContactMethod::SignalHolePunch(
|
||||||
|
@ -22,7 +22,12 @@ impl RPCOperationWatchValueQ {
|
|||||||
watcher: PublicKey,
|
watcher: PublicKey,
|
||||||
signature: Signature,
|
signature: Signature,
|
||||||
) -> Result<Self, RPCError> {
|
) -> Result<Self, RPCError> {
|
||||||
if subkeys.len() > MAX_WATCH_VALUE_Q_SUBKEYS_LEN {
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
let subkeys_len = subkeys.len() as usize;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
let subkeys_len = subkeys.len();
|
||||||
|
|
||||||
|
if subkeys_len > MAX_WATCH_VALUE_Q_SUBKEYS_LEN {
|
||||||
return Err(RPCError::protocol("WatchValueQ subkeys length too long"));
|
return Err(RPCError::protocol("WatchValueQ subkeys length too long"));
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@ -37,8 +42,12 @@ impl RPCOperationWatchValueQ {
|
|||||||
|
|
||||||
// signature covers: key, subkeys, expiration, count, using watcher key
|
// signature covers: key, subkeys, expiration, count, using watcher key
|
||||||
fn make_signature_data(&self) -> Vec<u8> {
|
fn make_signature_data(&self) -> Vec<u8> {
|
||||||
let mut sig_data =
|
#[cfg(target_arch = "wasm32")]
|
||||||
Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (self.subkeys.len() * 8) + 8 + 4);
|
let subkeys_len = self.subkeys.len() as usize;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
let subkeys_len = self.subkeys.len();
|
||||||
|
|
||||||
|
let mut sig_data = Vec::with_capacity(PUBLIC_KEY_LENGTH + 4 + (subkeys_len * 8) + 8 + 4);
|
||||||
sig_data.extend_from_slice(&self.key.kind.0);
|
sig_data.extend_from_slice(&self.key.kind.0);
|
||||||
sig_data.extend_from_slice(&self.key.value.bytes);
|
sig_data.extend_from_slice(&self.key.value.bytes);
|
||||||
for sk in self.subkeys.ranges() {
|
for sk in self.subkeys.ranges() {
|
||||||
|
@ -70,7 +70,7 @@ pub async fn test_protected_store(ps: ProtectedStore) {
|
|||||||
assert_eq!(ps.load_user_secret("_test_broken").await.unwrap(), None);
|
assert_eq!(ps.load_user_secret("_test_broken").await.unwrap(), None);
|
||||||
assert_eq!(ps.load_user_secret("_test_broken").await.unwrap(), None);
|
assert_eq!(ps.load_user_secret("_test_broken").await.unwrap(), None);
|
||||||
assert!(ps.remove_user_secret("_test_key").await.unwrap());
|
assert!(ps.remove_user_secret("_test_key").await.unwrap());
|
||||||
assert!(ps.remove_user_secret("_test_key").await.unwrap());
|
assert!(!ps.remove_user_secret("_test_key").await.unwrap());
|
||||||
assert!(!ps.remove_user_secret("_test_key").await.unwrap());
|
assert!(!ps.remove_user_secret("_test_key").await.unwrap());
|
||||||
assert!(!ps.remove_user_secret("_test_broken").await.unwrap());
|
assert!(!ps.remove_user_secret("_test_broken").await.unwrap());
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ cfg_if! {
|
|||||||
|
|
||||||
pub fn get_timestamp() -> u64 {
|
pub fn get_timestamp() -> u64 {
|
||||||
if is_browser() {
|
if is_browser() {
|
||||||
return (Date::now() * 1000.0f64) as u64;
|
(Date::now() * 1000.0f64) as u64
|
||||||
} else {
|
} else {
|
||||||
panic!("WASM requires browser environment");
|
panic!("WASM requires browser environment");
|
||||||
}
|
}
|
||||||
@ -23,28 +23,34 @@ cfg_if! {
|
|||||||
let show_month = show_year || now.get_utc_month() != date.get_utc_month();
|
let show_month = show_year || now.get_utc_month() != date.get_utc_month();
|
||||||
let show_date = show_month || now.get_utc_date() != date.get_utc_date();
|
let show_date = show_month || now.get_utc_date() != date.get_utc_date();
|
||||||
|
|
||||||
|
let s_year = if show_year {
|
||||||
|
format!("{:04}/",date.get_utc_full_year())
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
};
|
||||||
|
let s_month = if show_month {
|
||||||
|
format!("{:02}/",date.get_utc_month())
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
};
|
||||||
|
let s_date = if show_date {
|
||||||
|
format!("{:02}-",date.get_utc_date())
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
};
|
||||||
|
let s_time = format!("{:02}:{:02}:{:02}.{:04}",
|
||||||
|
date.get_utc_hours(),
|
||||||
|
date.get_utc_minutes(),
|
||||||
|
date.get_utc_seconds(),
|
||||||
|
date.get_utc_milliseconds()
|
||||||
|
);
|
||||||
|
|
||||||
format!("{}{}{}{}",
|
format!("{}{}{}{}",
|
||||||
if show_year {
|
s_year,
|
||||||
format!("{:04}/",date.get_utc_full_year())
|
s_month,
|
||||||
} else {
|
s_date,
|
||||||
"".to_owned()
|
s_time
|
||||||
},
|
)
|
||||||
if show_month {
|
|
||||||
format!("{:02}/",date.get_utc_month())
|
|
||||||
} else {
|
|
||||||
"".to_owned()
|
|
||||||
},
|
|
||||||
if show_date {
|
|
||||||
format!("{:02}-",date.get_utc_date())
|
|
||||||
} else {
|
|
||||||
"".to_owned()
|
|
||||||
},
|
|
||||||
format!("{:02}:{:02}:{:02}.{:04}",
|
|
||||||
date.get_utc_hours(),
|
|
||||||
date.get_utc_minutes(),
|
|
||||||
date.get_utc_seconds(),
|
|
||||||
date.get_utc_milliseconds()
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
panic!("WASM requires browser environment");
|
panic!("WASM requires browser environment");
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ pub fn is_browser() -> bool {
|
|||||||
return cache != 0;
|
return cache != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = Reflect::has(&global().as_ref(), &"navigator".into()).unwrap_or_default();
|
let res = Reflect::has(global().as_ref(), &"navigator".into()).unwrap_or_default();
|
||||||
|
|
||||||
CACHE.store(res as i8, Ordering::Relaxed);
|
CACHE.store(res as i8, Ordering::Relaxed);
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ pub fn is_browser_https() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_wasm_global_string_value<K: AsRef<str>>(key: K) -> Option<String> {
|
pub fn get_wasm_global_string_value<K: AsRef<str>>(key: K) -> Option<String> {
|
||||||
let Ok(v) = Reflect::get(&global().as_ref(), &JsValue::from_str(key.as_ref())) else {
|
let Ok(v) = Reflect::get(global().as_ref(), &JsValue::from_str(key.as_ref())) else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
v.as_string()
|
v.as_string()
|
||||||
|
@ -79,7 +79,7 @@ pub fn unmarshall(b64: String) -> APIResult<Vec<u8>> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn marshall(data: &Vec<u8>) -> String {
|
pub fn marshall(data: &[u8]) -> String {
|
||||||
data_encoding::BASE64URL_NOPAD.encode(data)
|
data_encoding::BASE64URL_NOPAD.encode(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ where
|
|||||||
F: Future<Output = APIResult<T>> + 'static,
|
F: Future<Output = APIResult<T>> + 'static,
|
||||||
T: Serialize + Debug + 'static,
|
T: Serialize + Debug + 'static,
|
||||||
{
|
{
|
||||||
future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(|e| to_json(e))))
|
future_to_promise(future.map(|res| res.map(|v| to_json(v)).map_err(to_json)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wrap_api_future_plain<F, T>(future: F) -> Promise
|
pub fn wrap_api_future_plain<F, T>(future: F) -> Promise
|
||||||
@ -125,14 +125,14 @@ where
|
|||||||
JsValue: From<T>,
|
JsValue: From<T>,
|
||||||
T: 'static,
|
T: 'static,
|
||||||
{
|
{
|
||||||
future_to_promise(future.map(|res| res.map(|v| to_jsvalue(v)).map_err(|e| to_json(e))))
|
future_to_promise(future.map(|res| res.map(|v| to_jsvalue(v)).map_err(to_json)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wrap_api_future_void<F>(future: F) -> Promise
|
pub fn wrap_api_future_void<F>(future: F) -> Promise
|
||||||
where
|
where
|
||||||
F: Future<Output = APIResult<()>> + 'static,
|
F: Future<Output = APIResult<()>> + 'static,
|
||||||
{
|
{
|
||||||
future_to_promise(future.map(|res| res.map(|_| JsValue::UNDEFINED).map_err(|e| to_json(e))))
|
future_to_promise(future.map(|res| res.map(|_| JsValue::UNDEFINED).map_err(to_json)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
@ -340,7 +340,7 @@ pub fn release_routing_context(id: u32) -> i32 {
|
|||||||
if rc.remove(&id).is_none() {
|
if rc.remove(&id).is_none() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -352,8 +352,7 @@ pub fn routing_context_with_privacy(id: u32) -> u32 {
|
|||||||
let Ok(routing_context) = routing_context.clone().with_privacy() else {
|
let Ok(routing_context) = routing_context.clone().with_privacy() else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let new_id = add_routing_context(routing_context);
|
add_routing_context(routing_context)
|
||||||
new_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -371,8 +370,7 @@ pub fn routing_context_with_custom_privacy(id: u32, safety_selection: String) ->
|
|||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let new_id = add_routing_context(routing_context);
|
add_routing_context(routing_context)
|
||||||
new_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -384,8 +382,7 @@ pub fn routing_context_with_sequencing(id: u32, sequencing: String) -> u32 {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let routing_context = routing_context.clone().with_sequencing(sequencing);
|
let routing_context = routing_context.clone().with_sequencing(sequencing);
|
||||||
let new_id = add_routing_context(routing_context);
|
add_routing_context(routing_context)
|
||||||
new_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -561,7 +558,7 @@ pub fn routing_context_get_dht_value(
|
|||||||
pub fn routing_context_set_dht_value(id: u32, key: String, subkey: u32, data: String) -> Promise {
|
pub fn routing_context_set_dht_value(id: u32, key: String, subkey: u32, data: String) -> Promise {
|
||||||
let key: veilid_core::TypedKey = veilid_core::deserialize_json(&key).unwrap();
|
let key: veilid_core::TypedKey = veilid_core::deserialize_json(&key).unwrap();
|
||||||
let data: Vec<u8> = data_encoding::BASE64URL_NOPAD
|
let data: Vec<u8> = data_encoding::BASE64URL_NOPAD
|
||||||
.decode(&data.as_bytes())
|
.decode(data.as_bytes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
wrap_api_future_json(async move {
|
wrap_api_future_json(async move {
|
||||||
@ -741,7 +738,7 @@ pub fn release_table_db(id: u32) -> i32 {
|
|||||||
if tdbs.remove(&id).is_none() {
|
if tdbs.remove(&id).is_none() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -766,7 +763,7 @@ pub fn table_db_get_column_count(id: u32) -> u32 {
|
|||||||
let Ok(cc) = table_db.clone().get_column_count() else {
|
let Ok(cc) = table_db.clone().get_column_count() else {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
return cc;
|
cc
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -810,8 +807,7 @@ pub fn table_db_transact(id: u32) -> u32 {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let tdbt = table_db.clone().transact();
|
let tdbt = table_db.clone().transact();
|
||||||
let tdbtid = add_table_db_transaction(tdbt);
|
add_table_db_transaction(tdbt)
|
||||||
return tdbtid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
@ -820,7 +816,7 @@ pub fn release_table_db_transaction(id: u32) -> i32 {
|
|||||||
if tdbts.remove(&id).is_none() {
|
if tdbts.remove(&id).is_none() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen()]
|
#[wasm_bindgen()]
|
||||||
|
@ -163,12 +163,11 @@ impl VeilidClient {
|
|||||||
/// Return the cargo package version of veilid-core, in object format.
|
/// Return the cargo package version of veilid-core, in object format.
|
||||||
pub fn version() -> VeilidVersion {
|
pub fn version() -> VeilidVersion {
|
||||||
let (major, minor, patch) = veilid_core::veilid_version();
|
let (major, minor, patch) = veilid_core::veilid_version();
|
||||||
let vv = super::VeilidVersion {
|
super::VeilidVersion {
|
||||||
major,
|
major,
|
||||||
minor,
|
minor,
|
||||||
patch,
|
patch,
|
||||||
};
|
}
|
||||||
vv
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the cargo package version of veilid-core, in string format.
|
/// Return the cargo package version of veilid-core, in string format.
|
||||||
|
@ -411,7 +411,7 @@ impl VeilidCrypto {
|
|||||||
veilid_core::SharedSecret::from_str(&shared_secret)?;
|
veilid_core::SharedSecret::from_str(&shared_secret)?;
|
||||||
|
|
||||||
let associated_data = associated_data
|
let associated_data = associated_data
|
||||||
.map(|ad| unmarshall(ad))
|
.map(unmarshall)
|
||||||
.map_or(APIResult::Ok(None), |r| r.map(Some))?;
|
.map_or(APIResult::Ok(None), |r| r.map(Some))?;
|
||||||
|
|
||||||
let veilid_api = get_veilid_api()?;
|
let veilid_api = get_veilid_api()?;
|
||||||
@ -453,7 +453,7 @@ impl VeilidCrypto {
|
|||||||
veilid_core::SharedSecret::from_str(&shared_secret)?;
|
veilid_core::SharedSecret::from_str(&shared_secret)?;
|
||||||
|
|
||||||
let associated_data: Option<Vec<u8>> = associated_data
|
let associated_data: Option<Vec<u8>> = associated_data
|
||||||
.map(|ad| unmarshall(ad))
|
.map(unmarshall)
|
||||||
.map_or(APIResult::Ok(None), |r| r.map(Some))?;
|
.map_or(APIResult::Ok(None), |r| r.map(Some))?;
|
||||||
|
|
||||||
let veilid_api = get_veilid_api()?;
|
let veilid_api = get_veilid_api()?;
|
||||||
|
@ -23,7 +23,9 @@ impl VeilidTableDB {
|
|||||||
|
|
||||||
fn getTableDB(&self) -> APIResult<TableDB> {
|
fn getTableDB(&self) -> APIResult<TableDB> {
|
||||||
let Some(table_db) = &self.inner_table_db else {
|
let Some(table_db) = &self.inner_table_db else {
|
||||||
return APIResult::Err(veilid_core::VeilidAPIError::generic("Unable to getTableDB instance. Ensure you've called openTable()."));
|
return APIResult::Err(veilid_core::VeilidAPIError::generic(
|
||||||
|
"Unable to getTableDB instance. Ensure you've called openTable().",
|
||||||
|
));
|
||||||
};
|
};
|
||||||
APIResult::Ok(table_db.clone())
|
APIResult::Ok(table_db.clone())
|
||||||
}
|
}
|
||||||
@ -140,7 +142,9 @@ impl VeilidTableDBTransaction {
|
|||||||
|
|
||||||
fn getTransaction(&self) -> APIResult<TableDBTransaction> {
|
fn getTransaction(&self) -> APIResult<TableDBTransaction> {
|
||||||
let Some(transaction) = &self.inner_transaction else {
|
let Some(transaction) = &self.inner_transaction else {
|
||||||
return APIResult::Err(veilid_core::VeilidAPIError::generic("Unable to getTransaction instance. inner_transaction is None."));
|
return APIResult::Err(veilid_core::VeilidAPIError::generic(
|
||||||
|
"Unable to getTransaction instance. inner_transaction is None.",
|
||||||
|
));
|
||||||
};
|
};
|
||||||
APIResult::Ok(transaction.clone())
|
APIResult::Ok(transaction.clone())
|
||||||
}
|
}
|
||||||
@ -174,3 +178,9 @@ impl VeilidTableDBTransaction {
|
|||||||
transaction.delete(col, &key)
|
transaction.delete(col, &key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for VeilidTableDBTransaction {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user