refactor
This commit is contained in:
111
cli.go
111
cli.go
@@ -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)
|
||||
}
|
||||
27
cmd/reseeder.go
Normal file
27
cmd/reseeder.go
Normal file
@@ -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"))
|
||||
}
|
||||
27
main.go
Normal file
27
main.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package reseed
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package reseed
|
||||
|
||||
// read in all files from netdb dir into a slice of routerinfos
|
||||
|
||||
5
reseed/server.go
Normal file
5
reseed/server.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package reseed
|
||||
|
||||
const (
|
||||
LIST_TEMPLATE = `<html><head><title>NetDB</title></head><body><ul>{{ range $index, $_ := . }}<li><a href="{{ $index }}">{{ $index }}</a></li>{{ end }}</ul></body></html>`
|
||||
)
|
||||
70
su3/su3.go
Normal file
70
su3/su3.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user