all: update use of ln

This commit is contained in:
Cadey Ratio 2017-10-01 06:28:13 -07:00
parent 4d05d9b7cd
commit f69257f5f8
No known key found for this signature in database
GPG Key ID: D607EE27C2E7F89A
8 changed files with 88 additions and 64 deletions

View File

@ -31,6 +31,7 @@ var allScopes = []string{
"token:get", "token:getall", "token:put", "token:delete", "token:deactivate", "token:get", "token:getall", "token:put", "token:delete", "token:deactivate",
"route:get", "route:getall", "route:put", "route:delete", "route:get", "route:getall", "route:put", "route:delete",
"connect", "connect",
"admin",
} }
var whoami string var whoami string
@ -123,10 +124,21 @@ func handle(w http.ResponseWriter, r *http.Request) {
func main() { func main() {
cmdline := kingpin.MustParse(app.Parse(os.Args[1:])) cmdline := kingpin.MustParse(app.Parse(os.Args[1:]))
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
retry_netrc:
n, err := netrc.Parse(*netrcPath) n, err := netrc.Parse(*netrcPath)
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "netrc.Parse"}) _, err := os.Stat(*netrcPath)
if err == os.ErrNotExist {
fout, err := os.Create(*netrcPath)
if err != nil {
ln.FatalErr(ctx, err, ln.Action("creating netrc"), ln.F{"path": *netrcPath})
}
fout.Close()
goto retry_netrc
}
} }
_ = n _ = n
@ -134,30 +146,30 @@ func main() {
case "test-server": case "test-server":
http.HandleFunc("/", handle) http.HandleFunc("/", handle)
ln.Fatal(ln.F{"err": http.ListenAndServe(*testServerAddr, nil), "action": "test_server"}) ln.FatalErr(ctx, http.ListenAndServe(*testServerAddr, nil), ln.Action("test server listenAndServe"))
case "generate-key": case "generate-key":
key, err := routecrypto.GenerateKey() key, err := routecrypto.GenerateKey()
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "routecrypto.GenerateKey"}) ln.FatalErr(ctx, err, ln.Action("generating encryption key"))
} }
fmt.Println("Your key is:", routecrypto.ShowKey(key)) fmt.Println("Your key is:", routecrypto.ShowKey(key))
case "token generate-root": case "token generate-root":
key, err := routecrypto.ParseKey(*tokenGenerateKey) key, err := routecrypto.ParseKey(*tokenGenerateKey)
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "routecrypto.ParseKey"}) ln.FatalErr(ctx, err, ln.Action("parsing encryption key"))
} }
db, err := database.NewBoltStorage(*tokenGenerateDatabasePath, key) db, err := database.NewBoltStorage(*tokenGenerateDatabasePath, key)
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "database.NewBoltStorage"}) ln.FatalErr(ctx, err, ln.Action("opening routed database"))
} }
tBody := uuid.New() tBody := uuid.New()
_, err = db.PutToken(context.Background(), tBody, *tokenGenerateUsername, *tokenGenerateScopes) _, err = db.PutToken(context.Background(), tBody, *tokenGenerateUsername, *tokenGenerateScopes)
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "db.PutToken"}) ln.FatalErr(ctx, err, ln.Action("add newly created token to database"))
} }
defer db.Close() defer db.Close()
@ -166,7 +178,7 @@ func main() {
n.AddMachine(*grpcServer, *tokenGenerateUsername, tBody) n.AddMachine(*grpcServer, *tokenGenerateUsername, tBody)
err = n.Save() err = n.Save()
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "n.Save"}) ln.FatalErr(ctx, err, ln.Action("add machine to netrc"))
} }
return return
@ -182,7 +194,7 @@ func main() {
grpc.WithTransportCredentials(connCreds), grpc.WithTransportCredentials(connCreds),
grpc.WithPerRPCCredentials(creds)) grpc.WithPerRPCCredentials(creds))
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "grpc.Dial"}) ln.FatalErr(ctx, err, ln.Action("dialing grpc server"), ln.F{"hostname": *grpcServer})
} }
rc := proto.NewRoutesClient(conn) rc := proto.NewRoutesClient(conn)
@ -195,19 +207,21 @@ func main() {
switch cmdline { switch cmdline {
case "route create": case "route create":
idr, err := rc.Put(context.Background(), &proto.Route{Host: *routesCreateDomain}) idr, err := rc.Put(ctx, &proto.Route{Host: *routesCreateDomain})
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "rc.Put"}) ln.FatalErr(ctx, err, ln.Action("create new route"))
} }
fmt.Println(idr.Id) fmt.Println("created route with id " + idr.Id)
return
case "route inspect": case "route inspect":
r, err := rc.Get(context.Background(), &proto.GetRouteRequest{ r, err := rc.Get(context.Background(), &proto.GetRouteRequest{
Host: *routesCreateDomain, Host: *routesCreateDomain,
}) })
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "rc.Get"}) ln.FatalErr(ctx, err, ln.Action("get single route"), ln.F{"domain": *routesCreateDomain})
} }
json.NewEncoder(os.Stdout).Encode(r) json.NewEncoder(os.Stdout).Encode(r)
@ -218,7 +232,7 @@ func main() {
case "route list": case "route list":
rts, err := rc.GetAll(context.Background(), &proto.Nil{}) rts, err := rc.GetAll(context.Background(), &proto.Nil{})
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "rc.GetAll"}) ln.FatalErr(ctx, err, ln.Action("get all routes"))
} }
table := tablewriter.NewWriter(os.Stdout) table := tablewriter.NewWriter(os.Stdout)
@ -235,7 +249,7 @@ func main() {
case "route rm": case "route rm":
_, err := rc.Delete(context.Background(), &proto.Route{Id: *routesRmID}) _, err := rc.Delete(context.Background(), &proto.Route{Id: *routesRmID})
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "rc.Delete"}) ln.FatalErr(ctx, err, ln.Action("remove single route"), ln.F{"id": *routesRmID})
} }
case "backend list": case "backend list":
@ -244,7 +258,7 @@ func main() {
User: *backendListUser, User: *backendListUser,
}) })
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "list backends"}) ln.FatalErr(ctx, err, ln.Action("list backends"))
} }
table := tablewriter.NewWriter(os.Stdout) table := tablewriter.NewWriter(os.Stdout)
@ -259,7 +273,7 @@ func main() {
case "backend kill": case "backend kill":
_, err := bc.Kill(context.Background(), &proto.BackendID{Id: *backendKillID}) _, err := bc.Kill(context.Background(), &proto.BackendID{Id: *backendKillID})
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "attempt to kill backend", "backend_id": *backendKillID}) ln.FatalErr(ctx, err, ln.Action("attempt to kill backend"), ln.F{"backend_id": *backendKillID})
} }
fmt.Println("killed backend " + *backendKillID) fmt.Println("killed backend " + *backendKillID)

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"context"
"crypto/tls" "crypto/tls"
"flag" "flag"
"os"
"git.xeserv.us/xena/route/lib/tun2" "git.xeserv.us/xena/route/lib/tun2"
"github.com/Xe/ln" "github.com/Xe/ln"
@ -34,9 +34,6 @@ func main() {
client, _ := tun2.NewClient(cfg) client, _ := tun2.NewClient(cfg)
err := client.Connect() err := client.Connect()
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.FatalErr(context.Background(), err, ln.Action("http agent is now running"))
"action": "client_running",
})
os.Exit(1)
} }
} }

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"context"
"crypto/tls" "crypto/tls"
"flag" "flag"
"log"
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"
@ -25,26 +25,29 @@ func main() {
flag.Parse() flag.Parse()
flagenv.Parse() flagenv.Parse()
rand.Seed(time.Now().Unix()) rand.Seed(time.Now().Unix())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
certKey, _ := routecrypto.ParseKey(*sslCertKey) certKey, _ := routecrypto.ParseKey(*sslCertKey)
scfg := server.Config{} scfg := server.Config{}
err := env.Parse(&scfg) err := env.Parse(&scfg)
if err != nil { if err != nil {
ln.Fatal(ln.F{"err": err, "action": "env.Parse()"}) ln.FatalErr(ctx, err, ln.Action("parsing environment for config"))
} }
scfg.CertKey = certKey scfg.CertKey = certKey
s, err := server.New(scfg) s, err := server.New(scfg)
if err != nil { if err != nil {
log.Fatal(err) ln.FatalErr(ctx, err, ln.Action("create server instance"))
} }
go setupTLS(s, scfg) go setupTLS(s, scfg)
// listen on HTTP listener
l, err := net.Listen("tcp", scfg.WebAddr) l, err := net.Listen("tcp", scfg.WebAddr)
if err != nil { if err != nil {
log.Fatal(err) ln.FatalErr(ctx, err, ln.Action("listening on HTTP port"), ln.F{"addr": scfg.WebAddr})
} }
defer l.Close() defer l.Close()
@ -65,5 +68,7 @@ func setupTLS(s *server.Server, scfg server.Config) {
}, },
} }
for {
hs.ListenAndServeTLS("", "") hs.ListenAndServeTLS("", "")
}
} }

