Skip to content

Commit

Permalink
Merge pull request #25 from CoLearn-Dev/request_info
Browse files Browse the repository at this point in the history
- request_core_info -> request_info
  • Loading branch information
stneng authored Oct 26, 2022
2 parents 06d2c28 + 8627047 commit e55f753
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 37 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ jobs:
run: cargo fmt --all -- --check
- name: Clippy test
run: cargo clippy --profile test -- -D warnings -D clippy::dbg_macro
- name: Pull and Build Server
env:
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
run: bash pull-and-build-server.sh
- name: Download Server
run: bash download-server.sh
working-directory: tests
- name: Run tests
run: cargo test
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "colink"
version = "0.1.22"
version = "0.2.0"
edition = "2021"
description = "CoLink Rust SDK"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CoLink SDK helps both application adnd protocol developers access the functional
Add this to your Cargo.toml:
```toml
[dependencies]
colink = "0.1.22"
colink = "0.2.0"
```

## Getting Started
Expand Down Expand Up @@ -71,7 +71,7 @@ cargo run --example auto_confirm <address> <user_jwt> <protocol_name>
cargo run --example get_next_greeting_message <address> <user_jwt> <start_timestamp> # <start_timestamp> is optional
```
```
cargo run --example mtls_request_core_info <address> <ca_certificate> <client_cert> <client_key>
cargo run --example mtls_request_info <address> <ca_certificate> <client_cert> <client_key>
```
```
cargo run --example user_lock <address> <user_jwt>
Expand Down
2 changes: 1 addition & 1 deletion examples/host_import_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>

