MCPcopy Create free account
hub / github.com/encodeous/nylon / HandleNylonIPC

Function HandleNylonIPC

core/ipc_handler.go:54–98  ·  view source on GitHub ↗
(n *Nylon, rw *bufio.ReadWriter)

Source from the content-addressed store, hash-verified

52}
53
54func HandleNylonIPC(n *Nylon, rw *bufio.ReadWriter) error {
55 req, err := readRequest(rw)
56 if err != nil {
57 if err := writeResponse(rw, errResponse(err.Error())); err != nil {
58 return err
59 }
60 return device.ErrIPCStatusHandled
61 }
62
63 // trace is blocking, so we dont dispatch
64 if _, ok := req.Request.(*protocol.IpcRequest_Trace); ok {
65 return handleTrace(n, rw)
66 }
67
68 done := make(chan *protocol.IpcResponse, 1)
69 n.Dispatch(func() error {
70 var resp *protocol.IpcResponse
71 switch req.Request.(type) {
72 case *protocol.IpcRequest_Status:
73 resp = handleStatus(n, req.GetStatus())
74 case *protocol.IpcRequest_Probe:
75 resp = handleIPCProbe(n, req.GetProbe())
76 case *protocol.IpcRequest_Reload:
77 resp = handleIPCReload(n, req.GetReload())
78 default:
79 resp = errResponse("unknown method")
80 }
81 done <- resp
82 return nil
83 })
84
85 var resp *protocol.IpcResponse
86 select {
87 case resp = <-done:
88 case <-n.Context.Done():
89 resp = errResponse("nylon shutting down")
90 case <-time.After(1 * time.Second):
91 // nylon is too busy to handle IPC requests
92 resp = errResponse("timed out waiting for dispatch")
93 }
94 if err := writeResponse(rw, resp); err != nil {
95 return err
96 }
97 return device.ErrIPCStatusHandled
98}
99
100func handleStatus(n *Nylon, req *protocol.StatusRequest) *protocol.IpcResponse {
101 activeEps := 0

Callers 3

ipcCallFunction · 0.92
TestIPCMalformedRequestFunction · 0.92
initWireGuardMethod · 0.85

Calls 13

readRequestFunction · 0.85
writeResponseFunction · 0.85
errResponseFunction · 0.85
handleTraceFunction · 0.85
handleStatusFunction · 0.85
handleIPCProbeFunction · 0.85
handleIPCReloadFunction · 0.85
DispatchMethod · 0.80
AfterMethod · 0.80
ErrorMethod · 0.45
GetStatusMethod · 0.45
GetProbeMethod · 0.45

Tested by 2

ipcCallFunction · 0.74
TestIPCMalformedRequestFunction · 0.74