Skip to content

Commit

Permalink
Substantially condense common config, options and initialisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Mar 19, 2024
1 parent 2857775 commit ba99394
Show file tree
Hide file tree
Showing 26 changed files with 387 additions and 719 deletions.
21 changes: 14 additions & 7 deletions cmd/actor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package main
import (
"fmt"

"github.com/bahner/go-ma-actor/config"
"github.com/bahner/go-ma-actor/config/db"
"github.com/bahner/go-ma-actor/entity/actor"
"github.com/bahner/go-ma-actor/p2p"
"github.com/bahner/go-ma-actor/ui"
"github.com/bahner/go-ma-actor/ui/web"

Expand All @@ -17,7 +19,8 @@ func main() {
err error
)

actor.InitConfig()
fmt.Println("Initialising actor configuation...")
actor.InitConfig(config.Profile())

// DB
fmt.Println("Initialising DB ...")
Expand All @@ -27,21 +30,25 @@ func main() {
}

// P2P
p2P, err := initP2P()
fmt.Println("Setting default p2p options...")
p2pOpts := p2p.DefaultOptions()
fmt.Println("Initialising p2p...")
p2P, err := p2p.Init(p2pOpts)
if err != nil {
panic(fmt.Sprintf("failed to initialize p2p: %v", err))
}

// ACTOR
fmt.Println("Initialising actor...")
a := actor.Init()

// Start the webserver in the background. Ignore - but log - errors.
wh := web.NewWebEntityHandler(p2P, a.Entity)
// WEB
fmt.Println("Initialising web UI...")
wh := web.NewEntityHandler(p2P, a.Entity)
go web.Start(wh)

// We have a valid actor, but for it to be useful, we need to discover peers.
// discoverPeersOrPanic(p2P)

// TEXT UI
fmt.Println("Initialising text UI...")
ui := ui.Init(p2P, a)

// START THE ACTOR UI
Expand Down
73 changes: 0 additions & 73 deletions cmd/actor/p2p.go

This file was deleted.

40 changes: 0 additions & 40 deletions cmd/node/actor.go

This file was deleted.

31 changes: 0 additions & 31 deletions cmd/node/dht.go

This file was deleted.

55 changes: 0 additions & 55 deletions cmd/node/init.go

This file was deleted.

15 changes: 11 additions & 4 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,32 @@ package main
import (
"context"

"github.com/bahner/go-ma-actor/config"
"github.com/bahner/go-ma-actor/entity/actor"
"github.com/bahner/go-ma-actor/p2p"
"github.com/bahner/go-ma-actor/ui/web"
log "github.com/sirupsen/logrus"
)

const name = "node"

func main() {

ctx := context.Background()

// Init config and logger
initConfig()
config.SetProfile(name)
actor.InitConfig(config.Profile())

p, err := initP2P()
p, err := p2p.Init(p2p.DefaultOptions())
if err != nil {
log.Fatalf("Error initialising P2P: %v", err)
}

// Init of actor requires P2P to be initialized
a := initActorOrPanic()
a := actor.Init()

go startWebServer(p, a)
go web.Start(web.NewEntityHandler(p, a.Entity))
go p.StartDiscoveryLoop(ctx)
go a.Subscribe(ctx, a.Entity)

Expand Down
25 changes: 0 additions & 25 deletions cmd/node/p2p.go

This file was deleted.

44 changes: 0 additions & 44 deletions cmd/node/web.go

This file was deleted.

Loading

0 comments on commit ba99394

Please sign in to comment.