Commit 025c090a authored by Jordan Sissel's avatar Jordan Sissel

- Add -public-key and -private-key flags

- add more startup validation
parent 44fbcc9f
......@@ -8,14 +8,27 @@ import (
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var spool_size = flag.Uint64("spool-size", 1024, "Maximum number of events to spool before a flush is forced.")
var idle_timeout = flag.Duration("idle-flush-time", 5 * time.Second, "Maximum time to wait for a full spool before flushing anyway")
var server_timeout = flag.Duration("server-timeout", 30 * time.Second, "Maximum time to wait for a request to a server before giving up and trying another.")
var servers = flag.String("servers", "", "Server (or comma-separated list of servers) to send events to. Each server can be a 'host' or 'host:port'. If the port is not specified, port 5005 is assumed. One server is chosen of the list at random, and only on failure is another server used.")
var public_key_path = flag.String("public-key", "", "the nacl public key file (generate one with the 'keygen' tool that comes with lumberjack)")
var secret_key_path = flag.String("private-key", "", "the nacl secret key file (generate one with the 'keygen' tool that comes with lumberjack). If you don't provide one, lumberjack will generate one at runtime.")
func read_key(path string, key []byte) (err error) {
file, err := os.Open(path)
if err != nil {
// TODO(sissel): check length of read
_, err = file.Read(key)
func main() {
......@@ -33,11 +46,15 @@ func main() {
if *public_key_path == "" {
log.Fatalf("No -public-key flag given")
// Turn 'host' and 'host:port' into 'tcp://host:port'
if *servers == "" {
log.Printf("No servers specified, please provide the -servers setting\n")
log.Fatalf("No servers specified, please provide the -servers setting\n")
server_list := strings.Split(*servers, ",")
for i, server := range server_list {
if !strings.Contains(server, ":") {
......@@ -53,6 +70,35 @@ func main() {
event_chan := make(chan *lumberjack.FileEvent, 16)
publisher_chan := make(chan []*lumberjack.FileEvent, 1)
paths := flag.Args()
if len(paths) == 0 {
log.Fatalf("No paths given. What files do you want me to watch?\n")
var public_key [sodium.PUBLICKEYBYTES]byte
err := read_key(*public_key_path, public_key[:])
if err != nil {
log.Fatalf("Unable to read public key path (%s): %s\n",
*public_key_path, err)
var secret_key [sodium.SECRETKEYBYTES]byte
if *secret_key_path == "" {
log.Printf("No secret key given; generating one.")
_, secret_key = sodium.CryptoBoxKeypair()
} else {
err := read_key(*secret_key_path, secret_key[:])
if err != nil {
log.Printf("Unable to read private key (%s): %s\n",
*public_key_path, err)
log.Printf("Generating a private key now.\n")
_, sk := sodium.CryptoBoxKeypair()
copy(secret_key[:], sk[:])
// The basic model of execution:
// - prospector: finds files in paths/globs to harvest, starts harvesters
// - harvester: reads a file, sends events to the spooler
......@@ -63,12 +109,13 @@ func main() {
// determine where in each file to resume a harvester.
// Prospect the globs/paths given on the command line and launch harvesters
go lumberjack.Prospect(flag.Args(), event_chan)
go lumberjack.Prospect(paths, event_chan)
// Harvesters dump events into the spooler.
go lumberjack.Spool(event_chan, publisher_chan, *spool_size, *idle_timeout)
lumberjack.Publish(publisher_chan, server_list, *server_timeout)
lumberjack.Publish(publisher_chan, server_list, public_key, secret_key,
// TODO(sissel): publisher should send state to the registrar
// TODO(sissel): registrar records last acknowledged positions in all files.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment