|
|
|
@ -5,6 +5,8 @@ import ( |
|
|
|
|
"flag" |
|
|
|
|
"fmt" |
|
|
|
|
"net/http" |
|
|
|
|
"net/http/httputil" |
|
|
|
|
"net/url" |
|
|
|
|
"path" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
@ -26,11 +28,13 @@ func main() { |
|
|
|
|
logger := mlog.NewLogger(nil) |
|
|
|
|
|
|
|
|
|
hostname := flag.String("hostname", "localhost:4000", "Hostname to advertise this server as") |
|
|
|
|
staticDir := flag.String("static-dir", "", "Directory from which static files are served") |
|
|
|
|
listenAddr := flag.String("listen-addr", ":4000", "Address to listen for HTTP requests on") |
|
|
|
|
dataDir := flag.String("data-dir", ".", "Directory to use for long term storage") |
|
|
|
|
|
|
|
|
|
powTargetStr := flag.String("pow-target", "0x000FFFF", "Proof-of-work target, lower is more difficult") |
|
|
|
|
staticDir := flag.String("static-dir", "", "Directory from which static files are served (mutually exclusive with -static-proxy-url)") |
|
|
|
|
staticProxyURLStr := flag.String("static-proxy-url", "", "HTTP address from which static files are served (mutually exclusive with -static-dir)") |
|
|
|
|
|
|
|
|
|
powTargetStr := flag.String("pow-target", "0x0000FFFF", "Proof-of-work target, lower is more difficult") |
|
|
|
|
powSecret := flag.String("pow-secret", "", "Secret used to sign proof-of-work challenge seeds") |
|
|
|
|
|
|
|
|
|
smtpAddr := flag.String("ml-smtp-addr", "", "Address of SMTP server to use for sending emails for the mailing list") |
|
|
|
@ -41,8 +45,8 @@ func main() { |
|
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
|
switch { |
|
|
|
|
case *staticDir == "": |
|
|
|
|
logger.Fatal(context.Background(), "-static-dir is required") |
|
|
|
|
case *staticDir == "" && *staticProxyURLStr == "": |
|
|
|
|
logger.Fatal(context.Background(), "-static-dir or -static-proxy-url is required") |
|
|
|
|
case *powSecret == "": |
|
|
|
|
logger.Fatal(context.Background(), "-pow-secret is required") |
|
|
|
|
case *smtpAddr == "": |
|
|
|
@ -51,6 +55,14 @@ func main() { |
|
|
|
|
logger.Fatal(context.Background(), "-ml-smtp-auth is required") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var staticProxyURL *url.URL |
|
|
|
|
if *staticProxyURLStr != "" { |
|
|
|
|
var err error |
|
|
|
|
if staticProxyURL, err = url.Parse(*staticProxyURLStr); err != nil { |
|
|
|
|
loggerFatalErr(context.Background(), logger, "parsing -static-proxy-url", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
powTargetUint, err := strconv.ParseUint(*powTargetStr, 0, 32) |
|
|
|
|
if err != nil { |
|
|
|
|
loggerFatalErr(context.Background(), logger, "parsing -pow-target", err) |
|
|
|
@ -68,7 +80,6 @@ func main() { |
|
|
|
|
|
|
|
|
|
ctx := mctx.Annotate(context.Background(), |
|
|
|
|
"hostname", *hostname, |
|
|
|
|
"staticDir", *staticDir, |
|
|
|
|
"listenAddr", *listenAddr, |
|
|
|
|
"dataDir", *dataDir, |
|
|
|
|
"powTarget", fmt.Sprintf("%x", powTarget), |
|
|
|
@ -76,6 +87,12 @@ func main() { |
|
|
|
|
"smtpSendAs", smtpSendAs, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if *staticDir != "" { |
|
|
|
|
ctx = mctx.Annotate(ctx, "staticDir", *staticDir) |
|
|
|
|
} else { |
|
|
|
|
ctx = mctx.Annotate(ctx, "staticProxyURL", *staticProxyURLStr) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
clock := clock.Realtime() |
|
|
|
|
|
|
|
|
|
powStore := pow.NewMemoryStore(clock) |
|
|
|
@ -112,7 +129,15 @@ func main() { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
mux := http.NewServeMux() |
|
|
|
|
mux.Handle("/", http.FileServer(http.Dir(*staticDir))) |
|
|
|
|
|
|
|
|
|
var staticHandler http.Handler |
|
|
|
|
if *staticDir != "" { |
|
|
|
|
staticHandler = http.FileServer(http.Dir(*staticDir)) |
|
|
|
|
} else { |
|
|
|
|
staticHandler = httputil.NewSingleHostReverseProxy(staticProxyURL) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mux.Handle("/", staticHandler) |
|
|
|
|
|
|
|
|
|
apiMux := http.NewServeMux() |
|
|
|
|
apiMux.Handle("/pow/challenge", newPowChallengeHandler(powMgr)) |
|
|
|
|