mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-01-21 20:21:07 -05:00
removing dev branch, many changes
This commit is contained in:
parent
1430f3f656
commit
0a890c8707
1843
Cargo.lock
generated
1843
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,4 @@
|
||||
[workspace]
|
||||
|
||||
members = [
|
||||
"veilid-tools",
|
||||
"veilid-core",
|
||||
|
@ -23,13 +23,15 @@ logging:
|
||||
enabled: false
|
||||
level: 'trace'
|
||||
grpc_endpoint: 'localhost:4317'
|
||||
console:
|
||||
enabled: false
|
||||
testing:
|
||||
subnode_index: 0
|
||||
core:
|
||||
protected_store:
|
||||
allow_insecure_fallback: true
|
||||
always_use_insecure_storage: true
|
||||
insecure_fallback_directory: '%INSECURE_FALLBACK_DIRECTORY%'
|
||||
directory: '%DIRECTORY%'
|
||||
delete: false
|
||||
table_store:
|
||||
directory: '%TABLE_STORE_DIRECTORY%'
|
||||
@ -47,10 +49,10 @@ core:
|
||||
client_whitelist_timeout_ms: 300000
|
||||
reverse_connection_receipt_time_ms: 5000
|
||||
hole_punch_receipt_time_ms: 5000
|
||||
node_id: ''
|
||||
node_id_secret: ''
|
||||
bootstrap: ['bootstrap.dev.veilid.net']
|
||||
routing_table:
|
||||
node_id: null
|
||||
node_id_secret: null
|
||||
bootstrap: ['bootstrap.dev.veilid.net']
|
||||
limit_over_attached: 64
|
||||
limit_fully_attached: 32
|
||||
limit_attached_strong: 16
|
||||
@ -61,27 +63,31 @@ core:
|
||||
queue_size: 1024
|
||||
max_timestamp_behind_ms: 10000
|
||||
max_timestamp_ahead_ms: 10000
|
||||
timeout_ms: 10000
|
||||
timeout_ms: 5000
|
||||
max_route_hop_count: 4
|
||||
default_route_hop_count: 1
|
||||
|
||||
dht:
|
||||
resolve_node_timeout:
|
||||
resolve_node_count: 20
|
||||
resolve_node_fanout: 3
|
||||
max_find_node_count: 20
|
||||
get_value_timeout:
|
||||
get_value_count: 20
|
||||
get_value_fanout: 3
|
||||
set_value_timeout:
|
||||
set_value_count: 20
|
||||
set_value_fanout: 5
|
||||
resolve_node_timeout_ms: 10000
|
||||
resolve_node_count: 1
|
||||
resolve_node_fanout: 4
|
||||
get_value_timeout_ms: 10000
|
||||
get_value_count: 3
|
||||
get_value_fanout: 4
|
||||
set_value_timeout_ms: 10000
|
||||
set_value_count: 5
|
||||
set_value_fanout: 4
|
||||
min_peer_count: 20
|
||||
min_peer_refresh_time_ms: 2000
|
||||
validate_dial_info_receipt_time_ms: 2000
|
||||
local_subkey_cache_size: 128
|
||||
local_max_subkey_cache_memory_mb: 256
|
||||
remote_subkey_cache_size: 1024
|
||||
remote_max_records: 65536
|
||||
remote_max_subkey_cache_memory_mb: %REMOTE_MAX_SUBKEY_CACHE_MEMORY_MB%
|
||||
remote_max_storage_space_mb: 0
|
||||
upnp: true
|
||||
detect_address_changes: true
|
||||
enable_local_peer_scope: false
|
||||
restricted_nat_retries: 0
|
||||
tls:
|
||||
certificate_path: '%CERTIFICATE_PATH%'
|
||||
@ -123,5 +129,4 @@ core:
|
||||
max_connections: 16
|
||||
listen_address: ':5150'
|
||||
path: 'ws'
|
||||
# url: ''
|
||||
|
||||
# url: ''
|
@ -155,7 +155,7 @@ testing:
|
||||
protected_store:
|
||||
allow_insecure_fallback: true
|
||||
always_use_insecure_storage: true
|
||||
insecure_fallback_directory: '%INSECURE_FALLBACK_DIRECTORY%'
|
||||
directory: '%DIRECTORY%'
|
||||
delete: false
|
||||
```
|
||||
|
||||
@ -225,7 +225,7 @@ rpc:
|
||||
queue_size: 1024
|
||||
max_timestamp_behind_ms: 10000
|
||||
max_timestamp_ahead_ms: 10000
|
||||
timeout_ms: 10000
|
||||
timeout_ms: 5000
|
||||
max_route_hop_count: 4
|
||||
default_route_hop_count: 1
|
||||
```
|
||||
@ -234,19 +234,25 @@ rpc:
|
||||
|
||||
```yaml
|
||||
dht:
|
||||
resolve_node_timeout:
|
||||
resolve_node_count: 20
|
||||
resolve_node_fanout: 3
|
||||
max_find_node_count: 20
|
||||
get_value_timeout:
|
||||
get_value_count: 20
|
||||
get_value_fanout: 3
|
||||
set_value_timeout:
|
||||
set_value_count: 20
|
||||
set_value_fanout: 5
|
||||
resolve_node_timeout_ms: 10000
|
||||
resolve_node_count: 1
|
||||
resolve_node_fanout: 4
|
||||
get_value_timeout_ms: 10000
|
||||
get_value_count: 3
|
||||
get_value_fanout: 4
|
||||
set_value_timeout_ms: 10000
|
||||
set_value_count: 5
|
||||
set_value_fanout: 4
|
||||
min_peer_count: 20
|
||||
min_peer_refresh_time_ms: 2000
|
||||
validate_dial_info_receipt_time_ms: 2000
|
||||
local_subkey_cache_size: 128
|
||||
local_max_subkey_cache_memory_mb: 256
|
||||
remote_subkey_cache_size: 1024
|
||||
remote_max_records: 65536
|
||||
remote_max_subkey_cache_memory_mb: %REMOTE_MAX_SUBKEY_CACHE_MEMORY_MB%
|
||||
remote_max_storage_space_mb: 0
|
||||
```
|
||||
|
||||
#### core:network:tls
|
||||
|
2
external/keyvaluedb
vendored
2
external/keyvaluedb
vendored
@ -1 +1 @@
|
||||
Subproject commit 3408e0b2ae3df0088e0714bc23fb33c82a58e22c
|
||||
Subproject commit 9bb05a54b4c0278a289841b2bf7c1749aa0fbd5d
|
@ -14,7 +14,7 @@ logging:
|
||||
enabled: false
|
||||
core:
|
||||
protected_store:
|
||||
insecure_fallback_directory: '/var/db/veilid-server/protected_store'
|
||||
directory: '/var/db/veilid-server/protected_store'
|
||||
table_store:
|
||||
directory: '/var/db/veilid-server/table_store'
|
||||
block_store:
|
||||
|
@ -57,7 +57,7 @@ do
|
||||
HOMEBREW_DIR=$(dirname `which brew`)
|
||||
fi
|
||||
|
||||
env -i PATH=/usr/bin:/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH
|
||||
env -i PATH=/usr/bin:/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" IPHONEOS_DEPLOYMENT_TARGET="$IPHONEOS_DEPLOYMENT_TARGET" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH
|
||||
|
||||
LIPOS="$LIPOS $TARGET_PATH/$CARGO_TARGET/$BUILD_MODE/lib$PACKAGE_NAME.a"
|
||||
|
||||
|
@ -47,7 +47,7 @@ do
|
||||
HOMEBREW_DIR=$(dirname `which brew`)
|
||||
fi
|
||||
|
||||
env -i PATH=/usr/bin:/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH
|
||||
env -i PATH=/usr/bin:/bin:$HOMEBREW_DIR:$CARGO_DIR HOME="$HOME" USER="$USER" MACOSX_DEPLOYMENT_TARGET="$MACOSX_DEPLOYMENT_TARGET" cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH
|
||||
|
||||
LIPOS="$LIPOS $TARGET_PATH/$CARGO_TARGET/$BUILD_MODE/lib$PACKAGE_NAME.dylib"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
ID=$(xcrun simctl create test-iphone com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro com.apple.CoreSimulator.SimRuntime.iOS-16-1 2>/dev/null)
|
||||
RUNTIME=$(xcrun simctl runtime list -j | jq '.[].runtimeIdentifier' -r | head -1)
|
||||
ID=$(xcrun simctl create test-iphone com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro $RUNTIME 2>/dev/null)
|
||||
xcrun simctl boot $ID
|
||||
xcrun simctl bootstatus $ID
|
||||
echo Simulator ID is $ID
|
||||
|
@ -122,5 +122,5 @@ if [ "$BREW_USER" == "" ]; then
|
||||
BREW_USER=`whoami`
|
||||
fi
|
||||
fi
|
||||
sudo -H -u $BREW_USER brew install capnp cmake wabt llvm protobuf openjdk@11
|
||||
sudo -H -u $BREW_USER brew install capnp cmake wabt llvm protobuf openjdk@11 jq
|
||||
sudo gem install cocoapods
|
||||
|
@ -38,7 +38,7 @@ cfg-if = "^1"
|
||||
capnp = "^0"
|
||||
capnp-rpc = "^0"
|
||||
config = { version = "^0", features = ["yaml"] }
|
||||
bugsalot = "^0"
|
||||
bugsalot = { git = "https://github.com/crioux/bugsalot.git" }
|
||||
flexi_logger = { version = "^0", features = ["use_chrono_for_offset"] }
|
||||
thiserror = "^1"
|
||||
crossbeam-channel = "^0"
|
||||
|
@ -38,7 +38,7 @@ fn map_to_internal_error<T: ToString>(e: T) -> VeilidAPIError {
|
||||
|
||||
fn decode_api_result<T: DeserializeOwned + fmt::Debug>(
|
||||
reader: &api_result::Reader,
|
||||
) -> Result<T, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<T> {
|
||||
match reader.which().map_err(map_to_internal_error)? {
|
||||
api_result::Which::Ok(v) => {
|
||||
let ok_val = v.map_err(map_to_internal_error)?;
|
||||
@ -92,7 +92,7 @@ impl veilid_client::Server for VeilidClientImpl {
|
||||
VeilidUpdate::Config(config) => {
|
||||
self.comproc.update_config(config);
|
||||
}
|
||||
VeilidUpdate::Route(route) => {
|
||||
VeilidUpdate::RouteChange(route) => {
|
||||
self.comproc.update_route(route);
|
||||
}
|
||||
VeilidUpdate::Shutdown => self.comproc.update_shutdown(),
|
||||
@ -355,7 +355,7 @@ impl ClientApiConnection {
|
||||
.map_err(map_to_string)?
|
||||
.get_result()
|
||||
.map_err(map_to_string)?;
|
||||
let res: Result<(), VeilidAPIError> = decode_api_result(&reader);
|
||||
let res: VeilidAPIResult<()> = decode_api_result(&reader);
|
||||
res.map_err(map_to_string)
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ impl ClientApiConnection {
|
||||
.map_err(map_to_string)?
|
||||
.get_result()
|
||||
.map_err(map_to_string)?;
|
||||
let res: Result<(), VeilidAPIError> = decode_api_result(&reader);
|
||||
let res: VeilidAPIResult<()> = decode_api_result(&reader);
|
||||
res.map_err(map_to_string)
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ impl ClientApiConnection {
|
||||
.map_err(map_to_string)?
|
||||
.get_result()
|
||||
.map_err(map_to_string)?;
|
||||
let res: Result<String, VeilidAPIError> = decode_api_result(&reader);
|
||||
let res: VeilidAPIResult<String> = decode_api_result(&reader);
|
||||
res.map_err(map_to_string)
|
||||
}
|
||||
|
||||
@ -453,7 +453,7 @@ impl ClientApiConnection {
|
||||
.map_err(map_to_string)?
|
||||
.get_result()
|
||||
.map_err(map_to_string)?;
|
||||
let res: Result<(), VeilidAPIError> = decode_api_result(&reader);
|
||||
let res: VeilidAPIResult<()> = decode_api_result(&reader);
|
||||
res.map_err(map_to_string)
|
||||
}
|
||||
|
||||
@ -483,7 +483,7 @@ impl ClientApiConnection {
|
||||
.map_err(map_to_string)?
|
||||
.get_result()
|
||||
.map_err(map_to_string)?;
|
||||
let res: Result<(), VeilidAPIError> = decode_api_result(&reader);
|
||||
let res: VeilidAPIResult<()> = decode_api_result(&reader);
|
||||
res.map_err(map_to_string)
|
||||
}
|
||||
|
||||
|
@ -406,7 +406,7 @@ reply - reply to an AppCall not handled directly by the server
|
||||
pub fn update_config(&mut self, config: veilid_core::VeilidStateConfig) {
|
||||
self.inner_mut().ui.set_config(config.config)
|
||||
}
|
||||
pub fn update_route(&mut self, route: veilid_core::VeilidStateRoute) {
|
||||
pub fn update_route(&mut self, route: veilid_core::VeilidRouteChange) {
|
||||
let mut out = String::new();
|
||||
if !route.dead_routes.is_empty() {
|
||||
out.push_str(&format!("Dead routes: {:?}", route.dead_routes));
|
||||
@ -445,46 +445,46 @@ reply - reply to an AppCall not handled directly by the server
|
||||
pub fn update_app_message(&mut self, msg: veilid_core::VeilidAppMessage) {
|
||||
// check is message body is ascii printable
|
||||
let mut printable = true;
|
||||
for c in &msg.message {
|
||||
for c in msg.message() {
|
||||
if *c < 32 || *c > 126 {
|
||||
printable = false;
|
||||
}
|
||||
}
|
||||
|
||||
let strmsg = if printable {
|
||||
String::from_utf8_lossy(&msg.message).to_string()
|
||||
String::from_utf8_lossy(msg.message()).to_string()
|
||||
} else {
|
||||
hex::encode(&msg.message)
|
||||
hex::encode(msg.message())
|
||||
};
|
||||
|
||||
self.inner()
|
||||
.ui
|
||||
.add_node_event(format!("AppMessage ({:?}): {}", msg.sender, strmsg));
|
||||
.add_node_event(format!("AppMessage ({:?}): {}", msg.sender(), strmsg));
|
||||
}
|
||||
|
||||
pub fn update_app_call(&mut self, call: veilid_core::VeilidAppCall) {
|
||||
// check is message body is ascii printable
|
||||
let mut printable = true;
|
||||
for c in &call.message {
|
||||
for c in call.message() {
|
||||
if *c < 32 || *c > 126 {
|
||||
printable = false;
|
||||
}
|
||||
}
|
||||
|
||||
let strmsg = if printable {
|
||||
String::from_utf8_lossy(&call.message).to_string()
|
||||
String::from_utf8_lossy(call.message()).to_string()
|
||||
} else {
|
||||
format!("#{}", hex::encode(&call.message))
|
||||
format!("#{}", hex::encode(call.message()))
|
||||
};
|
||||
|
||||
self.inner().ui.add_node_event(format!(
|
||||
"AppCall ({:?}) id = {:016x} : {}",
|
||||
call.sender,
|
||||
call.id.as_u64(),
|
||||
call.sender(),
|
||||
call.id().as_u64(),
|
||||
strmsg
|
||||
));
|
||||
|
||||
self.inner_mut().last_call_id = Some(call.id);
|
||||
self.inner_mut().last_call_id = Some(call.id());
|
||||
}
|
||||
|
||||
pub fn update_shutdown(&mut self) {
|
||||
|
@ -53,13 +53,9 @@ impl TableViewItem<PeerTableColumn> for PeerTableData {
|
||||
PeerTableColumn::NodeId => self
|
||||
.node_ids
|
||||
.first()
|
||||
.cloned()
|
||||
.map(|n| n.to_string())
|
||||
.unwrap_or_else(|| "???".to_owned()),
|
||||
PeerTableColumn::Address => format!(
|
||||
"{:?}:{}",
|
||||
self.peer_address.protocol_type(),
|
||||
self.peer_address.to_socket_addr()
|
||||
),
|
||||
PeerTableColumn::Address => self.peer_address.clone(),
|
||||
PeerTableColumn::LatencyAvg => format!(
|
||||
"{}",
|
||||
self.peer_stats
|
||||
|
@ -10,13 +10,14 @@ license = "LGPL-2.0-or-later OR MPL-2.0 OR (MIT AND BSD-3-Clause)"
|
||||
crate-type = ["cdylib", "staticlib", "rlib"]
|
||||
|
||||
[features]
|
||||
default = [ "enable-crypto-vld0" ]
|
||||
crypto-test = [ "enable-crypto-vld0", "enable-crypto-none" ]
|
||||
crypto-test-none = [ "enable-crypto-none" ]
|
||||
default = ["enable-crypto-vld0"]
|
||||
crypto-test = ["enable-crypto-vld0", "enable-crypto-none"]
|
||||
crypto-test-none = ["enable-crypto-none"]
|
||||
enable-crypto-vld0 = []
|
||||
enable-crypto-none = []
|
||||
rt-async-std = ["async-std", "async-std-resolver", "async_executors/async_std", "rtnetlink?/smol_socket", "veilid-tools/rt-async-std"]
|
||||
rt-tokio = ["tokio", "tokio-util", "tokio-stream", "trust-dns-resolver/tokio-runtime", "async_executors/tokio_tp", "async_executors/tokio_io", "async_executors/tokio_timer", "rtnetlink?/tokio_socket", "veilid-tools/rt-tokio"]
|
||||
rt-wasm-bindgen = ["veilid-tools/rt-wasm-bindgen", "async_executors/bindgen"]
|
||||
|
||||
veilid_core_android_tests = ["dep:paranoid-android"]
|
||||
veilid_core_ios_tests = ["dep:tracing-oslog"]
|
||||
@ -65,11 +66,11 @@ rtnetlink = { version = "^0", default-features = false, optional = true }
|
||||
async-std-resolver = { version = "^0", optional = true }
|
||||
trust-dns-resolver = { version = "^0", optional = true }
|
||||
keyvaluedb = { path = "../external/keyvaluedb/keyvaluedb" }
|
||||
#rkyv = { version = "^0", default_features = false, features = ["std", "alloc", "strict", "size_32", "validation"] }
|
||||
rkyv = { git = "https://github.com/rkyv/rkyv.git", rev = "57e2a8d", default_features = false, features = ["std", "alloc", "strict", "size_32", "validation"] }
|
||||
bytecheck = "^0"
|
||||
rkyv = { version = "^0", default_features = false, features = ["std", "alloc", "strict", "size_32", "validation"] }
|
||||
data-encoding = { version = "^2" }
|
||||
weak-table = "0.3.2"
|
||||
range-set-blaze = "0.1.5"
|
||||
argon2 = "0.5.0"
|
||||
|
||||
# Dependencies for native builds only
|
||||
# Linux, Windows, Mac, iOS, Android
|
||||
@ -91,8 +92,8 @@ rustls = "^0.19"
|
||||
rustls-pemfile = "^0.2"
|
||||
futures-util = { version = "^0", default-features = false, features = ["async-await", "sink", "std", "io"] }
|
||||
keyvaluedb-sqlite = { path = "../external/keyvaluedb/keyvaluedb-sqlite" }
|
||||
socket2 = "^0"
|
||||
bugsalot = "^0"
|
||||
socket2 = { version = "^0", features = ["all"] }
|
||||
bugsalot = { git = "https://github.com/crioux/bugsalot.git" }
|
||||
chrono = "^0"
|
||||
libc = "^0"
|
||||
nix = "^0"
|
||||
|
@ -27,13 +27,12 @@ struct Nonce24 @0xb6260db25d8d7dfc {
|
||||
u2 @2 :UInt64;
|
||||
}
|
||||
|
||||
using PublicKey = Key256; # Node id / DHT key / Route id, etc
|
||||
using PublicKey = Key256; # Node id / Hash / DHT key / Route id, etc
|
||||
using Nonce = Nonce24; # One-time encryption nonce
|
||||
using Signature = Signature512; # Signature block
|
||||
using TunnelID = UInt64; # Id for tunnels
|
||||
using CryptoKind = UInt32; # FOURCC code for cryptography type
|
||||
using ValueSeqNum = UInt32; # sequence numbers for values
|
||||
using ValueSchema = UInt32; # FOURCC code for schema (0 = freeform, SUB0 = subkey control v0)
|
||||
using Subkey = UInt32; # subkey index for dht
|
||||
|
||||
struct TypedKey @0xe2d567a9f1e61b29 {
|
||||
@ -312,47 +311,66 @@ struct OperationAppMessage @0x9baf542d81b411f5 {
|
||||
message @0 :Data; # opaque message to application
|
||||
}
|
||||
|
||||
struct SubkeyRange {
|
||||
struct SubkeyRange @0xf592dac0a4d0171c {
|
||||
start @0 :Subkey; # the start of a subkey range
|
||||
end @1 :Subkey; # the end of a subkey range
|
||||
}
|
||||
|
||||
struct ValueData @0xb4b7416f169f2a3d {
|
||||
|
||||
struct SignedValueData @0xb4b7416f169f2a3d {
|
||||
seq @0 :ValueSeqNum; # sequence number of value
|
||||
schema @1 :ValueSchema; # fourcc code of schema for value
|
||||
data @2 :Data; # value or subvalue contents
|
||||
data @1 :Data; # value or subvalue contents
|
||||
writer @2 :PublicKey; # the public key of the writer
|
||||
signature @3 :Signature; # signature of data at this subkey, using the writer key (which may be the same as the owner key)
|
||||
# signature covers:
|
||||
# * ownerKey
|
||||
# * subkey
|
||||
# * sequence number
|
||||
# * data
|
||||
# signature does not need to cover schema because schema is validated upon every set
|
||||
# so the data either fits, or it doesn't.
|
||||
}
|
||||
|
||||
struct SignedValueDescriptor @0xe7911cd3f9e1b0e7 {
|
||||
owner @0 :PublicKey; # the public key of the owner
|
||||
schemaData @1 :Data; # the schema data
|
||||
# Changing this after key creation is not supported as it would change the dht key
|
||||
signature @2 :Signature; # Schema data is signed by ownerKey and is verified both by set and get operations
|
||||
}
|
||||
|
||||
|
||||
struct OperationGetValueQ @0xf88a5b6da5eda5d0 {
|
||||
key @0 :TypedKey; # the location of the value
|
||||
subkey @1 :Subkey; # the index of the subkey (0 for the default subkey)
|
||||
key @0 :TypedKey; # DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
|
||||
subkey @1 :Subkey; # the index of the subkey
|
||||
wantDescriptor @2 :Bool; # whether or not to include the descriptor for the key
|
||||
}
|
||||
|
||||
|
||||
struct OperationGetValueA @0xd896bb46f2e0249f {
|
||||
union {
|
||||
data @0 :ValueData; # the value if successful
|
||||
peers @1 :List(PeerInfo); # returned 'closer peer' information if not successful
|
||||
}
|
||||
value @0 :SignedValueData; # optional: the value if successful, or if unset, no value returned
|
||||
peers @1 :List(PeerInfo); # returned 'closer peer' information on either success or failure
|
||||
descriptor @2 :SignedValueDescriptor; # optional: the descriptor if requested if the value is also returned
|
||||
}
|
||||
|
||||
struct OperationSetValueQ @0xbac06191ff8bdbc5 {
|
||||
key @0 :TypedKey; # the location of the value
|
||||
subkey @1 :Subkey; # the index of the subkey (0 for the default subkey)
|
||||
value @2 :ValueData; # value or subvalue contents (older or equal seq number gets dropped)
|
||||
struct OperationSetValueQ @0xbac06191ff8bdbc5 {
|
||||
key @0 :TypedKey; # DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
|
||||
subkey @1 :Subkey; # the index of the subkey
|
||||
value @2 :SignedValueData; # value or subvalue contents (older or equal seq number gets dropped)
|
||||
descriptor @3 :SignedValueDescriptor; # optional: the descriptor if needed
|
||||
}
|
||||
|
||||
struct OperationSetValueA @0x9378d0732dc95be2 {
|
||||
union {
|
||||
data @0 :ValueData; # the new value if successful, may be a different value than what was set if the seq number was lower or equal
|
||||
peers @1 :List(PeerInfo); # returned 'closer peer' information if not successful
|
||||
}
|
||||
set @0 :Bool; # true if the set was close enough to be set
|
||||
value @1 :SignedValueData; # optional: the current value at the key if the set seq number was lower or equal to what was there before
|
||||
peers @2 :List(PeerInfo); # returned 'closer peer' information on either success or failure
|
||||
}
|
||||
|
||||
struct OperationWatchValueQ @0xf9a5a6c547b9b228 {
|
||||
key @0 :TypedKey; # key for value to watch
|
||||
subkeys @1 :List(SubkeyRange); # subkey range to watch, if empty, watch everything
|
||||
subkeys @1 :List(SubkeyRange); # subkey range to watch (up to 512 subranges), if empty, watch everything
|
||||
expiration @2 :UInt64; # requested timestamp when this watch will expire in usec since epoch (can be return less, 0 for max)
|
||||
count @3 :UInt32; # requested number of changes to watch for (0 = cancel, 1 = single shot, 2+ = counter, UINT32_MAX = continuous)
|
||||
watcher @4 :PublicKey; # the watcher performing the watch, can be the owner or a schema member
|
||||
signature @5 :Signature; # signature of the watcher, must be one of the schema members or the key owner. signature covers: key, subkeys, expiration, count
|
||||
}
|
||||
|
||||
struct OperationWatchValueA @0xa726cab7064ba893 {
|
||||
@ -364,7 +382,7 @@ struct OperationValueChanged @0xd1c59ebdd8cc1bf6 {
|
||||
key @0 :TypedKey; # key for value that changed
|
||||
subkeys @1 :List(SubkeyRange); # subkey range that changed (up to 512 ranges at a time)
|
||||
count @2 :UInt32; # remaining changes left (0 means watch has expired)
|
||||
value @3 :ValueData; # first value that changed (the rest can be gotten with getvalue)
|
||||
value @3 :SignedValueData; # first value that changed (the rest can be gotten with getvalue)
|
||||
}
|
||||
|
||||
struct OperationSupplyBlockQ @0xadbf4c542d749971 {
|
||||
@ -372,10 +390,8 @@ struct OperationSupplyBlockQ @0xadbf4c542d749971 {
|
||||
}
|
||||
|
||||
struct OperationSupplyBlockA @0xf003822e83b5c0d7 {
|
||||
union {
|
||||
expiration @0 :UInt64; # when the block supplier entry will need to be refreshed
|
||||
peers @1 :List(PeerInfo); # returned 'closer peer' information if not successful
|
||||
}
|
||||
expiration @0 :UInt64; # when the block supplier entry will need to be refreshed, or 0 if not successful
|
||||
peers @1 :List(PeerInfo); # returned 'closer peer' information if not successful
|
||||
}
|
||||
|
||||
struct OperationFindBlockQ @0xaf4353ff004c7156 {
|
||||
|
@ -3,7 +3,7 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
pushd $SCRIPTDIR 2>/dev/null
|
||||
if [[ "$1" == "wasm" ]]; then
|
||||
WASM_BINDGEN_TEST_TIMEOUT=120 wasm-pack test --firefox --headless
|
||||
WASM_BINDGEN_TEST_TIMEOUT=120 wasm-pack test --firefox --headless --features=rt-wasm-bindgen
|
||||
elif [[ "$1" == "ios" ]]; then
|
||||
SYMROOT=/tmp/testout
|
||||
APPNAME=veilidcore-tests
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::crypto::Crypto;
|
||||
use crate::network_manager::*;
|
||||
use crate::routing_table::*;
|
||||
use crate::*;
|
||||
use crypto::Crypto;
|
||||
use network_manager::*;
|
||||
use routing_table::*;
|
||||
use storage_manager::*;
|
||||
|
||||
pub struct AttachmentManagerInner {
|
||||
last_attachment_state: AttachmentState,
|
||||
@ -26,6 +27,7 @@ pub struct AttachmentManager {
|
||||
impl AttachmentManager {
|
||||
fn new_unlocked_inner(
|
||||
config: VeilidConfig,
|
||||
storage_manager: StorageManager,
|
||||
protected_store: ProtectedStore,
|
||||
table_store: TableStore,
|
||||
block_store: BlockStore,
|
||||
@ -35,6 +37,7 @@ impl AttachmentManager {
|
||||
config: config.clone(),
|
||||
network_manager: NetworkManager::new(
|
||||
config,
|
||||
storage_manager,
|
||||
protected_store,
|
||||
table_store,
|
||||
block_store,
|
||||
@ -54,6 +57,7 @@ impl AttachmentManager {
|
||||
}
|
||||
pub fn new(
|
||||
config: VeilidConfig,
|
||||
storage_manager: StorageManager,
|
||||
protected_store: ProtectedStore,
|
||||
table_store: TableStore,
|
||||
block_store: BlockStore,
|
||||
@ -63,6 +67,7 @@ impl AttachmentManager {
|
||||
inner: Arc::new(Mutex::new(Self::new_inner())),
|
||||
unlocked_inner: Arc::new(Self::new_unlocked_inner(
|
||||
config,
|
||||
storage_manager,
|
||||
protected_store,
|
||||
table_store,
|
||||
block_store,
|
||||
|
@ -1,12 +1,16 @@
|
||||
use crate::api_tracing_layer::*;
|
||||
use crate::attachment_manager::*;
|
||||
use crate::crypto::Crypto;
|
||||
use crate::storage_manager::*;
|
||||
use crate::veilid_api::*;
|
||||
use crate::veilid_config::*;
|
||||
use crate::*;
|
||||
|
||||
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>;
|
||||
|
||||
/// Internal services startup mechanism
|
||||
/// Ensures that everything is started up, and shut down in the right order
|
||||
/// and provides an atomic state for if the system is properly operational
|
||||
struct ServicesContext {
|
||||
pub config: VeilidConfig,
|
||||
pub update_callback: UpdateCallback,
|
||||
@ -16,6 +20,7 @@ struct ServicesContext {
|
||||
pub block_store: Option<BlockStore>,
|
||||
pub crypto: Option<Crypto>,
|
||||
pub attachment_manager: Option<AttachmentManager>,
|
||||
pub storage_manager: Option<StorageManager>,
|
||||
}
|
||||
|
||||
impl ServicesContext {
|
||||
@ -28,6 +33,7 @@ impl ServicesContext {
|
||||
block_store: None,
|
||||
crypto: None,
|
||||
attachment_manager: None,
|
||||
storage_manager: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +45,7 @@ impl ServicesContext {
|
||||
block_store: BlockStore,
|
||||
crypto: Crypto,
|
||||
attachment_manager: AttachmentManager,
|
||||
storage_manager: StorageManager,
|
||||
) -> Self {
|
||||
Self {
|
||||
config,
|
||||
@ -48,6 +55,7 @@ impl ServicesContext {
|
||||
block_store: Some(block_store),
|
||||
crypto: Some(crypto),
|
||||
attachment_manager: Some(attachment_manager),
|
||||
storage_manager: Some(storage_manager),
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,15 +70,24 @@ impl ServicesContext {
|
||||
trace!("init protected store");
|
||||
let protected_store = ProtectedStore::new(self.config.clone());
|
||||
if let Err(e) = protected_store.init().await {
|
||||
error!("failed to init protected store: {}", e);
|
||||
self.shutdown().await;
|
||||
return Err(e);
|
||||
}
|
||||
self.protected_store = Some(protected_store.clone());
|
||||
|
||||
// Set up tablestore
|
||||
// Set up tablestore and crypto system
|
||||
trace!("create table store and crypto system");
|
||||
let table_store = TableStore::new(self.config.clone(), protected_store.clone());
|
||||
let crypto = Crypto::new(self.config.clone(), table_store.clone());
|
||||
table_store.set_crypto(crypto.clone());
|
||||
|
||||
// Initialize table store first, so crypto code can load caches
|
||||
// Tablestore can use crypto during init, just not any cached operations or things
|
||||
// that require flushing back to the tablestore
|
||||
trace!("init table store");
|
||||
let table_store = TableStore::new(self.config.clone());
|
||||
if let Err(e) = table_store.init().await {
|
||||
error!("failed to init table store: {}", e);
|
||||
self.shutdown().await;
|
||||
return Err(e);
|
||||
}
|
||||
@ -78,12 +95,8 @@ impl ServicesContext {
|
||||
|
||||
// Set up crypto
|
||||
trace!("init crypto");
|
||||
let crypto = Crypto::new(
|
||||
self.config.clone(),
|
||||
table_store.clone(),
|
||||
protected_store.clone(),
|
||||
);
|
||||
if let Err(e) = crypto.init().await {
|
||||
error!("failed to init crypto: {}", e);
|
||||
self.shutdown().await;
|
||||
return Err(e);
|
||||
}
|
||||
@ -93,22 +106,41 @@ impl ServicesContext {
|
||||
trace!("init block store");
|
||||
let block_store = BlockStore::new(self.config.clone());
|
||||
if let Err(e) = block_store.init().await {
|
||||
error!("failed to init block store: {}", e);
|
||||
self.shutdown().await;
|
||||
return Err(e);
|
||||
}
|
||||
self.block_store = Some(block_store.clone());
|
||||
|
||||
// Set up storage manager
|
||||
trace!("init storage manager");
|
||||
let storage_manager = StorageManager::new(
|
||||
self.config.clone(),
|
||||
self.crypto.clone().unwrap(),
|
||||
self.protected_store.clone().unwrap(),
|
||||
self.table_store.clone().unwrap(),
|
||||
self.block_store.clone().unwrap(),
|
||||
);
|
||||
if let Err(e) = storage_manager.init().await {
|
||||
error!("failed to init storage manager: {}", e);
|
||||
self.shutdown().await;
|
||||
return Err(e);
|
||||
}
|
||||
self.storage_manager = Some(storage_manager.clone());
|
||||
|
||||
// Set up attachment manager
|
||||
trace!("init attachment manager");
|
||||
let update_callback = self.update_callback.clone();
|
||||
let attachment_manager = AttachmentManager::new(
|
||||
self.config.clone(),
|
||||
storage_manager,
|
||||
protected_store,
|
||||
table_store,
|
||||
block_store,
|
||||
crypto,
|
||||
);
|
||||
if let Err(e) = attachment_manager.init(update_callback).await {
|
||||
error!("failed to init attachment manager: {}", e);
|
||||
self.shutdown().await;
|
||||
return Err(e);
|
||||
}
|
||||
@ -126,6 +158,10 @@ impl ServicesContext {
|
||||
trace!("terminate attachment manager");
|
||||
attachment_manager.terminate().await;
|
||||
}
|
||||
if let Some(storage_manager) = &mut self.storage_manager {
|
||||
trace!("terminate storage manager");
|
||||
storage_manager.terminate().await;
|
||||
}
|
||||
if let Some(block_store) = &mut self.block_store {
|
||||
trace!("terminate block store");
|
||||
block_store.terminate().await;
|
||||
@ -159,6 +195,7 @@ pub struct VeilidCoreContext {
|
||||
pub config: VeilidConfig,
|
||||
pub update_callback: UpdateCallback,
|
||||
// Services
|
||||
pub storage_manager: StorageManager,
|
||||
pub protected_store: ProtectedStore,
|
||||
pub table_store: TableStore,
|
||||
pub block_store: BlockStore,
|
||||
@ -171,7 +208,7 @@ impl VeilidCoreContext {
|
||||
async fn new_with_config_callback(
|
||||
update_callback: UpdateCallback,
|
||||
config_callback: ConfigCallback,
|
||||
) -> Result<VeilidCoreContext, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<VeilidCoreContext> {
|
||||
// Set up config from callback
|
||||
trace!("setup config with callback");
|
||||
let mut config = VeilidConfig::new();
|
||||
@ -184,7 +221,7 @@ impl VeilidCoreContext {
|
||||
async fn new_with_config_json(
|
||||
update_callback: UpdateCallback,
|
||||
config_json: String,
|
||||
) -> Result<VeilidCoreContext, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<VeilidCoreContext> {
|
||||
// Set up config from callback
|
||||
trace!("setup config with json");
|
||||
let mut config = VeilidConfig::new();
|
||||
@ -196,7 +233,7 @@ impl VeilidCoreContext {
|
||||
async fn new_common(
|
||||
update_callback: UpdateCallback,
|
||||
config: VeilidConfig,
|
||||
) -> Result<VeilidCoreContext, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<VeilidCoreContext> {
|
||||
cfg_if! {
|
||||
if #[cfg(target_os = "android")] {
|
||||
if !crate::intf::android::is_android_ready() {
|
||||
@ -209,8 +246,9 @@ impl VeilidCoreContext {
|
||||
sc.startup().await.map_err(VeilidAPIError::generic)?;
|
||||
|
||||
Ok(VeilidCoreContext {
|
||||
update_callback: sc.update_callback,
|
||||
config: sc.config,
|
||||
update_callback: sc.update_callback,
|
||||
storage_manager: sc.storage_manager.unwrap(),
|
||||
protected_store: sc.protected_store.unwrap(),
|
||||
table_store: sc.table_store.unwrap(),
|
||||
block_store: sc.block_store.unwrap(),
|
||||
@ -229,6 +267,7 @@ impl VeilidCoreContext {
|
||||
self.block_store,
|
||||
self.crypto,
|
||||
self.attachment_manager,
|
||||
self.storage_manager,
|
||||
);
|
||||
sc.shutdown().await;
|
||||
}
|
||||
@ -244,7 +283,7 @@ lazy_static::lazy_static! {
|
||||
pub async fn api_startup(
|
||||
update_callback: UpdateCallback,
|
||||
config_callback: ConfigCallback,
|
||||
) -> Result<VeilidAPI, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<VeilidAPI> {
|
||||
// See if we have an API started up already
|
||||
let mut initialized_lock = INITIALIZED.lock().await;
|
||||
if *initialized_lock {
|
||||
@ -267,7 +306,7 @@ pub async fn api_startup(
|
||||
pub async fn api_startup_json(
|
||||
update_callback: UpdateCallback,
|
||||
config_json: String,
|
||||
) -> Result<VeilidAPI, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<VeilidAPI> {
|
||||
// See if we have an API started up already
|
||||
let mut initialized_lock = INITIALIZED.lock().await;
|
||||
if *initialized_lock {
|
||||
|
@ -7,22 +7,26 @@ use core::hash::Hash;
|
||||
|
||||
use data_encoding::BASE64URL_NOPAD;
|
||||
|
||||
use rkyv::{Archive as RkyvArchive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Length of a public key in bytes
|
||||
/// Length of a crypto key in bytes
|
||||
#[allow(dead_code)]
|
||||
pub const PUBLIC_KEY_LENGTH: usize = 32;
|
||||
/// Length of a public key in bytes after encoding to base64url
|
||||
pub const CRYPTO_KEY_LENGTH: usize = 32;
|
||||
/// Length of a crypto key in bytes after encoding to base64url
|
||||
#[allow(dead_code)]
|
||||
pub const PUBLIC_KEY_LENGTH_ENCODED: usize = 43;
|
||||
pub const CRYPTO_KEY_LENGTH_ENCODED: usize = 43;
|
||||
/// Length of a crypto key in bytes
|
||||
#[allow(dead_code)]
|
||||
pub const PUBLIC_KEY_LENGTH: usize = CRYPTO_KEY_LENGTH;
|
||||
/// Length of a crypto key in bytes after encoding to base64url
|
||||
#[allow(dead_code)]
|
||||
pub const PUBLIC_KEY_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
|
||||
/// Length of a secret key in bytes
|
||||
#[allow(dead_code)]
|
||||
pub const SECRET_KEY_LENGTH: usize = 32;
|
||||
pub const SECRET_KEY_LENGTH: usize = CRYPTO_KEY_LENGTH;
|
||||
/// Length of a secret key in bytes after encoding to base64url
|
||||
#[allow(dead_code)]
|
||||
pub const SECRET_KEY_LENGTH_ENCODED: usize = 43;
|
||||
pub const SECRET_KEY_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
|
||||
/// Length of a signature in bytes
|
||||
#[allow(dead_code)]
|
||||
pub const SIGNATURE_LENGTH: usize = 64;
|
||||
@ -37,16 +41,22 @@ pub const NONCE_LENGTH: usize = 24;
|
||||
pub const NONCE_LENGTH_ENCODED: usize = 32;
|
||||
/// Length of a shared secret in bytes
|
||||
#[allow(dead_code)]
|
||||
pub const SHARED_SECRET_LENGTH: usize = 32;
|
||||
pub const SHARED_SECRET_LENGTH: usize = CRYPTO_KEY_LENGTH;
|
||||
/// Length of a shared secret in bytes after encoding to base64url
|
||||
#[allow(dead_code)]
|
||||
pub const SHARED_SECRET_LENGTH_ENCODED: usize = 43;
|
||||
pub const SHARED_SECRET_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
|
||||
/// Length of a route id in bytes
|
||||
#[allow(dead_code)]
|
||||
pub const ROUTE_ID_LENGTH: usize = 32;
|
||||
pub const ROUTE_ID_LENGTH: usize = CRYPTO_KEY_LENGTH;
|
||||
/// Length of a route id in bytes afer encoding to base64url
|
||||
#[allow(dead_code)]
|
||||
pub const ROUTE_ID_LENGTH_ENCODED: usize = 43;
|
||||
pub const ROUTE_ID_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
|
||||
/// Length of a hash digest in bytes
|
||||
#[allow(dead_code)]
|
||||
pub const HASH_DIGEST_LENGTH: usize = CRYPTO_KEY_LENGTH;
|
||||
/// Length of a hash digest in bytes after encoding to base64url
|
||||
#[allow(dead_code)]
|
||||
pub const HASH_DIGEST_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -56,11 +66,11 @@ where
|
||||
{
|
||||
fn encode(&self) -> String;
|
||||
fn encoded_len() -> usize;
|
||||
fn try_decode<S: AsRef<str>>(input: S) -> Result<Self, VeilidAPIError> {
|
||||
fn try_decode<S: AsRef<str>>(input: S) -> VeilidAPIResult<Self> {
|
||||
let b = input.as_ref().as_bytes();
|
||||
Self::try_decode_bytes(b)
|
||||
}
|
||||
fn try_decode_bytes(b: &[u8]) -> Result<Self, VeilidAPIError>;
|
||||
fn try_decode_bytes(b: &[u8]) -> VeilidAPIResult<Self>;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -120,18 +130,6 @@ macro_rules! byte_array_type {
|
||||
Self { bytes }
|
||||
}
|
||||
|
||||
pub fn try_from_vec(v: Vec<u8>) -> Result<Self, VeilidAPIError> {
|
||||
let vl = v.len();
|
||||
Ok(Self {
|
||||
bytes: v.try_into().map_err(|_| {
|
||||
VeilidAPIError::generic(format!(
|
||||
"Expected a Vec of length {} but it was {}",
|
||||
$size, vl
|
||||
))
|
||||
})?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn bit(&self, index: usize) -> bool {
|
||||
assert!(index < ($size * 8));
|
||||
let bi = index / 8;
|
||||
@ -182,7 +180,7 @@ macro_rules! byte_array_type {
|
||||
fn encoded_len() -> usize {
|
||||
$encoded_size
|
||||
}
|
||||
fn try_decode_bytes(b: &[u8]) -> Result<Self, VeilidAPIError> {
|
||||
fn try_decode_bytes(b: &[u8]) -> VeilidAPIResult<Self> {
|
||||
let mut bytes = [0u8; $size];
|
||||
let res = BASE64URL_NOPAD.decode_len(b.len());
|
||||
match res {
|
||||
@ -244,23 +242,47 @@ macro_rules! byte_array_type {
|
||||
Self::try_decode(value)
|
||||
}
|
||||
}
|
||||
impl TryFrom<&[u8]> for $name {
|
||||
type Error = VeilidAPIError;
|
||||
fn try_from(v: &[u8]) -> Result<Self, Self::Error> {
|
||||
let vl = v.len();
|
||||
Ok(Self {
|
||||
bytes: v.try_into().map_err(|_| {
|
||||
VeilidAPIError::generic(format!(
|
||||
"Expected a slice of length {} but it was {}",
|
||||
$size, vl
|
||||
))
|
||||
})?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::Deref for $name {
|
||||
type Target = [u8; $size];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.bytes
|
||||
}
|
||||
}
|
||||
|
||||
impl core::ops::DerefMut for $name {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.bytes
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
|
||||
byte_array_type!(PublicKey, PUBLIC_KEY_LENGTH, PUBLIC_KEY_LENGTH_ENCODED);
|
||||
byte_array_type!(SecretKey, SECRET_KEY_LENGTH, SECRET_KEY_LENGTH_ENCODED);
|
||||
byte_array_type!(CryptoKey, CRYPTO_KEY_LENGTH, CRYPTO_KEY_LENGTH_ENCODED);
|
||||
|
||||
pub type PublicKey = CryptoKey;
|
||||
pub type SecretKey = CryptoKey;
|
||||
pub type HashDigest = CryptoKey;
|
||||
pub type SharedSecret = CryptoKey;
|
||||
pub type RouteId = CryptoKey;
|
||||
pub type CryptoKeyDistance = CryptoKey;
|
||||
|
||||
byte_array_type!(Signature, SIGNATURE_LENGTH, SIGNATURE_LENGTH_ENCODED);
|
||||
byte_array_type!(
|
||||
PublicKeyDistance,
|
||||
PUBLIC_KEY_LENGTH,
|
||||
PUBLIC_KEY_LENGTH_ENCODED
|
||||
);
|
||||
byte_array_type!(Nonce, NONCE_LENGTH, NONCE_LENGTH_ENCODED);
|
||||
byte_array_type!(
|
||||
SharedSecret,
|
||||
SHARED_SECRET_LENGTH,
|
||||
SHARED_SECRET_LENGTH_ENCODED
|
||||
);
|
||||
byte_array_type!(RouteId, ROUTE_ID_LENGTH, ROUTE_ID_LENGTH_ENCODED);
|
||||
|
@ -6,52 +6,36 @@ pub trait CryptoSystem {
|
||||
fn crypto(&self) -> Crypto;
|
||||
|
||||
// Cached Operations
|
||||
fn cached_dh(
|
||||
&self,
|
||||
key: &PublicKey,
|
||||
secret: &SecretKey,
|
||||
) -> Result<SharedSecret, VeilidAPIError>;
|
||||
fn cached_dh(&self, key: &PublicKey, secret: &SecretKey) -> VeilidAPIResult<SharedSecret>;
|
||||
|
||||
// Generation
|
||||
fn random_bytes(&self, len: u32) -> Vec<u8>;
|
||||
fn default_salt_length(&self) -> u32;
|
||||
fn hash_password(&self, password: &[u8], salt: &[u8]) -> VeilidAPIResult<String>;
|
||||
fn verify_password(&self, password: &[u8], password_hash: &str) -> VeilidAPIResult<bool>;
|
||||
fn derive_shared_secret(&self, password: &[u8], salt: &[u8]) -> VeilidAPIResult<SharedSecret>;
|
||||
fn random_nonce(&self) -> Nonce;
|
||||
fn random_shared_secret(&self) -> SharedSecret;
|
||||
fn compute_dh(
|
||||
&self,
|
||||
key: &PublicKey,
|
||||
secret: &SecretKey,
|
||||
) -> Result<SharedSecret, VeilidAPIError>;
|
||||
fn compute_dh(&self, key: &PublicKey, secret: &SecretKey) -> VeilidAPIResult<SharedSecret>;
|
||||
fn generate_keypair(&self) -> KeyPair;
|
||||
fn generate_hash(&self, data: &[u8]) -> PublicKey;
|
||||
fn generate_hash_reader(
|
||||
&self,
|
||||
reader: &mut dyn std::io::Read,
|
||||
) -> Result<PublicKey, VeilidAPIError>;
|
||||
fn generate_hash(&self, data: &[u8]) -> HashDigest;
|
||||
fn generate_hash_reader(&self, reader: &mut dyn std::io::Read) -> VeilidAPIResult<HashDigest>;
|
||||
|
||||
// Validation
|
||||
fn validate_keypair(&self, dht_key: &PublicKey, dht_key_secret: &SecretKey) -> bool;
|
||||
fn validate_hash(&self, data: &[u8], dht_key: &PublicKey) -> bool;
|
||||
fn validate_keypair(&self, key: &PublicKey, secret: &SecretKey) -> bool;
|
||||
fn validate_hash(&self, data: &[u8], hash: &HashDigest) -> bool;
|
||||
fn validate_hash_reader(
|
||||
&self,
|
||||
reader: &mut dyn std::io::Read,
|
||||
key: &PublicKey,
|
||||
) -> Result<bool, VeilidAPIError>;
|
||||
hash: &HashDigest,
|
||||
) -> VeilidAPIResult<bool>;
|
||||
|
||||
// Distance Metric
|
||||
fn distance(&self, key1: &PublicKey, key2: &PublicKey) -> PublicKeyDistance;
|
||||
fn distance(&self, key1: &CryptoKey, key2: &CryptoKey) -> CryptoKeyDistance;
|
||||
|
||||
// Authentication
|
||||
fn sign(
|
||||
&self,
|
||||
key: &PublicKey,
|
||||
secret: &SecretKey,
|
||||
data: &[u8],
|
||||
) -> Result<Signature, VeilidAPIError>;
|
||||
fn verify(
|
||||
&self,
|
||||
key: &PublicKey,
|
||||
data: &[u8],
|
||||
signature: &Signature,
|
||||
) -> Result<(), VeilidAPIError>;
|
||||
fn sign(&self, key: &PublicKey, secret: &SecretKey, data: &[u8]) -> VeilidAPIResult<Signature>;
|
||||
fn verify(&self, key: &PublicKey, data: &[u8], signature: &Signature) -> VeilidAPIResult<()>;
|
||||
|
||||
// AEAD Encrypt/Decrypt
|
||||
fn aead_overhead(&self) -> usize;
|
||||
@ -61,53 +45,53 @@ pub trait CryptoSystem {
|
||||
nonce: &Nonce,
|
||||
shared_secret: &SharedSecret,
|
||||
associated_data: Option<&[u8]>,
|
||||
) -> Result<(), VeilidAPIError>;
|
||||
) -> VeilidAPIResult<()>;
|
||||
fn decrypt_aead(
|
||||
&self,
|
||||
body: &[u8],
|
||||
nonce: &Nonce,
|
||||
shared_secret: &SharedSecret,
|
||||
associated_data: Option<&[u8]>,
|
||||
) -> Result<Vec<u8>, VeilidAPIError>;
|
||||
) -> VeilidAPIResult<Vec<u8>>;
|
||||
fn encrypt_in_place_aead(
|
||||
&self,
|
||||
body: &mut Vec<u8>,
|
||||
nonce: &Nonce,
|
||||
shared_secret: &SharedSecret,
|
||||
associated_data: Option<&[u8]>,
|
||||
) -> Result<(), VeilidAPIError>;
|
||||
) -> VeilidAPIResult<()>;
|
||||
fn encrypt_aead(
|
||||
&self,
|
||||
body: &[u8],
|
||||
nonce: &Nonce,
|
||||
shared_secret: &SharedSecret,
|
||||
associated_data: Option<&[u8]>,
|
||||
) -> Result<Vec<u8>, VeilidAPIError>;
|
||||
) -> VeilidAPIResult<Vec<u8>>;
|
||||
|
||||
// NoAuth Encrypt/Decrypt
|
||||
fn crypt_in_place_no_auth(
|
||||
&self,
|
||||
body: &mut Vec<u8>,
|
||||
nonce: &Nonce,
|
||||
body: &mut [u8],
|
||||
nonce: &[u8; NONCE_LENGTH],
|
||||
shared_secret: &SharedSecret,
|
||||
);
|
||||
fn crypt_b2b_no_auth(
|
||||
&self,
|
||||
in_buf: &[u8],
|
||||
out_buf: &mut [u8],
|
||||
nonce: &Nonce,
|
||||
nonce: &[u8; NONCE_LENGTH],
|
||||
shared_secret: &SharedSecret,
|
||||
);
|
||||
fn crypt_no_auth_aligned_8(
|
||||
&self,
|
||||
body: &[u8],
|
||||
nonce: &Nonce,
|
||||
nonce: &[u8; NONCE_LENGTH],
|
||||
shared_secret: &SharedSecret,
|
||||
) -> Vec<u8>;
|
||||
fn crypt_no_auth_unaligned(
|
||||
&self,
|
||||
body: &[u8],
|
||||
nonce: &Nonce,
|
||||
nonce: &[u8; NONCE_LENGTH],
|
||||
shared_secret: &SharedSecret,
|
||||
) -> Vec<u8>;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ impl Envelope {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_signed_data(crypto: Crypto, data: &[u8]) -> Result<Envelope, VeilidAPIError> {
|
||||
pub fn from_signed_data(crypto: Crypto, data: &[u8]) -> VeilidAPIResult<Envelope> {
|
||||
// Ensure we are at least the length of the envelope
|
||||
// Silent drop here, as we use zero length packets as part of the protocol for hole punching
|
||||
if data.len() < MIN_ENVELOPE_SIZE {
|
||||
@ -175,7 +175,7 @@ impl Envelope {
|
||||
crypto: Crypto,
|
||||
data: &[u8],
|
||||
node_id_secret: &SecretKey,
|
||||
) -> Result<Vec<u8>, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<Vec<u8>> {
|
||||
// Get DH secret
|
||||
let vcrypto = crypto
|
||||
.get(self.crypto_kind)
|
||||
@ -183,8 +183,11 @@ impl Envelope {
|
||||
let dh_secret = vcrypto.cached_dh(&self.sender_id, node_id_secret)?;
|
||||
|
||||
// Decrypt message without authentication
|
||||
let body =
|
||||
vcrypto.crypt_no_auth_aligned_8(&data[0x6A..data.len() - 64], &self.nonce, &dh_secret);
|
||||
let body = vcrypto.crypt_no_auth_aligned_8(
|
||||
&data[0x6A..data.len() - 64],
|
||||
&self.nonce.bytes,
|
||||
&dh_secret,
|
||||
);
|
||||
|
||||
Ok(body)
|
||||
}
|
||||
@ -194,7 +197,7 @@ impl Envelope {
|
||||
crypto: Crypto,
|
||||
body: &[u8],
|
||||
node_id_secret: &SecretKey,
|
||||
) -> Result<Vec<u8>, VeilidAPIError> {
|
||||
) -> VeilidAPIResult<Vec<u8>> {
|
||||
// Ensure body isn't too long
|
||||
let envelope_size: usize = body.len() + MIN_ENVELOPE_SIZE;
|
||||
if envelope_size > MAX_ENVELOPE_SIZE {
|
||||
@ -227,7 +230,7 @@ impl Envelope {
|
||||
data[0x4A..0x6A].copy_from_slice(&self.recipient_id.bytes);
|
||||
|
||||
// Encrypt and authenticate message
|
||||
let encrypted_body = vcrypto.crypt_no_auth_unaligned(body, &self.nonce, &dh_secret);
|
||||
let encrypted_body = vcrypto.crypt_no_auth_unaligned(body, &self.nonce.bytes, &dh_secret);
|
||||
|
||||
// Write body
|
||||
if !encrypted_body.is_empty() {
|
||||
|
@ -4,7 +4,6 @@ mod dh_cache;
|
||||
mod envelope;
|
||||
mod receipt;
|
||||
mod types;
|
||||
mod value;
|
||||
|
||||
pub mod crypto_system;
|
||||
#[cfg(feature = "enable-crypto-none")]
|
||||
@ -20,7 +19,6 @@ pub use dh_cache::*;
|
||||
pub use envelope::*;
|
||||
pub use receipt::*;
|
||||
pub use types::*;
|
||||
pub use value::*;
|
||||
|
||||
#[cfg(feature = "enable-crypto-none")]
|
||||
pub use none::*;
|
||||
@ -84,7 +82,6 @@ struct CryptoInner {
|
||||
struct CryptoUnlockedInner {
|
||||
config: VeilidConfig,
|
||||
table_store: TableStore,
|
||||
protected_store: ProtectedStore,
|
||||
}
|
||||
|
||||
/// Crypto factory implementation
|
||||
@ -106,16 +103,11 @@ impl Crypto {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
config: VeilidConfig,
|
||||
table_store: TableStore,
|
||||
protected_store: ProtectedStore,
|
||||
) -> Self {
|
||||
pub fn new(config: VeilidConfig, table_store: TableStore) -> Self {
|
||||
let out = Self {
|
||||
unlocked_inner: Arc::new(CryptoUnlockedInner {
|
||||
config,
|
||||
table_store,
|
||||
protected_store,
|
||||
}),
|
||||
inner: Arc::new(Mutex::new(Self::new_inner())),
|
||||
};
|
||||