generated from flashbots/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
232 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,31 @@ | ||
# go-template | ||
# orderflow-proxy | ||
|
||
[![Goreport status](https://goreportcard.com/badge/github.com/flashbots/orderflow-proxy)](https://goreportcard.com/report/github.com/flashbots/go-template) | ||
[![Test status](https://github.com/flashbots/orderflow-proxy/actions/workflows/checks.yml/badge.svg?branch=main)](https://github.com/flashbots/go-template/actions?query=workflow%3A%22Checks%22) | ||
|
||
Toolbox and building blocks for new Go projects, to get started quickly and right-footed! | ||
|
||
* [`Makefile`](https://github.com/flashbots/orderflow-proxy/blob/main/Makefile) with `lint`, `test`, `build`, `fmt` and more | ||
* Linting with `gofmt`, `gofumpt`, `go vet`, `staticcheck` and `golangci-lint` | ||
* Logging setup using the [slog logger](https://pkg.go.dev/golang.org/x/exp/slog) (with debug and json logging options) | ||
* [GitHub Workflows](.github/workflows/) for linting and testing, as well as releasing and publishing Docker images | ||
* Entry files for [CLI](/cmd/cli/main.go) and [HTTP server](/cmd/httpserver/main.go) | ||
* Webserver with | ||
* Graceful shutdown, implementing `livez`, `readyz` and draining API handlers | ||
* Prometheus metrics | ||
* Using https://pkg.go.dev/github.com/go-chi/chi/v5 for routing | ||
* [Urfave](https://cli.urfave.org/) for cli args | ||
* https://github.com/uber-go/nilaway | ||
* See also: | ||
* Public project setup: https://github.com/flashbots/flashbots-repository-template | ||
* Repository for common Go utilities: https://github.com/flashbots/go-utils | ||
|
||
Pick and choose whatever is useful to you! Don't feel the need to use everything, or even to follow this structure. | ||
|
||
--- | ||
|
||
## Getting started | ||
|
||
**Build CLI** | ||
**Build** | ||
|
||
```bash | ||
make build-cli | ||
``` | ||
make build | ||
``** | ||
|
||
**Build HTTP server** | ||
## Run | ||
|
||
```bash | ||
make build-httpserver | ||
``` | ||
`./build/orderflow-proxy` | ||
|
||
**Install dev dependencies** | ||
Will | ||
|
||
```bash | ||
go install mvdan.cc/[email protected] | ||
go install honnef.co/go/tools/cmd/[email protected] | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
go install go.uber.org/nilaway/cmd/[email protected] | ||
go install github.com/daixiang0/[email protected] | ||
``` | ||
* create metrics server | ||
* internal server (liveness endpoints) | ||
* orderflow proxy server that will generate self signed certificate and use it to accept requests that will be proxied to the local builder endpoint | ||
|
||
**Lint, test, format** | ||
Flags for the orderflow proxy | ||
|
||
```bash | ||
make lint | ||
make test | ||
make fmt | ||
``` | ||
--listen-addr value address to listen on for orderflow proxy API (default: "127.0.0.1:9090") | ||
--builder-endpoint value address to send local ordeflow to (default: "127.0.0.1:8546") | ||
--cert-duration value generated certificate duration (default: 8760h0m0s) | ||
--cert-hosts value [ --cert-hosts value ] generated certificate hosts (default: "127.0.0.1", "localhost") | ||
``` |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package proxy | ||
|
||
import ( | ||
"bytes" | ||
"crypto/ecdsa" | ||
"crypto/elliptic" | ||
"crypto/rand" | ||
"crypto/x509" | ||
"crypto/x509/pkix" | ||
"encoding/pem" | ||
"math/big" | ||
"net" | ||
"time" | ||
) | ||
|
||
// hosts is a list of ip / dns names for the certificate | ||
func GenerateCert(validFor time.Duration, hosts []string) (cert, key []byte, err error) { | ||
// copied from https://go.dev/src/crypto/tls/generate_cert.go | ||
priv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
keyUsage := x509.KeyUsageDigitalSignature | ||
|
||
notBefore := time.Now() | ||
notAfter := notBefore.Add(validFor) | ||
|
||
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) | ||
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
template := x509.Certificate{ | ||
SerialNumber: serialNumber, | ||
Subject: pkix.Name{ | ||
Organization: []string{"Acme"}, | ||
}, | ||
NotBefore: notBefore, | ||
NotAfter: notAfter, | ||
|
||
KeyUsage: keyUsage, | ||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, | ||
BasicConstraintsValid: true, | ||
} | ||
|
||
for _, h := range hosts { | ||
if ip := net.ParseIP(h); ip != nil { | ||
template.IPAddresses = append(template.IPAddresses, ip) | ||
} else { | ||
template.DNSNames = append(template.DNSNames, h) | ||
} | ||
} | ||
|
||
// certificate is its own CA | ||
template.IsCA = true | ||
template.KeyUsage |= x509.KeyUsageCertSign | ||
|
||
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var certOut bytes.Buffer | ||
if err = pem.Encode(&certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil { | ||
return nil, nil, err | ||
} | ||
cert = certOut.Bytes() | ||
|
||
privBytes, err := x509.MarshalPKCS8PrivateKey(priv) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var keyOut bytes.Buffer | ||
err = pem.Encode(&keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes}) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
key = keyOut.Bytes() | ||
return | ||
} |
Oops, something went wrong.