-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01d78e0
commit 1b0c4da
Showing
7 changed files
with
94 additions
and
35 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/mmcloughlin/pearl/torconfig" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// genkeysCmd represents the genkeys command | ||
var genkeysCmd = &cobra.Command{ | ||
Use: "genkeys", | ||
Short: "Generate tor relay keys", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return genkeys() | ||
}, | ||
} | ||
|
||
var ( | ||
datadir string | ||
) | ||
|
||
func init() { | ||
genkeysCmd.Flags().StringVarP(&datadir, "data-dir", "d", "", "data directory") | ||
|
||
rootCmd.AddCommand(genkeysCmd) | ||
} | ||
|
||
func genkeys() error { | ||
k, err := torconfig.GenerateKeys() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d := torconfig.NewDataDirectory(datadir) | ||
return d.SetKeys(k) | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#!/bin/bash -ex | ||
|
||
LOGDIR=logs | ||
DATADIR=/tmp/pearl/nodes | ||
|
||
port=$((3000 + RANDOM % 5000)) | ||
nick=$(printf "pearl%04x" $RANDOM) | ||
logfile=${LOGDIR}/${nick}.json | ||
datadir=${DATADIR}/$nick | ||
logfile=${datadir}/log.json | ||
|
||
mkdir -p ${LOGDIR} | ||
mkdir -p ${datadir} | ||
make install-race | ||
pearl serve -n ${nick} -p ${port} -l ${logfile} | ||
pearl genkeys -d ${datadir} | ||
pearl serve -n ${nick} -p ${port} -d ${datadir} -l ${logfile} |
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,36 @@ | ||
package torconfig | ||
|
||
import "path/filepath" | ||
|
||
// Data is an interface to router data storage. | ||
type Data interface { | ||
Keys() (*Keys, error) | ||
SetKeys(*Keys) error | ||
} | ||
|
||
// dataDirectory manages the data directory structure for a relay. | ||
type dataDirectory string | ||
|
||
// NewDataDirectory constructs a new data directory at dir. | ||
func NewDataDirectory(dir string) Data { | ||
return dataDirectory(dir) | ||
} | ||
|
||
// Keys loads keys from the data directory. | ||
func (d dataDirectory) Keys() (*Keys, error) { | ||
return LoadKeysFromDirectory(d.keysDir()) | ||
} | ||
|
||
// SetKeys writes keys to the data directory. | ||
func (d dataDirectory) SetKeys(k *Keys) error { | ||
return k.SaveToDirectory(d.keysDir()) | ||
} | ||
|
||
func (d dataDirectory) keysDir() string { | ||
return d.path("keys") | ||
} | ||
|
||
// path constructs a path to sub inside the data directory. | ||
func (d dataDirectory) path(sub string) string { | ||
return filepath.Join(string(d), sub) | ||
} |