View File

@ -56,7 +56,7 @@ func (b *BoltDBStorage) GetRoute(ctx context.Context, host string) (Route, error
r := Route{} r := Route{}
err := b.db.One("Hostname", host, &r) err := b.db.One("Hostname", host, &r)
if err != nil { if err != nil {
ln.Error(err, ln.F{"err": err, "action": "route_get_route"}) ln.Error(ctx, err, ln.F{"err": err, "action": "route_get_route"})
switch err { switch err {
case storm.ErrNotFound: case storm.ErrNotFound:

View File

@ -49,7 +49,7 @@ func (s *Server) getAuth(ctx context.Context, scope string) (database.Token, err
} }
func handleError(ctx context.Context, clitok database.Token, err error, f ln.F) error { func handleError(ctx context.Context, clitok database.Token, err error, f ln.F) error {
ln.Error(err, f, clitok.F()) ln.Error(ctx, err, f, clitok)
return err return err
} }

View File

@ -26,7 +26,7 @@ func (r *Route) Get(ctx context.Context, req *proto.GetRouteRequest) (*proto.Rou
val, err := r.db.GetRoute(ctx, req.Host) val, err := r.db.GetRoute(ctx, req.Host)
if err != nil { if err != nil {
ln.Error(err, ln.F{"action": "Route.Get"}) ln.Error(ctx, err, ln.F{"action": "Route.Get"})
return nil, err return nil, err
} }
@ -47,7 +47,7 @@ func (r *Route) GetAll(ctx context.Context, req *proto.Nil) (*proto.GetAllRoutes
routes, err := r.db.GetAllRoutes(ctx, clitok.Owner) routes, err := r.db.GetAllRoutes(ctx, clitok.Owner)
if err != nil { if err != nil {
ln.Error(err, ln.F{"action": "Route.GetAll"}) ln.Error(ctx, err, ln.F{"action": "Route.GetAll"})
return nil, err return nil, err
} }
@ -76,12 +76,12 @@ func (r *Route) Put(ctx context.Context, rt *proto.Route) (*proto.IDResponse, er
drt, err := r.db.PutRoute(ctx, rt.Host, clitok.Owner) drt, err := r.db.PutRoute(ctx, rt.Host, clitok.Owner)
if err != nil { if err != nil {
ln.Error(err, ln.F{"action": "Route.Put"}) ln.Error(ctx, err, ln.F{"action": "Route.Put"})
return nil, err return nil, err
} }
ln.Log(drt.F(), ln.F{"action": "Route.Put_success"}) ln.Log(ctx, drt, ln.F{"action": "Route.Put_success"})
return &proto.IDResponse{ return &proto.IDResponse{
Id: drt.ID, Id: drt.ID,
@ -96,7 +96,7 @@ func (r *Route) Delete(ctx context.Context, rt *proto.Route) (*proto.IDResponse,
drt, err := r.db.GetRoute(ctx, rt.Host) drt, err := r.db.GetRoute(ctx, rt.Host)
if err != nil { if err != nil {
ln.Error(err, ln.F{"action": "Route.Delete_getRoute_verify"}) ln.Error(ctx, err, ln.F{"action": "Route.Delete_getRoute_verify"})
return nil, err return nil, err
} }
@ -112,7 +112,7 @@ func (r *Route) Delete(ctx context.Context, rt *proto.Route) (*proto.IDResponse,
handleError(ctx, clitok, ErrNotAuthorized, f) handleError(ctx, clitok, ErrNotAuthorized, f)
} }
ln.Log(f, drt.F()) ln.Log(ctx, f, drt)
return &proto.IDResponse{Id: rt.Id}, nil return &proto.IDResponse{Id: rt.Id}, nil
} }

View File

@ -50,14 +50,18 @@ func (c *Connection) F() ln.F {
// Ping ends a "ping" to the client. If the client doesn't respond or the connection // Ping ends a "ping" to the client. If the client doesn't respond or the connection
// dies, then the connection needs to be cleaned up. // dies, then the connection needs to be cleaned up.
func (c *Connection) Ping() error { func (c *Connection) Ping() error {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
req, err := http.NewRequest("GET", "http://backend/health", nil) req, err := http.NewRequest("GET", "http://backend/health", nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }
req = req.WithContext(ctx)
_, err = c.RoundTrip(req) _, err = c.RoundTrip(req)
if err != nil { if err != nil {
ln.Error(err, c.F(), ln.F{"action": "ping_roundtrip"}) ln.Error(ctx, err, c, ln.Action("pinging the backend"))
return err return err
} }
@ -67,20 +71,20 @@ func (c *Connection) Ping() error {
} }
// OpenStream creates a new stream (connection) to the backend server. // OpenStream creates a new stream (connection) to the backend server.
func (c *Connection) OpenStream() (net.Conn, error) { func (c *Connection) OpenStream(ctx context.Context) (net.Conn, error) {
if !c.usable { if !c.usable {
return nil, ErrNoSuchBackend return nil, ErrNoSuchBackend
} }
err := c.conn.SetDeadline(time.Now().Add(time.Second)) err := c.conn.SetDeadline(time.Now().Add(time.Second))
if err != nil { if err != nil {
ln.Error(err, c.F()) ln.Error(ctx, err, c)
return nil, err return nil, err
} }
stream, err := c.session.OpenStream() stream, err := c.session.OpenStream()
if err != nil { if err != nil {
ln.Error(err, c.F()) ln.Error(ctx, err, c)
return nil, err return nil, err
} }
@ -117,7 +121,7 @@ var (
// RoundTrip forwards a HTTP request to the remote backend and then returns the // RoundTrip forwards a HTTP request to the remote backend and then returns the
// response, if any. // response, if any.
func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) { func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) {
stream, err := c.OpenStream() stream, err := c.OpenStream(req.Context())
if err != nil { if err != nil {
return nil, errors.Wrap(err, ErrCantOpenSessionStream.Error()) return nil, errors.Wrap(err, ErrCantOpenSessionStream.Error())
} }

View File

@ -146,7 +146,10 @@ func (s *Server) GetAllBackends() []Backend {
// ListenAndServe starts the backend TCP/KCP listeners and relays backend // ListenAndServe starts the backend TCP/KCP listeners and relays backend
// traffic to and from them. // traffic to and from them.
func (s *Server) ListenAndServe() error { func (s *Server) ListenAndServe() error {
ln.Log(ln.F{ ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ln.Log(ctx, ln.F{
"action": "listen_and_serve_called", "action": "listen_and_serve_called",
}) })
@ -157,7 +160,7 @@ func (s *Server) ListenAndServe() error {
panic(err) panic(err)
} }
ln.Log(ln.F{ ln.Log(ctx, ln.F{
"action": "tcp+tls_listening", "action": "tcp+tls_listening",
"addr": l.Addr(), "addr": l.Addr(),
}) })
@ -165,11 +168,11 @@ func (s *Server) ListenAndServe() error {
for { for {
conn, err := l.Accept() conn, err := l.Accept()
if err != nil { if err != nil {
ln.Error(err, ln.F{"kind": "tcp", "addr": l.Addr().String()}) ln.Error(ctx, err, ln.F{"kind": "tcp", "addr": l.Addr().String()})
continue continue
} }
ln.Log(ln.F{ ln.Log(ctx, ln.F{
"action": "new_client", "action": "new_client",
"kcp": false, "kcp": false,
"addr": conn.RemoteAddr(), "addr": conn.RemoteAddr(),
@ -187,7 +190,7 @@ func (s *Server) ListenAndServe() error {
panic(err) panic(err)
} }
ln.Log(ln.F{ ln.Log(ctx, ln.F{
"action": "kcp+tls_listening", "action": "kcp+tls_listening",
"addr": l.Addr(), "addr": l.Addr(),
}) })
@ -195,10 +198,10 @@ func (s *Server) ListenAndServe() error {
for { for {
conn, err := l.Accept() conn, err := l.Accept()
if err != nil { if err != nil {
ln.Error(err, ln.F{"kind": "kcp", "addr": l.Addr().String()}) ln.Error(ctx, err, ln.F{"kind": "kcp", "addr": l.Addr().String()})
} }
ln.Log(ln.F{ ln.Log(ctx, ln.F{
"action": "new_client", "action": "new_client",
"kcp": true, "kcp": true,
"addr": conn.RemoteAddr(), "addr": conn.RemoteAddr(),
@ -223,7 +226,7 @@ func (s *Server) ListenAndServe() error {
failureChance := c.detector.Phi(now) failureChance := c.detector.Phi(now)
if failureChance > 0.8 { if failureChance > 0.8 {
ln.Log(c.F(), ln.F{ ln.Log(ctx, c.F(), ln.F{
"action": "phi_failure_detection", "action": "phi_failure_detection",
"value": failureChance, "value": failureChance,
}) })
@ -247,7 +250,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
session, err := smux.Server(c, s.cfg.SmuxConf) session, err := smux.Server(c, s.cfg.SmuxConf)
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(ctx, err, ln.F{
"action": "session_failure", "action": "session_failure",
"local": c.LocalAddr().String(), "local": c.LocalAddr().String(),
"remote": c.RemoteAddr().String(), "remote": c.RemoteAddr().String(),
@ -261,7 +264,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
controlStream, err := session.OpenStream() controlStream, err := session.OpenStream()
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(ctx, err, ln.F{
"action": "control_stream_failure", "action": "control_stream_failure",
"local": c.LocalAddr().String(), "local": c.LocalAddr().String(),
"remote": c.RemoteAddr().String(), "remote": c.RemoteAddr().String(),
@ -275,7 +278,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
auth := &Auth{} auth := &Auth{}
err = csd.Decode(auth) err = csd.Decode(auth)
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(ctx, err, ln.F{
"action": "control_stream_auth_decoding_failure", "action": "control_stream_auth_decoding_failure",
"local": c.LocalAddr().String(), "local": c.LocalAddr().String(),
"remote": c.RemoteAddr().String(), "remote": c.RemoteAddr().String(),
@ -286,7 +289,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
routeUser, err := s.cfg.Storage.HasRoute(auth.Domain) routeUser, err := s.cfg.Storage.HasRoute(auth.Domain)
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(ctx, err, ln.F{
"action": "nosuch_domain", "action": "nosuch_domain",
"local": c.LocalAddr().String(), "local": c.LocalAddr().String(),
"remote": c.RemoteAddr().String(), "remote": c.RemoteAddr().String(),
@ -297,7 +300,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
tokenUser, scopes, err := s.cfg.Storage.HasToken(auth.Token) tokenUser, scopes, err := s.cfg.Storage.HasToken(auth.Token)
if err != nil { if err != nil {
ln.Error(err, ln.F{ ln.Error(ctx, err, ln.F{
"action": "nosuch_token", "action": "nosuch_token",
"local": c.LocalAddr().String(), "local": c.LocalAddr().String(),
"remote": c.RemoteAddr().String(), "remote": c.RemoteAddr().String(),
@ -315,7 +318,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
} }
if !ok { if !ok {
ln.Error(ErrAuthMismatch, ln.F{ ln.Error(ctx, ErrAuthMismatch, ln.F{
"action": "token_not_authorized", "action": "token_not_authorized",
"local": c.LocalAddr().String(), "local": c.LocalAddr().String(),
"remote": c.RemoteAddr().String(), "remote": c.RemoteAddr().String(),
@ -323,7 +326,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
} }
if routeUser != tokenUser { if routeUser != tokenUser {
ln.Error(ErrAuthMismatch, ln.F{ ln.Error(ctx, ErrAuthMismatch, ln.F{
"action": "auth_mismatch", "action": "auth_mismatch",
"local": c.LocalAddr().String(), "local": c.LocalAddr().String(),
"remote": c.RemoteAddr().String(), "remote": c.RemoteAddr().String(),
@ -346,11 +349,11 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
ln.Log(connection, ln.F{"action": "connection handler panic", "err": r}) ln.Log(ctx, connection, ln.F{"action": "connection handler panic", "err": r})
} }
}() }()
ln.Log(ln.F{ ln.Log(ctx, ln.F{
"action": "backend_connected", "action": "backend_connected",
}, connection.F()) }, connection.F())
@ -386,7 +389,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
connection.cancel() connection.cancel()
} }
case <-ctx.Done(): case <-ctx.Done():
s.RemoveConn(connection) s.RemoveConn(ctx, connection)
connection.Close() connection.Close()
return return
@ -395,7 +398,7 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
} }
// RemoveConn removes a connection. // RemoveConn removes a connection.
func (s *Server) RemoveConn(connection *Connection) { func (s *Server) RemoveConn(ctx context.Context, connection *Connection) {
s.connlock.Lock() s.connlock.Lock()
delete(s.conns, connection.conn) delete(s.conns, connection.conn)
s.connlock.Unlock() s.connlock.Unlock()
@ -408,7 +411,7 @@ func (s *Server) RemoveConn(connection *Connection) {
if ok { if ok {
conns, ok = val.([]*Connection) conns, ok = val.([]*Connection)
if !ok { if !ok {
ln.Error(ErrCantRemoveWhatDoesntExist, connection.F(), ln.F{ ln.Error(ctx, ErrCantRemoveWhatDoesntExist, connection.F(), ln.F{
"action": "looking_up_for_disconnect_removal", "action": "looking_up_for_disconnect_removal",
}) })
return return
@ -428,7 +431,7 @@ func (s *Server) RemoveConn(connection *Connection) {
s.domains.Remove(auth.Domain) s.domains.Remove(auth.Domain)
} }
ln.Log(connection.F(), ln.F{ ln.Log(ctx, connection.F(), ln.F{
"action": "client_disconnecting", "action": "client_disconnecting",
}) })
} }
@ -469,12 +472,13 @@ func gen502Page(req *http.Request) *http.Response {
// RoundTrip sends a HTTP request to a backend and then returns its response. // RoundTrip sends a HTTP request to a backend and then returns its response.
func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) { func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
var conns []*Connection var conns []*Connection
ctx := req.Context()
val, ok := s.domains.Get(req.Host) val, ok := s.domains.Get(req.Host)
if ok { if ok {
conns, ok = val.([]*Connection) conns, ok = val.([]*Connection)
if !ok { if !ok {
ln.Error(ErrNoSuchBackend, ln.F{ ln.Error(ctx, ErrNoSuchBackend, ln.F{
"action": "no_backend_connected", "action": "no_backend_connected",
"remote": req.RemoteAddr, "remote": req.RemoteAddr,
"host": req.Host, "host": req.Host,
@ -493,7 +497,7 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
} }
if len(goodConns) == 0 { if len(goodConns) == 0 {
ln.Error(ErrNoSuchBackend, ln.F{ ln.Error(ctx, ErrNoSuchBackend, ln.F{
"action": "no_backend_connected", "action": "no_backend_connected",
"remote": req.RemoteAddr, "remote": req.RemoteAddr,
"host": req.Host, "host": req.Host,
@ -507,7 +511,7 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
resp, err := c.RoundTrip(req) resp, err := c.RoundTrip(req)
if err != nil { if err != nil {
ln.Error(err, c.F(), ln.F{ ln.Error(ctx, err, c, ln.F{
"action": "connection_roundtrip", "action": "connection_roundtrip",
}) })
@ -515,7 +519,7 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) {
return nil, err return nil, err
} }
ln.Log(c.F(), ln.F{ ln.Log(ctx, c, ln.F{
"action": "http_traffic", "action": "http_traffic",
"remote_addr": req.RemoteAddr, "remote_addr": req.RemoteAddr,
"host": req.Host, "host": req.Host,