Checkpoint

This commit is contained in:
2025-10-01 15:37:55 +02:00
parent 4a60059ff2
commit 03352e3312
31 changed files with 2611 additions and 384 deletions

View File

@@ -14,8 +14,7 @@ import (
"sync/atomic"
"time"
"git.maze.io/maze/styx/internal/netutil/arp"
"github.com/sirupsen/logrus"
"git.maze.io/maze/styx/logger"
)
// Context provides convenience functions for the current ongoing HTTP proxy transaction (request).
@@ -71,17 +70,16 @@ func (w *countingWriter) Write(p []byte) (n int, err error) {
type proxyContext struct {
net.Conn
id uint64
mac net.HardwareAddr
cr *countingReader
br *bufio.Reader
cw *countingWriter
isTransparent bool
isTransparentTLS bool
serverName string
req *http.Request
res *http.Response
idleTimeout time.Duration
id uint64
cr *countingReader
br *bufio.Reader
cw *countingWriter
transparent int
transparentTLS bool
serverName string
req *http.Request
res *http.Response
idleTimeout time.Duration
}
// NewContext returns an initialized context for the provided [net.Conn].
@@ -98,7 +96,6 @@ func NewContext(c net.Conn) Context {
return &proxyContext{
Conn: c,
id: binary.BigEndian.Uint64(b),
mac: arp.Get(c.RemoteAddr()),
cr: cr,
br: bufio.NewReader(cr),
cw: cw,
@@ -106,26 +103,23 @@ func NewContext(c net.Conn) Context {
}
}
func (c *proxyContext) AccessLogEntry() *logrus.Entry {
func (c *proxyContext) AccessLogEntry() logger.Structured {
var id [8]byte
binary.BigEndian.PutUint64(id[:], c.id)
entry := AccessLog.WithFields(logrus.Fields{
entry := AccessLog.Values(logger.Values{
"client": c.RemoteAddr().String(),
"server": c.LocalAddr().String(),
"id": hex.EncodeToString(id[:]),
"bytes_rx": c.BytesRead(),
"bytes_tx": c.BytesSent(),
})
if c.mac != nil {
return entry.WithField("client_mac", c.mac.String())
}
return entry
}
func (c *proxyContext) LogEntry() *logrus.Entry {
func (c *proxyContext) LogEntry() logger.Structured {
var id [8]byte
binary.BigEndian.PutUint64(id[:], c.id)
return ServerLog.WithFields(logrus.Fields{
return ServerLog.Values(logger.Values{
"client": c.RemoteAddr().String(),
"server": c.LocalAddr().String(),
"id": hex.EncodeToString(id[:]),