Use a default data directory.

This commit is contained in:
Netscape Navigator 2020-09-11 07:12:51 -05:00
parent 63226afd23
commit 83a6194b7c
7 changed files with 60 additions and 22 deletions

View File

@ -6,34 +6,38 @@ A single executable to manage a Pigeon node.
Don't use the Go version yet. If you want something stable, there is a [Ruby version that is feature complete](https://tildegit.org/PigeonProtocolConsortium/Pigeon-Ruby).
# Setup
By default, data is stored in `~/.pigeon`.
You can override this value by specifying a `PIGEON_PATH` ENV var.
# TODO
- [ ] Finish http://go-database-sql.org/nulls.html
- [ ] Fix go module nonsense. Read a tut or sth https://thenewstack.io/understanding-golang-packages/
- [ ] Add a real testing lib to DRY things up.
- [ ] Figure out a system for where to place the default data storage directory
- [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc..
- [ ] Finish all the things below:
|Done?|Verb |Noun | Flag / arg 1 | Flag 2 |
|-----|------------|--------|---------------|-----------|
| |show |peers | | |
| |show |peers | --blocked | |
| |unfollow |peer | | |
| |follow |peer | user mhash | |
| |unblock |peer | user mhash | |
| |block |peer | user mhash | |
| |show |blob | | |
| |create |blob | file path | |
| |create |blob | pipe | |
| |create |draft | | |
| |update |draft | --key=? | --value=? |
| |show |draft | | |
| |publish |draft | | |
| |create |bundle | | |
| |create |draft | | |
| |find |blob | | |
| |find |message | --all | |
| |find |message | --last | |
| |follow |peer | user mhash | |
| |ingest |bundle | | |
| |publish |draft | | |
| |show |draft | | |
| |show |message | message mhash | |
| |show |peers | | |
| |show |peers | --blocked | |
| |unblock |peer | user mhash | |
| |unfollow |peer | | |
| |update |draft | --key=? | --value=? |
| X |show |identity| | |
| X |create |identity| | |
| X |help | | | |

View File

@ -3,3 +3,6 @@
cd project
go build --o=../pigeon-cli
cd -
PIGEON_PATH="."
./pigeon-cli version
./pigeon-cli show identity

View File

@ -7,15 +7,18 @@ import (
"github.com/spf13/cobra"
)
// ======== LEVEL ZERO =====================================
// CLI: `pigeon`
var rootCmd = &cobra.Command{
Use: "pigeon",
Short: "Pigeon is a peer-to-peer database for offline systems.",
Long: `Pigeon is an off-grid, serverless, peer-to-peer
database for building software that works on poor internet
connections, or entirely offline.`,
Run: func(cmd *cobra.Command, args []string) {
},
}
// CLI: `pigeon version`
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the software version.",
@ -24,20 +27,21 @@ var versionCmd = &cobra.Command{
},
}
// ======== LEVEL ONE ======================================
// CLI: `pigeon show [resource]`
var showCmd = &cobra.Command{
Use: "show [resource]",
Short: "Show various resources",
Long: `Shows resources such as blobs, drafts, identities, messages, peers, etc..`,
}
// CLI: `pigeon create [resource]`
var createCmd = &cobra.Command{
Use: "create [resource]",
Short: "Create various resources",
Long: `Creates resources, such as identities, drafts, messages, blobs, etc..`,
}
// ======== LEVEL TWO ======================================
// CLI: `pigeon create identity`
var createIdentityCmd = &cobra.Command{
Use: "identity",
Short: "Create a new identity.",
@ -47,6 +51,7 @@ var createIdentityCmd = &cobra.Command{
},
}
// CLI: `pigeon show identity`
var showIdentityCmd = &cobra.Command{
Use: "identity",
Short: "Show current user identity.",

View File

@ -3,6 +3,7 @@ package main
import (
"database/sql"
"log"
"path"
"modernc.org/ql"
)
@ -26,8 +27,9 @@ var migrations = []migration{
func openDB() *sql.DB {
ql.RegisterDriver()
db, err0 := sql.Open("ql", "file://testdata/secret.db")
pigeonPath := maybeSetupPigeonDir()
dbPath := path.Join(pigeonPath, "db")
db, err0 := sql.Open("ql", dbPath)
if err0 != nil {
log.Fatalf("failed to open db: %s", err0)

View File

@ -11,3 +11,7 @@ var encoder = base32.NewEncoding(alphabet).WithPadding(base32.NoPadding)
func B32Encode(data []byte) string {
return encoder.EncodeToString(data)
}
func encodeUserMhash(pubKey []byte) string {
return UserSigil + B32Encode(pubKey)
}

25
project/filesystem.go Normal file
View File

@ -0,0 +1,25 @@
package main
import (
"log"
"os"
"path"
"github.com/mitchellh/go-homedir"
)
func maybeSetupPigeonDir() string {
var pigeonDataDir string
customPath, hasCustomPath := os.LookupEnv("PIGEON_PATH")
if hasCustomPath {
pigeonDataDir = customPath
} else {
home, err := homedir.Dir()
if err != nil {
log.Fatalf("Home directory resolution error %s", err)
}
pigeonDataDir = path.Join(home, ".pigeon")
}
os.MkdirAll(pigeonDataDir, 0700)
return pigeonDataDir
}

View File

@ -37,8 +37,3 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
SetConfig("private_key", priv)
return pub, priv
}
func encodeUserMhash(pubKey []byte) string {
sigil := "USER."
return sigil + B32Encode(pubKey)
}