Skip to content

Commit 73ec1ea

Browse files
committed
std: add remove to client
1 parent 8d7e426 commit 73ec1ea

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

std/object/client_produce.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ type ProduceArgs struct {
2727
FreshnessPeriod time.Duration
2828
}
2929

30-
// Produce and sign data, and insert into the client's store
31-
func (c *Client) Produce(args ProduceArgs) (enc.Name, error) {
32-
// TODO: sign the data
33-
signer := sec.NewSha256Signer()
34-
35-
return Produce(args, c.store, signer)
36-
}
37-
3830
// Produce and sign data, and insert into a store
3931
// This function does not rely on the engine or client, so it can also be used in YaNFD
4032
func Produce(args ProduceArgs, store ndn.Store, signer ndn.Signer) (enc.Name, error) {
@@ -138,6 +130,42 @@ func Produce(args ProduceArgs, store ndn.Store, signer ndn.Signer) (enc.Name, er
138130
return basename, nil
139131
}
140132

133+
// Produce and sign data, and insert into the client's store
134+
func (c *Client) Produce(args ProduceArgs) (enc.Name, error) {
135+
// TODO: sign the data
136+
signer := sec.NewSha256Signer()
137+
138+
return Produce(args, c.store, signer)
139+
}
140+
141+
// Remove an object from the client's store by name
142+
func (c *Client) Remove(name enc.Name) error {
143+
// This will clear the store (probably not what you want)
144+
if len(name) == 0 {
145+
return nil
146+
}
147+
148+
c.store.Begin()
149+
defer c.store.Commit()
150+
151+
// Remove object data
152+
err := c.store.Remove(name, true)
153+
if err != nil {
154+
return err
155+
}
156+
157+
// Remove RDR metadata if we have a version
158+
// If there is no version, we removed this anyway in the previous step
159+
if version := name[len(name)-1]; version.Typ == enc.TypeVersionNameComponent {
160+
err = c.store.Remove(append(name[:len(name)-1], rdr.METADATA, version), true)
161+
if err != nil {
162+
return err
163+
}
164+
}
165+
166+
return nil
167+
}
168+
141169
// onInterest looks up the store for the requested data
142170
func (c *Client) onInterest(args ndn.InterestHandlerArgs) {
143171
// TODO: consult security if we can send this

0 commit comments

Comments
 (0)