Skip to content

Commit 510a03c

Browse files
authored
Merge pull request #30 from CoLearn-Dev/local_registry
- local registry - fix update_registries
2 parents 34631fa + 0059670 commit 510a03c

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "colink"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55
description = "CoLink Rust SDK"
66
license = "MIT"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CoLink SDK helps both application adnd protocol developers access the functional
99
Add this to your Cargo.toml:
1010
```toml
1111
[dependencies]
12-
colink = "0.2.1"
12+
colink = "0.2.3"
1313
```
1414

1515
## Getting Started

examples/protocol_greetings_with_instant_server.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![allow(unused_variables)]
2-
use colink::{extensions::instant_server::InstantServer, CoLink, Participant, ProtocolEntry};
2+
use colink::{
3+
extensions::instant_server::{InstantRegistry, InstantServer},
4+
CoLink, Participant, ProtocolEntry,
5+
};
36

47
struct Initiator;
58
#[colink::async_trait]
@@ -33,6 +36,8 @@ impl ProtocolEntry for Receiver {
3336

3437
#[tokio::main]
3538
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
39+
let ir = InstantRegistry::new().await;
40+
// The instant server will automatically use the instant registry when there is one.
3641
let is0 = InstantServer::new();
3742
let is1 = InstantServer::new();
3843
let cl0 = is0.get_colink().switch_to_generated_user().await?;

src/extensions/instant_server.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{utils::get_colink_home, CoLink};
22
use rand::Rng;
33
use std::{
4+
fs::File,
45
path::Path,
56
process::{Child, Command, Stdio},
67
};
@@ -103,3 +104,32 @@ impl InstantServer {
103104
CoLink::new(&format!("http://127.0.0.1:{}", self.port), &self.host_token)
104105
}
105106
}
107+
108+
pub struct InstantRegistry {
109+
_instant_server: InstantServer,
110+
}
111+
112+
impl Drop for InstantRegistry {
113+
fn drop(&mut self) {
114+
let colink_home = get_colink_home().unwrap();
115+
let registry_file = Path::new(&colink_home).join("reg_config");
116+
std::fs::remove_file(&registry_file).unwrap();
117+
}
118+
}
119+
120+
impl InstantRegistry {
121+
pub async fn new() -> Self {
122+
let is = InstantServer::new();
123+
let colink_home = get_colink_home().unwrap();
124+
let registry_file = Path::new(&colink_home).join("reg_config");
125+
let _file = File::options()
126+
.write(true)
127+
.create_new(true)
128+
.open(&registry_file)
129+
.unwrap();
130+
is.get_colink().switch_to_generated_user().await.unwrap();
131+
Self {
132+
_instant_server: is,
133+
}
134+
}
135+
}

src/extensions/registry.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ impl crate::application::CoLink {
1515
}];
1616
let mut payload = vec![];
1717
registries.encode(&mut payload).unwrap();
18-
self.run_task("registry", &payload, &participants, false)
18+
let task_id = self
19+
.run_task("registry", &payload, &participants, false)
1920
.await?;
21+
self.wait_task(&task_id).await?;
2022
Ok(())
2123
}
2224
}

0 commit comments

Comments
 (0)