Skip to content

Commit e3c0b91

Browse files
committed
fw: remove makeControlResponse
1 parent 4cb5f31 commit e3c0b91

10 files changed

+260
-428
lines changed

fw/face/internal-transport.go

+8-19
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
enc "github.com/named-data/ndnd/std/encoding"
1616
spec_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"
1918
)
2019

2120
// InternalTransport is a transport for use by internal YaNFD modules (e.g., management).
@@ -79,19 +78,8 @@ func (t *InternalTransport) GetSendQueueSize() uint64 {
7978
}
8079

8180
// Send sends a packet from the perspective of the internal component.
82-
func (t *InternalTransport) Send(netWire enc.Wire, pitToken []byte, nextHopFaceID *uint64) {
83-
lpPkt := &spec.LpPacket{
84-
Fragment: netWire,
85-
}
86-
if len(pitToken) > 0 {
87-
lpPkt.PitToken = append([]byte{}, pitToken...)
88-
}
89-
if nextHopFaceID != nil {
90-
lpPkt.NextHopFaceId = utils.IdPtr(*nextHopFaceID)
91-
}
92-
pkt := &spec.Packet{
93-
LpPacket: lpPkt,
94-
}
81+
func (t *InternalTransport) Send(lpPkt *spec.LpPacket) {
82+
pkt := &spec.Packet{LpPacket: lpPkt}
9583
encoder := spec.PacketEncoder{}
9684
encoder.Init(pkt)
9785
lpPacketWire := encoder.Encode(pkt)
@@ -103,7 +91,7 @@ func (t *InternalTransport) Send(netWire enc.Wire, pitToken []byte, nextHopFaceI
10391
}
10492

10593
// Receive receives a packet from the perspective of the internal component.
106-
func (t *InternalTransport) Receive() (enc.Wire, []byte, uint64) {
94+
func (t *InternalTransport) Receive() *spec.LpPacket {
10795
for frame := range t.recvQueue {
10896
packet, _, err := spec.ReadPacket(enc.NewBufferReader(frame))
10997
if err != nil {
@@ -112,15 +100,15 @@ func (t *InternalTransport) Receive() (enc.Wire, []byte, uint64) {
112100
}
113101

114102
lpPkt := packet.LpPacket
115-
if lpPkt.Fragment.Length() == 0 {
103+
if packet.LpPacket == nil || lpPkt.Fragment.Length() == 0 {
116104
core.LogWarn(t, "Received empty fragment - DROP")
117105
continue
118106
}
119107

120-
return lpPkt.Fragment, lpPkt.PitToken, *lpPkt.IncomingFaceId
108+
return lpPkt
121109
}
122110

123-
return nil, []byte{}, 0
111+
return nil
124112
}
125113

126114
func (t *InternalTransport) sendFrame(frame []byte) {
@@ -150,6 +138,7 @@ func (t *InternalTransport) runReceive() {
150138

151139
func (t *InternalTransport) Close() {
152140
if t.running.Swap(false) {
153-
// do not close the queues, let them be garbage collected
141+
// do not close the send queue, let it be garbage collected
142+
close(t.recvQueue)
154143
}
155144
}

fw/mgmt/cs.go

+13-25
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ import (
1414
"github.com/named-data/ndnd/fw/table"
1515
enc "github.com/named-data/ndnd/std/encoding"
1616
mgmt "github.com/named-data/ndnd/std/ndn/mgmt_2022"
17-
spec "github.com/named-data/ndnd/std/ndn/spec_2022"
1817
"github.com/named-data/ndnd/std/utils"
1918
)
2019

2120
// ContentStoreModule is the module that handles Content Store Management.
2221
type ContentStoreModule struct {
23-
manager *Thread
24-
nextDatasetVersion uint64
22+
manager *Thread
2523
}
2624

2725
func (c *ContentStoreModule) String() string {
@@ -36,7 +34,7 @@ func (c *ContentStoreModule) getManager() *Thread {
3634
return c.manager
3735
}
3836

39-
func (c *ContentStoreModule) handleIncomingInterest(interest *spec.Interest, pitToken []byte, inFace uint64) {
37+
func (c *ContentStoreModule) handleIncomingInterest(interest *Interest) {
4038
// Only allow from /localhost
4139
if !LOCAL_PREFIX.IsPrefix(interest.Name()) {
4240
core.LogWarn(c, "Received CS management Interest from non-local source - DROP")
@@ -47,40 +45,36 @@ func (c *ContentStoreModule) handleIncomingInterest(interest *spec.Interest, pit
4745
verb := interest.Name()[len(LOCAL_PREFIX)+1].String()
4846
switch verb {
4947
case "config":
50-
c.config(interest, pitToken, inFace)
48+
c.config(interest)
5149
case "erase":
5250
// TODO
53-
//c.erase(interest, pitToken, inFace)
51+
//c.erase(interest)
5452
case "info":
55-
c.info(interest, pitToken, inFace)
53+
c.info(interest)
5654
default:
5755
core.LogWarn(c, "Received Interest for non-existent verb '", verb, "'")
58-
response := makeControlResponse(501, "Unknown verb", nil)
59-
c.manager.sendResponse(response, interest, pitToken, inFace)
56+
c.manager.sendCtrlResp(interest, 501, "Unknown verb", nil)
6057
return
6158
}
6259
}
6360

64-
func (c *ContentStoreModule) config(interest *spec.Interest, pitToken []byte, inFace uint64) {
61+
func (c *ContentStoreModule) config(interest *Interest) {
6562
if len(interest.Name()) < len(LOCAL_PREFIX)+3 {
6663
// Name not long enough to contain ControlParameters
6764
core.LogWarn(c, "Missing ControlParameters in ", interest.Name())
68-
response := makeControlResponse(400, "ControlParameters is incorrect", nil)
69-
c.manager.sendResponse(response, interest, pitToken, inFace)
65+
c.manager.sendCtrlResp(interest, 400, "ControlParameters is incorrect", nil)
7066
return
7167
}
7268

7369
params := decodeControlParameters(c, interest)
7470
if params == nil {
75-
response := makeControlResponse(400, "ControlParameters is incorrect", nil)
76-
c.manager.sendResponse(response, interest, pitToken, inFace)
71+
c.manager.sendCtrlResp(interest, 400, "ControlParameters is incorrect", nil)
7772
return
7873
}
7974

8075
if (params.Flags == nil && params.Mask != nil) || (params.Flags != nil && params.Mask == nil) {
8176
core.LogWarn(c, "Flags and Mask fields must either both be present or both be not present")
82-
response := makeControlResponse(409, "ControlParameters are incorrect", nil)
83-
c.manager.sendResponse(response, interest, pitToken, inFace)
77+
c.manager.sendCtrlResp(interest, 409, "ControlParameters are incorrect", nil)
8478
return
8579
}
8680

@@ -103,14 +97,13 @@ func (c *ContentStoreModule) config(interest *spec.Interest, pitToken []byte, in
10397
}
10498
}
10599

106-
response := makeControlResponse(200, "OK", &mgmt.ControlArgs{
100+
c.manager.sendCtrlResp(interest, 200, "OK", &mgmt.ControlArgs{
107101
Capacity: utils.IdPtr(uint64(table.CsCapacity())),
108102
Flags: utils.IdPtr(c.getFlags()),
109103
})
110-
c.manager.sendResponse(response, interest, pitToken, inFace)
111104
}
112105

113-
func (c *ContentStoreModule) info(interest *spec.Interest, pitToken []byte, _ uint64) {
106+
func (c *ContentStoreModule) info(interest *Interest) {
114107
if len(interest.Name()) > len(LOCAL_PREFIX)+2 {
115108
// Ignore because contains version and/or segment components
116109
return
@@ -133,12 +126,7 @@ func (c *ContentStoreModule) info(interest *spec.Interest, pitToken []byte, _ ui
133126
enc.NewStringComponent(enc.TypeGenericNameComponent, "cs"),
134127
enc.NewStringComponent(enc.TypeGenericNameComponent, "info"),
135128
)
136-
segments := makeStatusDataset(name, c.nextDatasetVersion, status.Encode())
137-
c.manager.transport.Send(segments, pitToken, nil)
138-
139-
core.LogTrace(c, "Published forwarder status dataset version=", c.nextDatasetVersion,
140-
", containing ", len(segments), " segments")
141-
c.nextDatasetVersion++
129+
c.manager.sendStatusDataset(interest, name, status.Encode())
142130
}
143131

144132
func (c *ContentStoreModule) getFlags() uint64 {

0 commit comments

Comments
 (0)