fix: don't introduce self!
This commit is contained in:
parent
cd797fba83
commit
6006d04b2f
2 changed files with 50 additions and 14 deletions
|
@ -38,6 +38,9 @@ impl Ctx {
|
||||||
starchart_url: &Url,
|
starchart_url: &Url,
|
||||||
page: usize,
|
page: usize,
|
||||||
) -> ServiceResult<Vec<Forge>> {
|
) -> ServiceResult<Vec<Forge>> {
|
||||||
|
if starchart_url == &self.settings.introducer.public_url {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
let mut url = starchart_url.clone();
|
let mut url = starchart_url.clone();
|
||||||
url.set_path(ROUTES.forges);
|
url.set_path(ROUTES.forges);
|
||||||
url.set_query(Some(&format!("page={page}")));
|
url.set_query(Some(&format!("page={page}")));
|
||||||
|
@ -56,6 +59,9 @@ impl Ctx {
|
||||||
starchart_url: Url,
|
starchart_url: Url,
|
||||||
db: &Box<dyn SCDatabase>,
|
db: &Box<dyn SCDatabase>,
|
||||||
) -> ServiceResult<()> {
|
) -> ServiceResult<()> {
|
||||||
|
if starchart_url == self.settings.introducer.public_url {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
let clean_starchart_url = clean_url(&starchart_url);
|
let clean_starchart_url = clean_url(&starchart_url);
|
||||||
let mut page = 1;
|
let mut page = 1;
|
||||||
loop {
|
loop {
|
||||||
|
@ -83,6 +89,9 @@ impl Ctx {
|
||||||
mut starchart_url: Url,
|
mut starchart_url: Url,
|
||||||
page: usize,
|
page: usize,
|
||||||
) -> ServiceResult<Vec<Starchart>> {
|
) -> ServiceResult<Vec<Starchart>> {
|
||||||
|
if starchart_url == self.settings.introducer.public_url {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
starchart_url.set_path(ROUTES.introducer.list);
|
starchart_url.set_path(ROUTES.introducer.list);
|
||||||
starchart_url.set_query(Some(&format!("page={page}")));
|
starchart_url.set_query(Some(&format!("page={page}")));
|
||||||
Ok(self
|
Ok(self
|
||||||
|
@ -96,7 +105,10 @@ impl Ctx {
|
||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
async fn client_get_mini_index(&self, mut starchart_url: Url) -> ServiceResult<MiniIndex> {
|
async fn client_get_mini_index(&self, mut starchart_url: Url) -> ServiceResult<MiniIndex> {
|
||||||
starchart_url.set_path(ROUTES.introducer.introduce);
|
if starchart_url == self.settings.introducer.public_url {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
starchart_url.set_path(ROUTES.introducer.get_mini_index);
|
||||||
Ok(self
|
Ok(self
|
||||||
.client
|
.client
|
||||||
.get(starchart_url)
|
.get(starchart_url)
|
||||||
|
@ -109,6 +121,9 @@ impl Ctx {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn client_introduce_starchart(&self, mut starchart_url: Url) -> ServiceResult<()> {
|
async fn client_introduce_starchart(&self, mut starchart_url: Url) -> ServiceResult<()> {
|
||||||
|
if starchart_url == self.settings.introducer.public_url {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
starchart_url.set_path(ROUTES.introducer.introduce);
|
starchart_url.set_path(ROUTES.introducer.introduce);
|
||||||
let introduction_payload = Starchart {
|
let introduction_payload = Starchart {
|
||||||
instance_url: self.settings.introducer.public_url.to_string(),
|
instance_url: self.settings.introducer.public_url.to_string(),
|
||||||
|
@ -137,17 +152,38 @@ impl Ctx {
|
||||||
if nodes.is_empty() {
|
if nodes.is_empty() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for node in nodes.drain(0..) {
|
|
||||||
let node_url = Url::parse(&node.instance_url)?;
|
async fn _bootstrap(
|
||||||
|
ctx: &Ctx,
|
||||||
|
db: &Box<dyn SCDatabase>,
|
||||||
|
known_starcharts: &mut HashSet<Url>,
|
||||||
|
instance_url: &str,
|
||||||
|
) -> ServiceResult<()> {
|
||||||
|
if instance_url == ctx.settings.introducer.public_url.as_str() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let node_url = Url::parse(instance_url)?;
|
||||||
db.add_starchart_to_introducer(&node_url).await?;
|
db.add_starchart_to_introducer(&node_url).await?;
|
||||||
if known_starcharts.get(&node_url).is_none() {
|
if known_starcharts.get(&node_url).is_none() {
|
||||||
known_starcharts.insert(node_url.clone());
|
known_starcharts.insert(node_url.clone());
|
||||||
}
|
}
|
||||||
self.import_forges(node_url, db).await?;
|
ctx.import_forges(node_url.clone(), db).await?;
|
||||||
let mini_index = self.client_get_mini_index(starchart.clone()).await?;
|
let mini_index = ctx.client_get_mini_index(node_url.clone()).await?;
|
||||||
db.rm_imported_mini_index(starchart).await?;
|
db.rm_imported_mini_index(&node_url).await?;
|
||||||
db.import_mini_index(starchart, &mini_index.mini_index)
|
db.import_mini_index(&node_url, &mini_index.mini_index)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
_bootstrap(self, db, &mut known_starcharts, starchart.as_str()).await?;
|
||||||
|
|
||||||
|
for node in nodes.drain(0..) {
|
||||||
|
if node.instance_url == self.settings.introducer.public_url.as_str() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_bootstrap(self, db, &mut known_starcharts, &node.instance_url).await?;
|
||||||
}
|
}
|
||||||
page += 1;
|
page += 1;
|
||||||
}
|
}
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -113,13 +113,13 @@ async fn main() {
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
let s = tokio::spawn(server_fut);
|
let s = tokio::spawn(server_fut);
|
||||||
f.import(
|
// f.import(
|
||||||
url::Url::parse("http://localhost:7000").unwrap(),
|
// url::Url::parse("http://localhost:7000").unwrap(),
|
||||||
&c.client,
|
// &c.client,
|
||||||
&d,
|
// &d,
|
||||||
)
|
// )
|
||||||
.await
|
// .await
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
kill_crawler.send(true).unwrap();
|
kill_crawler.send(true).unwrap();
|
||||||
crawler_fut.await.unwrap().await;
|
crawler_fut.await.unwrap().await;
|
||||||
s.await.unwrap().unwrap();
|
s.await.unwrap().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue