From 8564f40478c10208360bb94b8594e3d0e5354a05 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 28 Feb 2023 17:30:25 +0530 Subject: [PATCH] feat: introduce self when bootstrapping --- config/default.toml | 1 + src/api.rs | 1 - src/introduce.rs | 12 ++++++++++++ src/settings.rs | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/config/default.toml b/config/default.toml index 918cb41..85053be 100644 --- a/config/default.toml +++ b/config/default.toml @@ -39,6 +39,7 @@ wait_before_next_api_call = 2 # in seconds [introducer] #nodes = ["http://localhost:7000"] +public_url = "http://localhost:7000" nodes = [] [repository] diff --git a/src/api.rs b/src/api.rs index 0c9c73b..a708ed7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -44,7 +44,6 @@ pub async fn lastest(federate: WebFederate) -> ServiceResult { Ok(HttpResponse::Ok().json(latest)) } - pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(lastest); cfg.service(forges); diff --git a/src/introduce.rs b/src/introduce.rs index 417a1ee..8eb92e0 100644 --- a/src/introduce.rs +++ b/src/introduce.rs @@ -50,6 +50,18 @@ impl Ctx { .json() .await .unwrap(); + + let mut introduce_url = starchart.clone(); + introduce_url.set_path(ROUTES.introducer.introduce); + let introduction_payload = Starchart { + instance_url: self.settings.introducer.public_url.to_string(), + }; + self.client + .post(introduce_url) + .json(&introduction_payload) + .send() + .await + .unwrap(); if nodes.is_empty() { break; } diff --git a/src/settings.rs b/src/settings.rs index b79c0d9..b9ee4e2 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -129,6 +129,7 @@ pub struct Crawler { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Introducer { pub nodes: Vec, + pub public_url: Url, } #[derive(Debug, Validate, Clone, PartialEq, Serialize, Deserialize)]