From aea04a6719baa3bf2d9b1ff4ab364e9e624c5ba5 Mon Sep 17 00:00:00 2001 From: Matt Drollette Date: Fri, 5 Dec 2014 15:22:34 -0600 Subject: [PATCH] refactor --- cli.go | 111 -------------------------------- cmd/reseeder.go | 27 ++++++++ main.go | 27 ++++++++ cert.go => reseed/cert.go | 2 +- reseeder.go => reseed/legacy.go | 2 +- reseed/server.go | 5 ++ su3.go | 1 - su3/su3.go | 70 ++++++++++++++++++++ 8 files changed, 131 insertions(+), 114 deletions(-) delete mode 100644 cli.go create mode 100644 cmd/reseeder.go create mode 100644 main.go rename cert.go => reseed/cert.go (99%) rename reseeder.go => reseed/legacy.go (99%) create mode 100644 reseed/server.go delete mode 100644 su3.go create mode 100644 su3/su3.go 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 = `NetDB` +) diff --git a/su3.go b/su3.go deleted file mode 100644 index 06ab7d0..0000000 --- a/su3.go +++ /dev/null @@ -1 +0,0 @@ -package main diff --git a/su3/su3.go b/su3/su3.go new file mode 100644 index 0000000..a1967f4 --- /dev/null +++ b/su3/su3.go @@ -0,0 +1,70 @@ +package su3 + +type Su3 struct { + // 0-5 Magic number "I2Psu3" + Magic [6]byte + + // 6 unused = 0 + Unused1 [1]byte + + // 7 su3 file format version = 0 + Format [1]byte + + // 8-9 Signature type + // 0x0000 = DSA-160 + // 0x0001 = ECDSA-SHA256-P256 + // 0x0002 = ECDSA-SHA384-P384 + // 0x0003 = ECDSA-SHA512-P521 + // 0x0004 = RSA-SHA256-2048 + // 0x0005 = RSA-SHA384-3072 + // 0x0006 = RSA-SHA512-4096 + SignatureType [2]byte + + // 10-11 Signature length, e.g. 40 (0x0028) for DSA-160 + SignatureLength [2]byte + + // 12 unused + Unused2 [1]byte + + // 13 Version length (in bytes not chars, including padding) must be at least 16 (0x10) for compatibility + VersionLength [1]byte + + // 14 unused + Unused3 [1]byte + + // 15 Signer ID length (in bytes not chars) + SignerIdLength [1]byte + + // 16-23 Content length (not including header or sig) + ContentLength [8]byte + + // 24 unused + Unused4 [1]byte + + // 25 File type + // 0x00 = zip file + // 0x01 = xml file (as of 0.9.15) + // 0x02 = html file (as of 0.9.17) + // 0x03 = xml.gz file (as of 0.9.17) + FileType [1]byte + + // 26 unused + Unused5 [1]byte + + // 27 Content type + // 0x00 = unknown + // 0x01 = router update + // 0x02 = plugin or plugin update + // 0x03 = reseed data + // 0x04 = news feed (as of 0.9.15) + ContentType [1]byte + + // 28-39 unused + Unused6 [12]byte + + // 40-55+ Version, UTF-8 padded with trailing 0x00, 16 bytes minimum, length specified at byte 13. Do not append 0x00 bytes if the length is 16 or more. + // xx+ ID of signer, (e.g. "zzz@mail.i2p") UTF-8, not padded, length specified at byte 15 + // xx+ Content, length and format specified in header + // xx+ Signature, length specified in header, covers everything starting at byte 0 + Version [16]byte +}