mirror of
https://github.com/fluencelabs/registry.git
synced 2025-04-25 10:12:13 +00:00
readme update (#4)
This commit is contained in:
parent
f2d98f1f8b
commit
8ae8678438
81
README.md
81
README.md
@ -1 +1,82 @@
|
|||||||
# aqua-dht
|
# aqua-dht
|
||||||
|
|
||||||
|
Repository demonstrating the how to start writing aqua and integrate it into a typescript application
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
- Install dependencies
|
||||||
|
|
||||||
|
```
|
||||||
|
rustup toolchain install nightly-2021-03-24-x86_64-unknown-linux-gnu
|
||||||
|
rustup default nightly-2021-03-24-x86_64-unknown-linux-gnu
|
||||||
|
rustup target add wasm32-wasi
|
||||||
|
cargo install +nightly marine
|
||||||
|
```
|
||||||
|
|
||||||
|
- To compile .wasm and generate aqua file
|
||||||
|
|
||||||
|
```
|
||||||
|
./build.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- To run tests
|
||||||
|
|
||||||
|
```
|
||||||
|
cargo test --release
|
||||||
|
```
|
||||||
|
|
||||||
|
- To deploy service
|
||||||
|
```
|
||||||
|
./deploy.sh
|
||||||
|
```
|
||||||
|
## Project structure
|
||||||
|
|
||||||
|
- Aqua source file is located in `aqua`directory.
|
||||||
|
|
||||||
|
- .wasm files are stored in `artifacts` directory.
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
Note: all timestamps should be passed as result of `("op" "timestamp_sec")` builtin call.
|
||||||
|
### Key methods
|
||||||
|
|
||||||
|
```~~~~
|
||||||
|
register_key(key: string, current_timestamp: u64)
|
||||||
|
get_key_metadata(key: string, current_timestamp: u64)
|
||||||
|
|
||||||
|
# used for replication
|
||||||
|
republish_key(key: Key, current_timestamp: u64)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Value methods
|
||||||
|
```
|
||||||
|
# key should already be registered, each peer_id has its own value for the key
|
||||||
|
put_value(key: string, value: string, current_timestamp: u64, relay_id: []string, service_id: []string)
|
||||||
|
put_value_relay(key: string, value: string, current_timestamp: u64, relay_id: string)
|
||||||
|
|
||||||
|
# return list of values for given key
|
||||||
|
get_values(key: string, current_timestamp: u64)
|
||||||
|
|
||||||
|
# used for replication
|
||||||
|
republish_values(key: string, records: []Record, current_timestamp: u64)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Other
|
||||||
|
```
|
||||||
|
# clear locally and return keys and values older than 1 hour for republishing
|
||||||
|
evict_stale(current_timestamp: u64)
|
||||||
|
|
||||||
|
# clear values and keys older than 24 hours
|
||||||
|
clear_expired(current_timestamp: u64)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
# this methods merge values and return the most recent
|
||||||
|
merge(records: [][]Record)
|
||||||
|
merge_two(a: []Record, b: []Record)
|
||||||
|
merge_wrapped(records: [][][]Record)
|
||||||
|
merge_hack(records: [][]Record, hack: string)
|
||||||
|
merge_hack_get_values(records: []GetValuesResult)
|
||||||
|
merge_hack_struct(records: RecordsStruct)
|
||||||
|
```
|
||||||
|
@ -102,6 +102,7 @@ fn get_key_metadata_helper(connection: &Connection, key: String, current_timesta
|
|||||||
fn update_key(connection: &Connection, key: String, peer_id: String, timestamp_created: u64, timestamp_accessed: u64) -> SqliteResult<()> {
|
fn update_key(connection: &Connection, key: String, peer_id: String, timestamp_created: u64, timestamp_accessed: u64) -> SqliteResult<()> {
|
||||||
let old_key = get_key_metadata_helper(&connection, key.clone(), timestamp_accessed);
|
let old_key = get_key_metadata_helper(&connection, key.clone(), timestamp_accessed);
|
||||||
|
|
||||||
|
// TODO: compare conflicting keys by timestamp_created
|
||||||
if old_key.is_err() || old_key?.peer_id == peer_id {
|
if old_key.is_err() || old_key?.peer_id == peer_id {
|
||||||
connection.execute(f!("
|
connection.execute(f!("
|
||||||
INSERT OR REPLACE INTO {KEYS_TABLE_NAME} VALUES ('{key}', '{timestamp_created}', '{timestamp_accessed}', '{peer_id}');
|
INSERT OR REPLACE INTO {KEYS_TABLE_NAME} VALUES ('{key}', '{timestamp_created}', '{timestamp_accessed}', '{peer_id}');
|
||||||
@ -199,6 +200,8 @@ pub fn republish_values_impl(key: String, records: Vec<Record>, current_timestam
|
|||||||
// checking key for existence
|
// checking key for existence
|
||||||
let _key = get_key_metadata_helper(&connection, key.clone(), current_timestamp.clone())?;
|
let _key = get_key_metadata_helper(&connection, key.clone(), current_timestamp.clone())?;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: compare conflicting values by timestamp_created
|
||||||
let mut updated = 0u64;
|
let mut updated = 0u64;
|
||||||
for record in records.iter() {
|
for record in records.iter() {
|
||||||
let relay_id = if record.relay_id.is_empty() {"".to_string()} else {record.relay_id[0].clone()};
|
let relay_id = if record.relay_id.is_empty() {"".to_string()} else {record.relay_id[0].clone()};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user