Skip to content

Commit

Permalink
Rename project
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Sep 17, 2023
1 parent ed9a52a commit 12b08c3
Show file tree
Hide file tree
Showing 31 changed files with 122 additions and 212 deletions.
20 changes: 10 additions & 10 deletions .env
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
export BUILD_IMAGE=golang:alpine
export GO=go
export IMAGE=docker.io/bahner/go-myspace:latest
export IMAGE=docker.io/bahner/go-space:latest

# This variable is used to set ports in docker-compose.yaml
export VAULT_DEV_ROOT_TOKEN_ID=myspace
export VAULT_DEV_ROOT_TOKEN_ID=space
export VAULT_PORT=8200
export VAULT_ADDR=http://localhost:${VAULT_PORT}
export VAULT_TOKEN=${VAULT_DEV_ROOT_TOKEN_ID}
export VAULT_IMAGE=docker.io/hashicorp/vault:latest

export GO_MYSPACE_ELIXIR_IMAGE=elixir:otp-25-alpine
export GO_MYSPACE_LOG_LEVEL=info
export GO_MYSPACE_MYSPACE_NODE_NAME=myspace@localhost
export GO_MYSPACE_NODE_NAME=pubsub@localhost
export GO_MYSPACE_NODE_PORT=4369
export GO_MYSPACE_NODE_COOKIE=myspace
export GO_space_ELIXIR_IMAGE=elixir:otp-25-alpine
export GO_space_LOG_LEVEL=info
export GO_space_space_NODE_NAME=space@localhost
export GO_space_NODE_NAME=pubsub@localhost
export GO_space_NODE_PORT=4369
export GO_space_NODE_COOKIE=space
# This is used inside the container network and
# should use the vault service name ad the host.
export GO_MYSPACE_VAULT_ADDR=http://localhost:${VAULT_PORT}
export GO_MYSPACE_VAULT_TOKEN=${VAULT_DEV_ROOT_TOKEN_ID}
export GO_space_VAULT_ADDR=http://localhost:${VAULT_PORT}
export GO_space_VAULT_TOKEN=${VAULT_DEV_ROOT_TOKEN_ID}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
go.work

# Binaries created by go build ., ie the module name.
go-myspace
go-myspace-*
go-space
go-space-*
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ COPY --from=Build /main /main

