diff --git a/cli.go b/cli.go deleted file mode 100644 index eb74f67..0000000 --- a/cli.go +++ /dev/null @@ -1,111 +0,0 @@ -package main - -import ( - "github.com/codegangsta/cli" - "os" - "time" -) - -func main() { - app := cli.NewApp() - app.Name = "reseeder" - app.Version = "1.0.0" - app.Usage = "I2P reseed server" - - app.Commands = []cli.Command{ - { - Name: "serve", - ShortName: "s", - Usage: "Start an http(s) reseed server", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "addr", - Value: "", - Usage: "Address to bind to", - }, - cli.StringFlag{ - Name: "port", - Value: "8080", - Usage: "Port to listen on", - }, - cli.StringFlag{ - Name: "cert", - Usage: "Certificate for TLS", - }, - cli.StringFlag{ - Name: "key", - Usage: "Key for TLS certificate", - }, - cli.StringFlag{ - Name: "netdb", - Value: "./netdb", - Usage: "Path to NetDB directory containing routerInfo files", - }, - cli.DurationFlag{ - Name: "refresh", - Value: 300 * time.Second, - Usage: "Period to refresh routerInfo lists in time duration format (200ns, 1s, 5m)", - }, - cli.BoolFlag{ - Name: "proxy", - Usage: "Trust the IP supplied in the X-Forwarded-For header", - }, - cli.BoolFlag{ - Name: "verbose", - Usage: "Display all access logs", - }, - cli.IntFlag{ - Name: "rateLimit", - Usage: "Maximum number of requests per minute per IP", - }, - }, - Action: func(c *cli.Context) { - Run(&Config{ - NetDBDir: c.String("netdb"), - RefreshInterval: c.Duration("refresh"), - Proxy: c.Bool("proxy"), - Verbose: c.Bool("verbose"), - RateLimit: c.Int("rateLimit"), - Addr: c.String("addr"), - Port: c.String("port"), - Cert: c.String("cert"), - Key: c.String("key"), - }) - }, - }, - { - Name: "generate", - ShortName: "g", - Usage: "Generate a celf-signed certificate", - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "host", - Usage: "Comma-separated hostnames and IPs to generate a certificate for", - }, - cli.StringFlag{ - Name: "validFrom", - Usage: "Creation date formatted as Jan 1 15:04:05 2011", - }, - cli.DurationFlag{ - Name: "validFor", - Value: 2 * 365 * 24 * time.Hour, - Usage: "Duration that certificate is valid for", - }, - cli.BoolFlag{ - Name: "ca", - Usage: "Whether this cert should be its own Certificate Authority", - }, - cli.IntFlag{ - Name: "rsaBits", - Value: 2048, - Usage: "Size of RSA key to generate", - }, - }, - Action: func(c *cli.Context) { - GenerateCert(c.String("host"), c.String("validFrom"), c.Duration("validFor"), c.Bool("isCA"), c.Int("rsaBits")) - }, - }, - } - - app.Run(os.Args) -} diff --git a/cmd/reseeder.go b/cmd/reseeder.go new file mode 100644 index 0000000..febb06a --- /dev/null +++ b/cmd/reseeder.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "log" + + "github.com/codegangsta/cli" +) + +func NewReseederCommand() cli.Command { + return cli.Command{ + Name: "reseeder", + Usage: "Start a reseed server", + Description: "Start a reseed server", + Action: reseederAction, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "addr", + Value: "127.0.0.1:8080", + Usage: "IP and port to listen on", + }, + }, + } +} + +func reseederAction(c *cli.Context) { + log.Println("Starting server on", c.String("addr")) +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..c5e1cb8 --- /dev/null +++ b/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "os" + + "github.com/MDrollette/go-i2p/cmd" + "github.com/codegangsta/cli" +) + +func main() { + app := cli.NewApp() + app.Name = "i2p" + app.Version = "0.1.0" + app.Usage = "I2P commands" + app.Flags = []cli.Flag{} + app.Before = func(c *cli.Context) error { + cmd.Init() + return nil + } + app.Commands = []cli.Command{ + cmd.NewReseederCommand(), + } + + if err := app.Run(os.Args); err != nil { + os.Exit(1) + } +} diff --git a/cert.go b/reseed/cert.go similarity index 99% rename from cert.go rename to reseed/cert.go index 6d83494..6bf1077 100644 --- a/cert.go +++ b/reseed/cert.go @@ -1,4 +1,4 @@ -package main +package reseed import ( "crypto/rand" diff --git a/reseeder.go b/reseed/legacy.go similarity index 99% rename from reseeder.go rename to reseed/legacy.go index 5c99500..238124b 100644 --- a/reseeder.go +++ b/reseed/legacy.go @@ -1,4 +1,4 @@ -package main +package reseed // read in all files from netdb dir into a slice of routerinfos diff --git a/reseed/server.go b/reseed/server.go new file mode 100644 index 0000000..e712e77 --- /dev/null +++ b/reseed/server.go @@ -0,0 +1,5 @@ +package reseed + +const ( + LIST_TEMPLATE = `