chore: module payload evaluation

This commit is contained in:
0x1a8510f2 2023-01-15 14:34:00 +00:00
parent e7ccc37c26
commit fc9c12195a
Signed by: 0x1a8510f2
GPG Key ID: 1C692E355D76775D
3 changed files with 29 additions and 7 deletions

View File

@ -10,7 +10,7 @@ type PacketReq struct {
// Which shm fields should be written to and the
// values that should be written.
Write map[string]interface{}
Write map[string]any
// Whether to return a list of all active memory cells
// in the response. Runs after Req.Payload.Write.

View File

@ -6,10 +6,7 @@ type PacketRes struct {
// The main body of the response.
Payload struct {
// A map of all read cells and their contents.
Read map[string]interface{}
// An array of all cells which were successfully written.
Written []string
Read map[string]any
// An array of all cells present in the shm if it was
// requested.

View File

@ -86,15 +86,40 @@ func (m *ModulePinecomms) handleRequest(ctx context.Context, w *libwraith.Wraith
// Execute the packet payload.
//
// TODO
// Read cells.
readCells := make(map[string]any, len(packetData.Payload.Read))
for _, cell := range packetData.Payload.Read {
readCells[cell] = w.SHMGet(cell)
}
// Write cells.
for cell, value := range packetData.Payload.Write {
w.SHMSet(cell, value)
}
// List cells.
var memList []string
if packetData.Payload.ListMem {
mem := w.SHMDump()
memList = make([]string, 0, len(mem))
for key := range mem {
memList = append(memList, key)
}
}
//
// Respond to the packet.
//
responseData := proto.PacketRes{
Payload: struct {
Read map[string]any
MemList []string
}{
Read: readCells,
MemList: memList,
},
TxId: packetData.TxId,
// TODO
}
responseDataBytes, err := proto.Marshal(&responseData, m.OwnPrivKey)