Skip to content

Commit 1e7b486

Browse files
committed
local registry
1 parent 34631fa commit 1e7b486

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
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

+5-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::{InstantServer, LocalRegistry},
4+
CoLink, Participant, ProtocolEntry,
5+
};
36

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

3437
#[tokio::main]
3538
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
39+
let lr = LocalRegistry::new().await;
3640
let is0 = InstantServer::new();
3741
let is1 = InstantServer::new();
3842
let cl0 = is0.get_colink().switch_to_generated_user().await?;

src/extensions/instant_server.rs

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::{utils::get_colink_home, CoLink};
22
use rand::Rng;
33
use std::{
4+
fs::File,
5+
io::Write,
46
path::Path,
57
process::{Child, Command, Stdio},
68
};
@@ -103,3 +105,29 @@ impl InstantServer {
103105
CoLink::new(&format!("http://127.0.0.1:{}", self.port), &self.host_token)
104106
}
105107
}
108+
109+
pub struct LocalRegistry {
110+
_instant_server: InstantServer,
111+
}
112+
113+
impl Drop for LocalRegistry {
114+
fn drop(&mut self) {
115+
let colink_home = get_colink_home().unwrap();
116+
let registry_file = Path::new(&colink_home).join("registry.conf");
117+
std::fs::remove_file(&registry_file).unwrap();
118+
}
119+
}
120+
121+
impl LocalRegistry {
122+
pub async fn new() -> Self {
123+
let is = InstantServer::new();
124+
let colink_home = get_colink_home().unwrap();
125+
let registry_file = Path::new(&colink_home).join("registry.conf");
126+
let mut file = File::create(&registry_file).unwrap();
127+
file.write_all(b"new_registry").unwrap();
128+
is.get_colink().switch_to_generated_user().await.unwrap();
129+
Self {
130+
_instant_server: is,
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)