Skip to content

Commit

Permalink
Implement handlers and policy enforcer helpers
Browse files Browse the repository at this point in the history
Also does go mod tidy/vendor

Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Jan 6, 2025
1 parent 301ac92 commit e93affb
Show file tree
Hide file tree
Showing 100 changed files with 8,029 additions and 168 deletions.
162 changes: 0 additions & 162 deletions cmd/gcs-sidecar/bridge/handlers.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// - b.quitCh is to be used if stop/shutdownContainer validation fails only right?
// - cherry pick commit to add annotations for securityPolicy
// - shimdiag.exe exec uvmID

// TODO: Do we need to support schema1 request types?
type requestMessage interface {

Check failure on line 28 in cmd/gcs-sidecar/internal/bridge/bridge.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type `requestMessage` is unused (unused)
Base() *requestBase
}
Expand All @@ -33,6 +33,7 @@ type responseMessage interface {
Base() *responseBase
}

/*
// rpc represents an outstanding rpc request to the guest
type rpc struct {
proc rpcProc
Expand All @@ -42,7 +43,7 @@ type rpc struct {
brdgErr error // error encountered when sending the request or unmarshaling the result
ch chan struct{}
}

*/
// TODO: 'B'ridge to 'b'ridge
type Bridge struct {
shimConn io.ReadWriteCloser
Expand Down Expand Up @@ -170,7 +171,7 @@ func (b *Bridge) AssignHandlers() {
b.HandleFunc(rpcStart, b.startContainer)
b.HandleFunc(rpcShutdownGraceful, b.shutdownGraceful)
b.HandleFunc(rpcShutdownForced, b.shutdownForced)
b.HandleFunc(rpcExecuteProcess, b.createProcess)
b.HandleFunc(rpcExecuteProcess, b.executeProcess)
b.HandleFunc(rpcWaitForProcess, b.waitForProcess)
b.HandleFunc(rpcSignalProcess, b.signalProcess)
b.HandleFunc(rpcResizeConsole, b.resizeConsole)
Expand All @@ -183,6 +184,12 @@ func (b *Bridge) AssignHandlers() {
b.HandleFunc(rpcLifecycleNotification, b.lifecycleNotification) // TODO: Validate this request as well?
}

type messageHeader struct {
Type uint32
Size uint32
ID int64
}

func readMessage(r io.Reader) (request, error) {
var h [hdrSize]byte
_, err := io.ReadFull(r, h[:])
Expand Down Expand Up @@ -244,7 +251,12 @@ func (b *Bridge) ListenAndServeShimRequests() error {
recverr = errors.Wrap(err, "bridge read from shim failed:")
break
}
log.Printf("bridge recv from shim: \n Header: %v \n msg: %v \n", "", string(req.message))
var header messageHeader
messageTyp := msgType(binary.LittleEndian.Uint32(req.header[hdrOffType:]))
header.Type = binary.LittleEndian.Uint32(req.header[hdrOffType:])
header.Size = binary.LittleEndian.Uint32(req.header[hdrOffSize:])
header.ID = int64(binary.LittleEndian.Uint64(req.header[hdrOffID:]))
log.Printf("bridge recv from shim: \n Header {Type: %v Size: %v ID: %v }\n msg: %v \n", messageTyp, header.Size, header.ID, string(req.message))
shimRequestChan <- req
}
shimRequestErrChan <- recverr
Expand All @@ -261,6 +273,7 @@ func (b *Bridge) ListenAndServeShimRequests() error {
// 2. Code cleanup on error
// ? b.close(err)
// b.quitCh <- true // give few seconds delay and close connections?
b.close(err)
return
}

Expand Down
Loading

0 comments on commit e93affb

Please sign in to comment.