Skip to content

Commit

Permalink
hackathon: grcp server fixes, lots of debug printf
Browse files Browse the repository at this point in the history
  • Loading branch information
matzf committed Nov 4, 2023
1 parent 1653a86 commit 97d8d3e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 23 additions & 7 deletions control/cmd/control/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)

Expand All @@ -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{
Expand Down Expand Up @@ -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}))
Expand Down Expand Up @@ -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)
Expand All @@ -705,24 +716,29 @@ 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")
}
}()
}
})

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 })
Expand Down
13 changes: 10 additions & 3 deletions pkg/snet/squic/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 97d8d3e

Please sign in to comment.