Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Download from relays #14

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ test:
.PHONY: clippy
clippy:
cargo clippy -- -D warnings

.PHONY: run
run:
cargo run
53 changes: 47 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ mod fixtures;

use crate::service::app;
use crate::service::app::commands::implementation as commandsimpl;
use crate::service::app::common::TransactionProvider;
use crate::service::domain;
use crate::service::ports::http;
use service::adapters::sqlite as sqliteadapters;
use service::app::commands::downloader::Downloader;
use std::thread;

fn main() {
let conn = sqlite::Connection::open("/tmp/db.sqlite").unwrap();
let conn_adapter = sqliteadapters::SqliteConnectionAdapter::new(conn);
let conn_pool = sqliteadapters::SqliteConnectionPool::new(conn);

//let adapters_factory_fn = new_adapters_factory_fn();

let mut migrations: Vec<migrations::Migration> = Vec::new();

// no idea how to make a factory function for this without ownership errors
let migration_registration_0001_create_tables =
sqliteadapters::RegistrationRepositoryMigration0001::new(conn_adapter.clone());
sqliteadapters::RegistrationRepositoryMigration0001::new(conn_pool.clone());

migrations.push(
migrations::Migration::new(
Expand All @@ -34,7 +37,7 @@ fn main() {

let migrations = migrations::Migrations::new(migrations).unwrap();

let transaction_provider = sqliteadapters::TransactionProvider::new(conn_adapter.clone());
let transaction_provider = sqliteadapters::TransactionProvider::new(conn_pool.clone());

let register = commandsimpl::RegisterHandler::new();

Expand All @@ -43,14 +46,52 @@ fn main() {
let app = app::Application::new(&commands, &queries);

let migration_status_repository =
sqliteadapters::MigrationStatusRepository::new(conn_adapter).unwrap();
sqliteadapters::MigrationStatusRepository::new(conn_pool).unwrap();
let runner = migrations::Runner::new(migration_status_repository);

let server = http::Server::new(&app);

let _downloader = Downloader::new(transaction_provider);

runner.run(&migrations).unwrap();

// todo remove!
{
let pk = domain::PubKey::new_from_hex(
"e731ca427c18059d66636ddfaeeeb15012bc2db3cdd27b9e4cade5057a6e82ed",
)
.unwrap();

let r = domain::Registration::new(
pk,
domain::APNSToken::new(String::from("a")).unwrap(),
vec![domain::RelayAddress::new(String::from("wss://relay.damus.io")).unwrap()],
domain::Locale::new(String::from("en")).unwrap(),
)
.unwrap();

let mut transaction = transaction_provider.start_transaction().unwrap();
{
let adapters = transaction.adapters();
let registrations = adapters.registrations.borrow();
registrations.save(&r).unwrap();
}
transaction.commit().unwrap();
}

thread::scope(|s| {
s.spawn(|| {
let mut downloader = Downloader::new(transaction_provider);
downloader.run(s).unwrap();
});

s.spawn(|| {
println!("hello from the second scoped thread");
// We can even mutably borrow `x` here,
// because no other threads are using it.
//x += a[0] + a[2];
});
println!("hello from the main thread");
});

server.listen_and_serve();
}

Expand Down
Loading