Skip to content

Commit eeba80a

Browse files
committed
fw: refactor mgmt typing
1 parent 7228737 commit eeba80a

File tree

6 files changed

+177
-199
lines changed

6 files changed

+177
-199
lines changed

fw/mgmt/cs.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
enc "github.com/named-data/ndnd/std/encoding"
1616
mgmt "github.com/named-data/ndnd/std/ndn/mgmt_2022"
1717
spec "github.com/named-data/ndnd/std/ndn/spec_2022"
18+
"github.com/named-data/ndnd/std/utils"
1819
)
1920

2021
// ContentStoreModule is the module that handles Content Store Management.
@@ -61,26 +62,24 @@ func (c *ContentStoreModule) handleIncomingInterest(interest *spec.Interest, pit
6162
}
6263

6364
func (c *ContentStoreModule) config(interest *spec.Interest, pitToken []byte, inFace uint64) {
64-
var response *mgmt.ControlResponse
65-
6665
if len(interest.Name()) < len(LOCAL_PREFIX)+3 {
6766
// Name not long enough to contain ControlParameters
6867
core.LogWarn(c, "Missing ControlParameters in ", interest.Name())
69-
response = makeControlResponse(400, "ControlParameters is incorrect", nil)
68+
response := makeControlResponse(400, "ControlParameters is incorrect", nil)
7069
c.manager.sendResponse(response, interest, pitToken, inFace)
7170
return
7271
}
7372

7473
params := decodeControlParameters(c, interest)
7574
if params == nil {
76-
response = makeControlResponse(400, "ControlParameters is incorrect", nil)
75+
response := makeControlResponse(400, "ControlParameters is incorrect", nil)
7776
c.manager.sendResponse(response, interest, pitToken, inFace)
7877
return
7978
}
8079

8180
if (params.Flags == nil && params.Mask != nil) || (params.Flags != nil && params.Mask == nil) {
8281
core.LogWarn(c, "Flags and Mask fields must either both be present or both be not present")
83-
response = makeControlResponse(409, "ControlParameters are incorrect", nil)
82+
response := makeControlResponse(409, "ControlParameters are incorrect", nil)
8483
c.manager.sendResponse(response, interest, pitToken, inFace)
8584
return
8685
}
@@ -104,12 +103,10 @@ func (c *ContentStoreModule) config(interest *spec.Interest, pitToken []byte, in
104103
}
105104
}
106105

107-
responseParams := map[string]any{
108-
"Capacity": uint64(table.CsCapacity()),
109-
"Flags": c.getFlags(),
110-
}
111-
112-
response = makeControlResponse(200, "OK", responseParams)
106+
response := makeControlResponse(200, "OK", &mgmt.ControlArgs{
107+
Capacity: utils.IdPtr(uint64(table.CsCapacity())),
108+
Flags: utils.IdPtr(c.getFlags()),
109+
})
113110
c.manager.sendResponse(response, interest, pitToken, inFace)
114111
}
115112

0 commit comments

Comments
 (0)