From 9a42b1ea4c14e22e8ebeb65d3d087e88bc17a0da Mon Sep 17 00:00:00 2001 From: Matthias Frei Date: Sat, 4 Nov 2023 20:12:25 +0100 Subject: [PATCH] hackathon: grcp server fixes, lots of debug printf --- BUILD.bazel | 2 +- control/cmd/control/main.go | 30 +++++++++++++++++++++++------- pkg/snet/squic/net.go | 13 ++++++++++--- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index c43159ca4e..2ad44fe769 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -177,7 +177,7 @@ pkg_tar( "//control/cmd/control", "//daemon/cmd/daemon", "//dispatcher/cmd/dispatcher", - "//gateway/cmd/gateway", + #"//gateway/cmd/gateway", "//router/cmd/router", "//scion-pki/cmd/scion-pki", "//scion/cmd/scion", diff --git a/control/cmd/control/main.go b/control/cmd/control/main.go index dc08bb30d7..a38c58711f 100644 --- a/control/cmd/control/main.go +++ b/control/cmd/control/main.go @@ -107,6 +107,14 @@ import ( trustmetrics "github.com/scionproto/scion/private/trust/metrics" ) +type loggingHandler struct{ next http.Handler } + +func (h loggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + fmt.Println(r.Method) + fmt.Println(r.URL) + h.next.ServeHTTP(w, r) +} + var globalCfg config.Config func main() { @@ -340,7 +348,7 @@ func realMain(ctx context.Context) error { Requests: libmetrics.NewPromCounter(cstrustmetrics.Handler.Requests), } // TODO needs a wrapper here... - connectMux.Handle(cpconnect.NewTrustMaterialServiceHandler(nil)) + //connectMux.Handle(cpconnect.NewTrustMaterialServiceHandler(nil)) cppb.RegisterTrustMaterialServiceServer(quicServer, trustServer) cppb.RegisterTrustMaterialServiceServer(tcpServer, trustServer) @@ -355,7 +363,11 @@ func realMain(ctx context.Context) error { }, } cppb.RegisterSegmentCreationServiceServer(quicServer, segmentCreationServer) - connectMux.Handle(cpconnect.NewSegmentCreationServiceHandler(beaconingconnect.SegmentCreationServer{SegmentCreationServer: segmentCreationServer})) + { + pattern, handler := cpconnect.NewSegmentCreationServiceHandler(beaconingconnect.SegmentCreationServer{SegmentCreationServer: segmentCreationServer}) + fmt.Println(pattern) + connectMux.Handle(pattern, handler) + } // Handle segment lookup authLookupServer := &segreqgrpc.LookupServer{ @@ -387,7 +399,6 @@ func realMain(ctx context.Context) error { // Always register a forwarding lookup for AS internal requests. cppb.RegisterSegmentLookupServiceServer(tcpServer, forwardingLookupServer) - connectMux.Handle(cpconnect.NewSegmentLookupServiceHandler(segreqconnect.LookupServer{LookupServer: forwardingLookupServer})) if topo.Core() { cppb.RegisterSegmentLookupServiceServer(quicServer, authLookupServer) connectMux.Handle(cpconnect.NewSegmentLookupServiceHandler(segreqconnect.LookupServer{LookupServer: authLookupServer})) @@ -687,7 +698,7 @@ func realMain(ctx context.Context) error { var cleanup app.Cleanup connectServer := http3.Server{ - Handler: connectMux, + Handler: loggingHandler{connectMux}, } grpcConns := make(chan quic.Connection) @@ -705,13 +716,15 @@ func realMain(ctx context.Context) error { } go func() { defer log.HandlePanic() - + fmt.Println("protocol", conn.ConnectionState().TLS.NegotiatedProtocol) if conn.ConnectionState().TLS.NegotiatedProtocol == "h3" { if err := connectServer.ServeQUICConn(conn); err != nil { log.Debug(err.Error()) } } else { + fmt.Println("<- conn") grpcConns <- conn + fmt.Println("<- conn ok") } }() } @@ -719,10 +732,13 @@ func realMain(ctx context.Context) error { g.Go(func() error { defer log.HandlePanic() - grpcListener := squic.NewConnListener(grpcConns) + grpcListener := squic.NewConnListener(grpcConns, quicStack.Listener.Addr()) + fmt.Println("serving gRPC") if err := quicServer.Serve(grpcListener); err != nil { - return serrors.WrapStr("serving gRPC/TCP API", err) + panic(err) + //return serrors.WrapStr("serving gRPC/TCP API", err) } + fmt.Println("whwwwwat?") return nil }) cleanup.Add(func() error { quicServer.GracefulStop(); return nil }) diff --git a/pkg/snet/squic/net.go b/pkg/snet/squic/net.go index 65500d213f..ee8ed6f292 100644 --- a/pkg/snet/squic/net.go +++ b/pkg/snet/squic/net.go @@ -53,28 +53,33 @@ type ConnListener struct { ctx context.Context cancel func() + + addr net.Addr } // NewConnListener constructs a new listener with the appropriate buffers set. -func NewConnListener(conns <-chan quic.Connection) *ConnListener { +func NewConnListener(conns <-chan quic.Connection, addr net.Addr) *ConnListener { ctx, cancel := context.WithCancel(context.Background()) c := &ConnListener{ Conns: conns, ctx: ctx, cancel: cancel, + addr: addr, } return c } func (l *ConnListener) Addr() net.Addr { - // TODO - return nil + fmt.Println("Addr():", l.addr) + return l.addr } // Accept accepts the first stream on a session and wraps it as a net.Conn. func (l *ConnListener) Accept() (net.Conn, error) { + fmt.Println("accept") select { case conn := <-l.Conns: + fmt.Println("conn <-") return newAcceptingConn(l.ctx, conn), nil case <-l.ctx.Done(): return nil, l.ctx.Err() @@ -84,8 +89,10 @@ func (l *ConnListener) Accept() (net.Conn, error) { // AcceptCtx accepts the first stream on a session and wraps it as a net.Conn. Accepts a context in // case the caller doesn't want this to block indefinitely. func (l *ConnListener) AcceptCtx(ctx context.Context) (net.Conn, error) { + fmt.Println("acceptctx") select { case conn := <-l.Conns: + fmt.Println("conn ctx <-") return newAcceptingConn(ctx, conn), nil case <-ctx.Done(): return nil, ctx.Err()