let cl = CoLink::new(addr, jwt);
let (pk, sk) = generate_user();
let (_, core_pub_key) = cl.request_core_info().await?;
let (_, core_pub_key, _) = cl.request_info().await?;
let (signature_timestamp, sig) =
prepare_import_user_signature(&pk, &sk, &core_pub_key, expiration_timestamp);
println!(
Expand Down
2 changes: 1 addition & 1 deletion examples/host_import_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
let mut users = vec![];
for _ in 0..num {
let (pk, sk) = generate_user();
let (_, core_pub_key) = cl.request_core_info().await?;
let (_, core_pub_key, _) = cl.request_info().await?;
let (signature_timestamp, sig) =
prepare_import_user_signature(&pk, &sk, &core_pub_key, expiration_timestamp);
users.push(
Expand Down
2 changes: 1 addition & 1 deletion examples/host_import_users_and_exchange_guest_jwts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
let mut guest_jwts = vec![];
for i in 0..num {
let (pk, sk) = generate_user();
let (_, core_pub_key) = cl.request_core_info().await?;
let (_, core_pub_key, _) = cl.request_info().await?;
let (signature_timestamp, sig) =
prepare_import_user_signature(&pk, &sk, &core_pub_key, expiration_timestamp);
users.push(
Expand Down
4 changes: 2 additions & 2 deletions examples/host_import_users_and_set_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
let cl = CoLink::new(addr, jwt);
let mut users = vec![];
let (pk, sk) = generate_user();
let (_, core_pub_key) = cl.request_core_info().await?;
let (_, core_pub_key, _) = cl.request_info().await?;
let (signature_timestamp, sig) =
prepare_import_user_signature(&pk, &sk, &core_pub_key, expiration_timestamp);
let registry_user = cl
Expand All @@ -42,7 +42,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
clt.update_registries(&registries).await?;
for i in 0..num {
let (pk, sk) = generate_user();
let (_, core_pub_key) = cl.request_core_info().await?;
let (_, core_pub_key, _) = cl.request_info().await?;
let (signature_timestamp, sig) =
prepare_import_user_signature(&pk, &sk, &core_pub_key, expiration_timestamp);
users.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>
let cl = CoLink::new(addr, "")
.ca_certificate(ca_certificate)
.identity(client_cert, client_key);
let (_, core_pub_key) = cl.request_core_info().await?;
let (_, core_pub_key, _) = cl.request_info().await?;
println!("{}", core_pub_key);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion proto
Submodule proto updated 1 files
+5 −2 colink.proto
9 changes: 5 additions & 4 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,13 @@ impl CoLink {
Ok(())
}

pub async fn request_core_info(&self) -> Result<(String, secp256k1::PublicKey), Error> {
pub async fn request_info(&self) -> Result<(String, secp256k1::PublicKey, String), Error> {
let mut client = self._grpc_connect(&self.core_addr).await?;
let request = generate_request(&self.jwt, Empty::default());
let response = client.request_core_info(request).await?;
let response = client.request_info(request).await?;
debug!("RESPONSE={:?}", response);
let mq_uri = response.get_ref().mq_uri.clone();
let requestor_ip = response.get_ref().requestor_ip.clone();
let core_public_key_vec: Vec<u8> = response.get_ref().core_public_key.clone();
let core_public_key: secp256k1::PublicKey =
match secp256k1::PublicKey::from_slice(&core_public_key_vec) {
Expand All @@ -371,7 +372,7 @@ impl CoLink {
))))
}
};
Ok((mq_uri, core_public_key))
Ok((mq_uri, core_public_key, requestor_ip))
}

pub async fn subscribe(
Expand Down Expand Up @@ -410,7 +411,7 @@ impl CoLink {
}

pub async fn new_subscriber(&self, queue_name: &str) -> Result<CoLinkSubscriber, Error> {
let (mq_uri, _) = self.request_core_info().await?;
let (mq_uri, _, _) = self.request_info().await?;
let subscriber = CoLinkSubscriber::new(&mq_uri, queue_name).await?;
Ok(subscriber)
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl CoLinkProtocol {
};
self.cl.unlock(lock).await?;

let (mq_addr, _) = self.cl.request_core_info().await?;
let (mq_addr, _, _) = self.cl.request_info().await?;
let mq = Connection::connect(&mq_addr, ConnectionProperties::default()).await?;
let channel = mq.create_channel().await?;
channel.basic_qos(1, BasicQosOptions::default()).await?;
Expand Down
8 changes: 8 additions & 0 deletions tests/download-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e
rm -rf colink-server
mkdir colink-server && cd colink-server
wget https://github.com/CoLearn-Dev/colink-server-dev/releases/download/v0.2.0/colink-server-linux-x86_64.tar.gz
tar -xzf colink-server-linux-x86_64.tar.gz
touch user_init_config.toml # create an empty user init config to prevent automatically starting protocols when importing users.
cd ..
7 changes: 0 additions & 7 deletions tests/pull-and-build-server.sh

This file was deleted.

21 changes: 10 additions & 11 deletions tests/test_example_protocol_greetings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ fn test_greetings(port: u16, user_num: usize) -> Result<(), Box<dyn std::error::
}

fn start_core(port: u16) -> Child {
Command::new("cargo")
Command::new("./colink-server")
.args([
"run",
"--",
"--address",
CORE_ADDR,
"--port",
Expand All @@ -140,6 +138,15 @@ fn start_core(port: u16) -> Child {
"--mq-prefix",
MQ_PREFIX,
])
.env(
"COLINK_HOME",
std::env::current_dir()
.unwrap()
.join("tests")
.join("colink-server")
.to_str()
.unwrap(),
)
.current_dir("./tests/colink-server")
.stdout(Stdio::null())
.stderr(Stdio::null())
Expand All @@ -148,21 +155,13 @@ fn start_core(port: u16) -> Child {
}

fn build() {
let mut core = Command::new("cargo")
.args(["build"])
.current_dir("./tests/colink-server")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap();
let mut sdk = Command::new("cargo")
.args(["build", "--all-targets"])
.current_dir("./")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap();
core.wait().unwrap();
sdk.wait().unwrap();
}

Expand Down

0 comments on commit e55f753

Please sign in to comment.