Skip to content

Commit

Permalink
feat(backend): almost finished site syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiyan committed Sep 21, 2023
1 parent 06fe60d commit 8c36e21
Show file tree
Hide file tree
Showing 24 changed files with 497 additions and 487 deletions.
1 change: 0 additions & 1 deletion backend/BUILD.plz
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ go_binary(
["**/*.go"],
exclude = ["**/*_test.go"],
) + [
"//backend/cmd/mintter-site/sitesql:go_library",
"//backend/daemon/storage:go_library",
"//backend/hyper/hypersql:go_library",
"//backend/lndhub/lndhubsql:go_library",
Expand Down
27 changes: 18 additions & 9 deletions backend/cmd/mintter-site/sites/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
"mintter/backend/daemon"
"mintter/backend/daemon/storage"
accounts "mintter/backend/genproto/accounts/v1alpha"
"mintter/backend/hyper"
"mintter/backend/ipfs"
"mintter/backend/mttnet"
"mintter/backend/pkg/future"
"mintter/backend/pkg/must"
"mintter/backend/pkg/slicex"
"net/url"

"crawshaw.io/sqlite/sqlitex"
"github.com/multiformats/go-multiaddr"
)

// App is the site daemon app.
Expand All @@ -42,13 +44,16 @@ func Load(ctx context.Context, address string, cfg config.Config, dir *storage.D
return nil, fmt.Errorf("address URL must not have a path: %s", address)
}

cfg.P2P.AnnounceAddrs = must.Do2(
ipfs.ParseMultiaddrs(
ipfs.DefaultListenAddrsDNS(u.Hostname(), cfg.P2P.Port)))
cfg.P2P.AnnounceAddrs, err = slicex.MapE(ipfs.DefaultListenAddrsDNS(u.Hostname(), cfg.P2P.Port), multiaddr.NewMultiaddr)
if err != nil {
panic(fmt.Errorf("failed to parse announce addresses: %w", err))
}

nodePromise := future.New[*mttnet.Node]()
dbPromise := future.New[*sqlitex.Pool]()
blobsPromise := future.New[*hyper.Storage]()

nf := future.New[*mttnet.Node]()
ndb := future.New[*sqlitex.Pool]()
site := NewServer(address, nf.ReadOnly, ndb.ReadOnly)
site := NewServer(address, blobsPromise.ReadOnly, nodePromise.ReadOnly, dbPromise.ReadOnly)

app, err := daemon.Load(ctx, cfg, dir, site, daemon.GenericHandler{
Path: "/.well-known/hypermedia-site",
Expand All @@ -61,7 +66,7 @@ func Load(ctx context.Context, address string, cfg config.Config, dir *storage.D

// This is some ugly stuff. Site server needs some stuff that are passed from the daemon.
go func() {
if err := ndb.Resolve(app.DB); err != nil {
if err := dbPromise.Resolve(app.DB); err != nil {
panic(err)
}

Expand All @@ -70,7 +75,11 @@ func Load(ctx context.Context, address string, cfg config.Config, dir *storage.D
panic(err)
}

if err := nf.Resolve(node); err != nil {
if err := nodePromise.Resolve(node); err != nil {
panic(err)
}

if err := blobsPromise.Resolve(app.Blobs); err != nil {
panic(err)
}
}()
Expand Down
Loading

0 comments on commit 8c36e21

Please sign in to comment.