# We always listen on 0.0.0.0 inside the docker container.
# By setting this explicit we override the
# MYSPACE_PUBSUB_DAEMON_ADDR which, has lower priority
# space_PUBSUB_DAEMON_ADDR which, has lower priority
ENTRYPOINT [ "/main"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/make -ef

NAME = go-myspace
NAME = go-space
VERSION=0.0.8
MODULE_NAME = github.com/bahner/go-myspace
MODULE_NAME = github.com/bahner/go-space

GO ?= go
PREFIX ?= /usr/local
Expand Down Expand Up @@ -30,7 +30,7 @@ clean:

console:
docker-compose up -d
docker attach go-myspace-pubsub_myspace_1
docker attach go-space-pubsub_space_1

distclean: clean
rm -f $(shell git ls-files --exclude-standard --others)
Expand Down
2 changes: 1 addition & 1 deletion NOTES
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GenServer.call({:myspace, :"pubsub@localhost"}, :closet)
GenServer.call({:space, :"pubsub@localhost"}, :closet)
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# go-github.com/bahner/go-myspace
# go-github.com/bahner/go-space

An Erlang node written in go that handles libp2p for Myspace.
An Erlang node written in go that handles libp2p for Space.

This node will handle the plumbing of messaging and pubsub.

Notably it handles the verification and signing of messages,
so that messages passed to Myspace are believed are trusted.
so that messages passed to Space are believed are trusted.
Since this is the only way in and out of messages for the time
being that should be OK. It's not out-of-scope to move this
to Myspace itself.
to Space itself.

Using Vault as a backend for secrets, secrets are easily shared,
but actually Myspace shouldn't need to do this for now.
but actually Space shouldn't need to do this for now.

Myspace has an objectID separate from the IPNS CID. This is
Space has an objectID separate from the IPNS CID. This is
a future proof way of designing the iplementation.
This make rekeying of objects possible. Between go and Elixir
the objectID is used (a NanoID, which is superior to UUID.4).

The NanoID is attached to the DID as the fragment of the did.
NB! The did part is not in any way, shape or form ready. But
this needs to be resolved fairly soon. The did:ipid author is
not responding yet. So a did:myspace is being thought of.
not responding yet. So a did:space is being thought of.
This is probably not a bad idea any way, as that means we
can add state (IPLD) to the did's.

This way things can be developed separately. Myspace trusts
This way things can be developed separately. Space trusts
go and Go needs to be made secure. The gist is that anything
over `lo` is safe and can be trusted. If that doesn't suit you,
then get involved.

The upshot should be that Myspace can be developed naiïvely for
The upshot should be that Space can be developed naiïvely for
now, without having to sign and verify everything. I believe this
a huge relief.
As stated, this can be changed. Store secrets in Vault and Bob's
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Start an application and required supervisors in main. Then let the myspace dispatcher and children to that.
Start an application and required supervisors in main. Then let the space dispatcher and children to that.
4 changes: 2 additions & 2 deletions app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"context"

"github.com/bahner/go-myspace/config"
"github.com/bahner/go-space/config"
"github.com/ergo-services/ergo/etf"
"github.com/ergo-services/ergo/gen"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -33,7 +33,7 @@ func (app *Application) Load(args ...etf.Term) (gen.ApplicationSpec, error) {
Children: []gen.ApplicationChildSpec{
{
Name: appName,
Child: createMyspace(app.ctx),
Child: createSpace(app.ctx),
},
},
}, nil
Expand Down
24 changes: 12 additions & 12 deletions app/myspace.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package app

// This genserver is started by the Myspace
// This genserver is started by the Space
// It is used to add children, ie. topics to the
// Myspace supervision tree
// Space supervision tree

import (
"context"
"fmt"

"github.com/bahner/go-myspace/config"
"github.com/bahner/go-myspace/subscription"
"github.com/bahner/go-space/config"
"github.com/bahner/go-space/subscription"
"github.com/ergo-services/ergo/etf"
"github.com/ergo-services/ergo/gen"

log "github.com/sirupsen/logrus"
)

type Myspace struct {
type Space struct {
gen.Server
ctx context.Context
}

func createMyspace(ctx context.Context) gen.ServerBehavior {
func createSpace(ctx context.Context) gen.ServerBehavior {

return &Myspace{
return &Space{
ctx: ctx,
}

}

func (gr *Myspace) Init(sp *gen.ServerProcess, args ...etf.Term) error {
func (gr *Space) Init(sp *gen.ServerProcess, args ...etf.Term) error {
appName := config.AppName

log.Infof("Initializing %s GenServer", appName)
Expand All @@ -38,13 +38,13 @@ func (gr *Myspace) Init(sp *gen.ServerProcess, args ...etf.Term) error {

}

func (gr *Myspace) HandleCast(server_procces *gen.ServerProcess, message etf.Term) gen.ServerStatus {
func (gr *Space) HandleCast(server_procces *gen.ServerProcess, message etf.Term) gen.ServerStatus {

log.Infof("Creating new topic subscription with no reply: %s\n", message)
return gen.ServerStatusOK
}

func (gr *Myspace) HandleCall(serverProcess *gen.ServerProcess, from gen.ServerFrom, message etf.Term) (etf.Term, gen.ServerStatus) {
func (gr *Space) HandleCall(serverProcess *gen.ServerProcess, from gen.ServerFrom, message etf.Term) (etf.Term, gen.ServerStatus) {

log.Debugf("Creating new topic with a reply: %s\n", message)

Expand All @@ -58,13 +58,13 @@ func (gr *Myspace) HandleCall(serverProcess *gen.ServerProcess, from gen.ServerF
subscribeTopic(gr.ctx, t)

msg := etf.Tuple{
etf.Atom("go_myspace_created_topic"),
etf.Atom("go_space_created_topic"),
etf.String(t)}

return msg, gen.ServerStatusOK
}

func (gr *Myspace) HandleInfo(serverProcess *gen.ServerProcess, message etf.Term) gen.ServerStatus {
func (gr *Space) HandleInfo(serverProcess *gen.ServerProcess, message etf.Term) gen.ServerStatus {
log.Debugf("Received message: %s\n", message)
return gen.ServerStatusOK
}
Expand Down
4 changes: 2 additions & 2 deletions app/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"context"

"github.com/bahner/go-myspace/config"
"github.com/bahner/go-space/config"
"github.com/ergo-services/ergo"
"github.com/ergo-services/ergo/gen"
"github.com/ergo-services/ergo/node"
Expand Down Expand Up @@ -42,7 +42,7 @@ func StartApplication(ctx context.Context) {
}

// Starting applications
process, err = n.Spawn("myspace", gen.ProcessOptions{}, createMyspace(ctx))
process, err = n.Spawn("space", gen.ProcessOptions{}, createSpace(ctx))
if err != nil {
panic(err)
}
Expand Down
26 changes: 13 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ import (
"context"
"flag"

"github.com/bahner/go-myspace/p2p/key"
"github.com/bahner/go-space/p2p/key"
log "github.com/sirupsen/logrus"
"go.deanishe.net/env"
)

var (
// Erlang application config
Version = "0.0.1"
AppName = "go-myspace"
Description = "Myspace node written in go to handle libp2p functionality."
AppName = "go-space"
Description = "Space node written in go to handle libp2p functionality."

// Package internal config
VaultAddr string = env.Get("GO_MYSPACE_VAULT_ADDR", "http://localhost:8200")
VaultToken string = env.Get("GO_MYSPACE_VAULT_TOKEN", "myspace")
VaultAddr string = env.Get("GO_space_VAULT_ADDR", "http://localhost:8200")
VaultToken string = env.Get("GO_space_VAULT_TOKEN", "space")

// Global config
LogLevel string = env.Get("GO_MYSPACE_LOG_LEVEL", "error")
MyspaceNodeName string = env.Get("GO_MYSPACE_MYSPACE_NODE_NAME", "myspace@localhost")
NodeCookie string = env.Get("GO_MYSPACE_NODE_COOKIE", "myspace")
NodeName string = env.Get("GO_MYSPACE_NODE_NAME", "pubsub@localhost")
Rendezvous string = env.Get("GO_MYSPACE_RENDEZVOUS", "myspace")
Secret string = env.Get("GO_MYSPACE_P2P_IDENTITY", "")
ServiceName string = env.Get("GO_MYSPACE_SERVICE_NAME", "myspace")
LogLevel string = env.Get("GO_space_LOG_LEVEL", "error")
SpaceNodeName string = env.Get("GO_space_space_NODE_NAME", "space@localhost")
NodeCookie string = env.Get("GO_space_NODE_COOKIE", "space")
NodeName string = env.Get("GO_space_NODE_NAME", "pubsub@localhost")
Rendezvous string = env.Get("GO_space_RENDEZVOUS", "space")
Secret string = env.Get("GO_space_P2P_IDENTITY", "")
ServiceName string = env.Get("GO_space_SERVICE_NAME", "space")
)

func Init(ctx context.Context) {

// Flags - user configurations
flag.StringVar(&LogLevel, "loglevel", LogLevel, "Loglevel to use for application")
flag.StringVar(&MyspaceNodeName, "myspace_nodename", MyspaceNodeName, "Name of the node running the actual Myspace")
flag.StringVar(&SpaceNodeName, "space_nodename", SpaceNodeName, "Name of the node running the actual Space")
flag.StringVar(&NodeCookie, "nodecookie", NodeCookie, "Secret shared by all erlang nodes in the cluster")
flag.StringVar(&NodeName, "nodename", NodeName, "Name of the erlang node")
flag.StringVar(&Rendezvous, "rendezvous", Rendezvous, "Unique string to identify group of nodes. Share this with your friends to let them connect with you")
Expand Down
4 changes: 2 additions & 2 deletions did/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
)

// ToJSON converts the DID to JSON format
func (d *DID) MarshalToJSON() ([]byte, error) {
func (d *DIDDocument) MarshalToJSON() ([]byte, error) {
return json.Marshal(d)
}

// CIDify creates a CID for the DID
// The cid is created from the entire DID document
// and is what will be pubslished to IPNS.
func (d *DID) CID() (string, error) {
func (d *DIDDocument) CID() (string, error) {

// Convert DID to bytes
DID, err := d.MarshalToJSON()
Expand Down
10 changes: 5 additions & 5 deletions did/did.go → did/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
// Ed25519PubKeyMulticodec is a constant representing the multicodec value for the Ed25519 public key
const Ed25519PubKeyMulticodec = multicodec.Ed25519Pub

// DID defines the structure of a DID Document
type DID struct {
// DIDDocument defines the structure of a DIDDocument Document
type DIDDocument struct {
Context []string `json:"@context"`
ID string `json:"id"`
Signature string `json:"signature,omitempty"`
Expand All @@ -23,7 +23,7 @@ type DID struct {
}

// New initializes a new DID
func New(identifier string, options map[string]interface{}) (*DID, error) {
func New(identifier string, options map[string]interface{}) (*DIDDocument, error) {
// Extract components from the identifier
scheme, method, version, multibaseValue := extractComponents(identifier)

Expand Down Expand Up @@ -53,8 +53,8 @@ func New(identifier string, options map[string]interface{}) (*DID, error) {
}

// initializeDID initializes a new DID with basic fields
func initializeDID(identifier string) DID {
return DID{
func initializeDID(identifier string) DIDDocument {
return DIDDocument{
Context: []string{"https://www.w3.org/ns/did/v1"},
ID: identifier,
}
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions did/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
)

// AddPubKey adds a public key to the DID
func (doc *DID) AddPubKey(pubKeyID, pubKeyType string, pubKey ed25519.PublicKey) error {
func (doc *DIDDocument) AddPubKey(pubKeyID, pubKeyType string, pubKey ed25519.PublicKey) error {
// Your original code for adding a public key goes here
return nil
}

// RemovePubKey removes a public key from the DID
func (doc *DID) RemovePubKey(pubKeyID string) error {
func (doc *DIDDocument) RemovePubKey(pubKeyID string) error {
// Your original code for removing a public key goes here
return nil
}

// GetNewestKey retrieves the newest key in the DID, based on expiry time.
func (doc *DID) GetNewestKey() (*VerificationMethod, error) {
func (doc *DIDDocument) GetNewestKey() (*VerificationMethod, error) {
var newest *VerificationMethod
for _, method := range doc.VerificationMethod {
if newest == nil || method.Expiry > newest.Expiry {
Expand All @@ -33,12 +33,12 @@ func (doc *DID) GetNewestKey() (*VerificationMethod, error) {
}

// GetAllKeys retrieves all keys from the DID.
func (doc *DID) GetAllKeys() []VerificationMethod {
func (doc *DIDDocument) GetAllKeys() []VerificationMethod {
return doc.VerificationMethod
}

// GetValidKeys retrieves all currently valid keys from the DID.
func (doc *DID) GetValidKeys() ([]VerificationMethod, error) {
func (doc *DIDDocument) GetValidKeys() ([]VerificationMethod, error) {
var validKeys []VerificationMethod
now := time.Now().Unix() // Current Unix timestamp
for _, method := range doc.VerificationMethod {
Expand Down
2 changes: 1 addition & 1 deletion did/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package did
import "time"

// Prune removes expired keys from the DID.
func (doc *DID) Prune() {
func (doc *DIDDocument) Prune() {
var pruned []VerificationMethod
now := time.Now().Unix() // Current Unix timestamp
for _, method := range doc.VerificationMethod {
Expand Down
2 changes: 1 addition & 1 deletion did/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func PublishOptions() *PublishOption {
}

// Publish publishes the DID document
func (d *DID) Publish(privateKey crypto.PrivKey, opts *PublishOption) error {
func (d *DIDDocument) Publish(privateKey crypto.PrivKey, opts *PublishOption) error {
if err := validatePublishOptions(opts); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion did/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package did

// Refresh would typically refresh the document from an external source.
// Since this example doesn't integrate external services, let's just return nil.
func (doc *DID) Refresh() error {
func (doc *DIDDocument) Refresh() error {
// Implement your logic to fetch the latest document
return nil
}
Loading

0 comments on commit 12b08c3

Please sign in to comment.