-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also make room for having a room here directly, not just a node.
- Loading branch information
Showing
21 changed files
with
447 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ go.work | |
# Binaries created by go build ., ie the module name. | ||
go-space | ||
.*.log | ||
go-space-node | ||
launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bahner/go-ma-actor/config" | ||
"github.com/bahner/go-ma-actor/entity" | ||
"github.com/bahner/go-ma-actor/entity/actor" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func initActorOrPanic() *actor.Actor { | ||
// The actor is needed for initialisation of the WebHandler. | ||
fmt.Println("Creating actor from keyset...") | ||
a, err := actor.NewFromKeyset(config.ActorKeyset()) | ||
if err != nil { | ||
log.Debugf("error creating actor: %s", err) | ||
} | ||
|
||
id := a.Entity.DID.Id | ||
|
||
fmt.Println("Creating and setting DID Document for actor...") | ||
err = a.CreateAndSetDocument(id) | ||
if err != nil { | ||
panic(fmt.Sprintf("error creating document: %s", err)) | ||
} | ||
|
||
// Better safe than sorry. | ||
// Without a valid actor, we can't do anything. | ||
if a == nil || a.Verify() != nil { | ||
panic(fmt.Sprintf("%s is not a valid actor: %v", id, err)) | ||
} | ||
|
||
_, err = entity.GetOrCreateFromDID(a.Entity.DID, false) | ||
if err != nil { | ||
panic(fmt.Sprintf("error getting or creating entity: %s", err)) | ||
} | ||
|
||
return a | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bahner/go-ma-actor/config" | ||
"github.com/bahner/go-ma-actor/p2p" | ||
"github.com/bahner/go-ma-actor/p2p/connmgr" | ||
"github.com/bahner/go-ma-actor/p2p/node" | ||
"github.com/libp2p/go-libp2p" | ||
) | ||
|
||
func DHT(cg *connmgr.ConnectionGater) (*p2p.DHT, error) { | ||
|
||
// THese are the relay specific parts. | ||
p2pOpts := []libp2p.Option{ | ||
libp2p.ConnectionGater(cg), | ||
} | ||
|
||
n, err := node.New(config.NodeIdentity(), p2pOpts...) | ||
if err != nil { | ||
return nil, fmt.Errorf("pong: failed to create libp2p node: %w", err) | ||
} | ||
|
||
d, err := p2p.NewDHT(n, cg) | ||
if err != nil { | ||
return nil, fmt.Errorf("pong: failed to create DHT: %w", err) | ||
} | ||
|
||
return d, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/bahner/go-ma-actor/config" | ||
"github.com/bahner/go-ma/did/doc" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
const name = "node" | ||
|
||
func initConfig() { | ||
|
||
// Always parse the flags first | ||
config.InitCommonFlags() | ||
config.InitActorFlags() | ||
pflag.Parse() | ||
config.SetProfile(name) | ||
config.Init() | ||
|
||
if config.GenerateFlag() { | ||
// Reinit logging to STDOUT | ||
log.SetOutput(os.Stdout) | ||
log.Info("Generating new actor and node identity") | ||
actor, node := generateActorIdentitiesOrPanic(config.Profile()) | ||
actorConfig := configTemplate(actor, node) | ||
config.Generate(actorConfig) | ||
os.Exit(0) | ||
} | ||
|
||
// At this point an actor *must* be initialized | ||
config.InitActor() | ||
|
||
// This flag is dependent on the actor to be initialized to make sense. | ||
if config.ShowConfigFlag() { | ||
config.Print() | ||
os.Exit(0) | ||
} | ||
|
||
} | ||
|
||
func generateActorIdentitiesOrPanic(name string) (string, string) { | ||
actor, node, err := config.GenerateActorIdentities(name) | ||
if err != nil { | ||
if errors.Is(err, doc.ErrAlreadyPublished) { | ||
log.Warnf("Actor document already published: %v", err) | ||
} else { | ||
log.Fatal(err) | ||
} | ||
} | ||
return actor, node | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
|
||
ctx := context.Background() | ||
|
||
// Init config and logger | ||
initConfig() | ||
|
||
p, err := initP2P() | ||
if err != nil { | ||
log.Fatalf("Error initialising P2P: %v", err) | ||
} | ||
|
||
// Init of actor requires P2P to be initialized | ||
a := initActorOrPanic() | ||
|
||
go p.StartDiscoveryLoop(ctx) | ||
go a.Subscribe(ctx, a.Entity) | ||
|
||
// Start application | ||
StartApplication(p) | ||
|
||
select {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bahner/go-ma-actor/p2p" | ||
"github.com/bahner/go-ma-actor/p2p/connmgr" | ||
) | ||
|
||
func initP2P() (P2P *p2p.P2P, err error) { | ||
fmt.Println("Initialising libp2p...") | ||
|
||
// Everyone needs a connection manager. | ||
cm, err := connmgr.Init() | ||
if err != nil { | ||
panic(fmt.Errorf("pong: failed to create connection manager: %w", err)) | ||
} | ||
cg := connmgr.NewConnectionGater(cm) | ||
|
||
d, err := DHT(cg) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to initialize dht: %v", err)) | ||
} | ||
return p2p.Init(d) | ||
} |
File renamed without changes.
Oops, something went wrong.