Skip to content

Commit

Permalink
all: adapt to chained append
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jan 31, 2025
1 parent ed6a64b commit dbb0b53
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 99 deletions.
59 changes: 26 additions & 33 deletions dv/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import (
const CostInfinity = uint64(16)
const NlsrOrigin = uint64(mgmt.RouteOriginNLSR)

var MulticastStrategy = enc.LOCALHOST.Append(
enc.NewGenericComponent("nfd"),
enc.NewGenericComponent("strategy"),
enc.NewGenericComponent("multicast"),
)
var MulticastStrategy = enc.LOCALHOST.
Append(enc.NewGenericComponent("nfd")).
Append(enc.NewGenericComponent("strategy")).
Append(enc.NewGenericComponent("multicast"))

//go:embed schema.tlv
var SchemaBytes []byte
Expand Down Expand Up @@ -136,40 +135,34 @@ func (c *Config) Parse() (err error) {
}

// Advertisement sync and data prefixes
c.advSyncPfxN = enc.LOCALHOP.Append(c.networkNameN.Append(
enc.NewKeywordComponent("DV"),
enc.NewKeywordComponent("ADS"),
)...)
c.advSyncActivePfxN = c.advSyncPfxN.Append(
enc.NewKeywordComponent("ACT"),
)
c.advSyncPassivePfxN = c.advSyncPfxN.Append(
enc.NewKeywordComponent("PSV"),
)
c.advDataPfxN = enc.LOCALHOP.Append(c.routerNameN.Append(
enc.NewKeywordComponent("DV"),
enc.NewKeywordComponent("ADV"),
)...)
c.advSyncPfxN = enc.LOCALHOP.
Append(c.networkNameN...).
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewKeywordComponent("ADS"))
c.advSyncActivePfxN = c.advSyncPfxN.
Append(enc.NewKeywordComponent("ACT"))
c.advSyncPassivePfxN = c.advSyncPfxN.
Append(enc.NewKeywordComponent("PSV"))
c.advDataPfxN = enc.LOCALHOP.
Append(c.routerNameN...).
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewKeywordComponent("ADV"))

// Prefix table sync prefix
c.pfxSyncPfxN = c.networkNameN.Append(
enc.NewKeywordComponent("DV"),
enc.NewKeywordComponent("PFS"),
)
c.pfxSyncPfxN = c.networkNameN.
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewKeywordComponent("PFS"))

// Router data prefix including prefix data and certificates
c.routerDataPfxN = c.routerNameN.Append(
enc.NewKeywordComponent("DV"),
)
c.pfxDataPfxN = c.routerNameN.Append(
enc.NewKeywordComponent("DV"),
enc.NewKeywordComponent("PFX"),
)
c.routerDataPfxN = c.routerNameN.
Append(enc.NewKeywordComponent("DV"))
c.pfxDataPfxN = c.routerNameN.
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewKeywordComponent("PFX"))

// Local prefixes to NFD
c.mgmtPrefix = enc.LOCALHOST.Append(
enc.NewGenericComponent("nlsr"),
)
c.mgmtPrefix = enc.LOCALHOST.
Append(enc.NewGenericComponent("nlsr"))

return nil
}
Expand Down
13 changes: 7 additions & 6 deletions dv/dv/advert_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ func (a *advertModule) dataFetch(nName enc.Name, bootTime uint64, seqNo uint64)
}

// Fetch the advertisement
advName := enc.LOCALHOP.Append(nName.Append(
enc.NewKeywordComponent("DV"),
enc.NewKeywordComponent("ADV"),
enc.NewTimestampComponent(bootTime),
)...)
advName := enc.LOCALHOP.
Append(nName...).
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewKeywordComponent("ADV")).
Append(enc.NewTimestampComponent(bootTime)).
WithVersion(seqNo)

a.dv.client.Consume(advName.WithVersion(seqNo), func(state ndn.ConsumeState) {
a.dv.client.Consume(advName, func(state ndn.ConsumeState) {
if !state.IsComplete() {
return
}
Expand Down
13 changes: 6 additions & 7 deletions dv/table/neighbor_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,15 @@ func (ns *NeighborState) delete() {
}

func (ns *NeighborState) localRoute() enc.Name {
return enc.LOCALHOP.Append(ns.Name.Append(
enc.NewKeywordComponent("DV"),
)...)
return enc.LOCALHOP.
Append(ns.Name...).
Append(enc.NewKeywordComponent("DV"))
}

func (ns *NeighborState) certRoute() enc.Name {
return ns.Name.Append(
enc.NewKeywordComponent("DV"),
enc.NewGenericComponent("KEY"),
)
return ns.Name.
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewGenericComponent("KEY"))
}

// Register route to this neighbor
Expand Down
13 changes: 6 additions & 7 deletions dv/table/prefix_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,17 @@ func (pt *PrefixTable) Apply(ops *tlv.PrefixOpList) (dirty bool) {
func (r *PrefixTableRouter) GetNextDataName() enc.Name {
// /<router>/32=DV/32=PFX/t=<boot>/32=SNAP/v=<seq>
// /<router>/32=DV/32=PFX/t=<boot>/seq=<seq>/v=0
name := r.Name.Append(
enc.NewKeywordComponent("DV"),
enc.NewKeywordComponent("PFX"),
enc.NewTimestampComponent(r.BootTime),
)
prefix := r.Name.
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewKeywordComponent("PFX")).
Append(enc.NewTimestampComponent(r.BootTime))

if r.Latest-r.Known > PrefixSnapThreshold {
return name.
return prefix.
Append(enc.NewKeywordComponent(PrefixSnapKeyword))
}

return name.
return prefix.
Append(enc.NewSequenceNumComponent(r.Known + 1)).
WithVersion(enc.VersionImmutable)
}
Expand Down
6 changes: 3 additions & 3 deletions fw/defn/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ var NON_LOCAL_PREFIX = enc.Name{enc.LOCALHOP, enc.NewGenericComponent("nfd")}
var STRATEGY_PREFIX = LOCAL_PREFIX.Append(enc.NewGenericComponent("strategy"))

// Default forwarding strategy name
var DEFAULT_STRATEGY = STRATEGY_PREFIX.Append(
enc.NewGenericComponent("best-route"),
enc.NewVersionComponent(1))
var DEFAULT_STRATEGY = STRATEGY_PREFIX.
Append(enc.NewGenericComponent("best-route")).
Append(enc.NewVersionComponent(1))
7 changes: 3 additions & 4 deletions fw/fw/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ func (s *StrategyBase) NewStrategyBase(
) {
s.thread = fwThread
s.threadID = s.thread.threadID
s.name = defn.STRATEGY_PREFIX.Append(
enc.NewGenericComponent(name),
enc.NewVersionComponent(version),
)
s.name = defn.STRATEGY_PREFIX.
Append(enc.NewGenericComponent(name)).
Append(enc.NewVersionComponent(version))
s.version = version
s.logName = name
}
Expand Down
7 changes: 3 additions & 4 deletions fw/mgmt/cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ func (c *ContentStoreModule) info(interest *Interest) {
status.CsInfo.NCsEntries += uint64(thread.GetNumCsEntries())
}

name := LOCAL_PREFIX.Append(
enc.NewGenericComponent("cs"),
enc.NewGenericComponent("info"),
)
name := LOCAL_PREFIX.
Append(enc.NewGenericComponent("cs")).
Append(enc.NewGenericComponent("info"))
c.manager.sendStatusDataset(interest, name, status.Encode())
}

Expand Down
7 changes: 3 additions & 4 deletions fw/mgmt/face.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,9 @@ func (f *FaceModule) list(interest *Interest) {
dataset.Vals = append(dataset.Vals, f.createDataset(faces[pos]))
}

name := LOCAL_PREFIX.Append(
enc.NewGenericComponent("faces"),
enc.NewGenericComponent("list"),
)
name := LOCAL_PREFIX.
Append(enc.NewGenericComponent("faces")).
Append(enc.NewGenericComponent("list"))
f.manager.sendStatusDataset(interest, name, dataset.Encode())
}

Expand Down
7 changes: 3 additions & 4 deletions fw/mgmt/fib.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ func (f *FIBModule) list(interest *Interest) {
dataset.Entries = append(dataset.Entries, fibEntry)
}

name := LOCAL_PREFIX.Append(
enc.NewGenericComponent("fib"),
enc.NewGenericComponent("list"),
)
name := LOCAL_PREFIX.
Append(enc.NewGenericComponent("fib")).
Append(enc.NewGenericComponent("list"))
f.manager.sendStatusDataset(interest, name, dataset.Encode())
}
7 changes: 3 additions & 4 deletions fw/mgmt/forwarder-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ func (f *ForwarderStatusModule) general(interest *Interest) {
status.NUnsatisfiedInterests += thread.(*fw.Thread).NUnsatisfiedInterests
}

name := LOCAL_PREFIX.Append(
enc.NewGenericComponent("status"),
enc.NewGenericComponent("general"),
)
name := LOCAL_PREFIX.
Append(enc.NewGenericComponent("status")).
Append(enc.NewGenericComponent("general"))
f.manager.sendStatusDataset(interest, name, status.Encode())
}
7 changes: 3 additions & 4 deletions fw/mgmt/rib.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ func (r *RIBModule) list(interest *Interest) {
dataset.Entries = append(dataset.Entries, ribEntry)
}

name := interest.Name()[:len(LOCAL_PREFIX)].Append(
enc.NewGenericComponent("rib"),
enc.NewGenericComponent("list"),
)
name := interest.Name()[:len(LOCAL_PREFIX)].
Append(enc.NewGenericComponent("rib")).
Append(enc.NewGenericComponent("list"))
r.manager.sendStatusDataset(interest, name, dataset.Encode())
}
3 changes: 2 additions & 1 deletion fw/mgmt/strategy-choice.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func (s *StrategyChoiceModule) set(interest *Interest) {
}
} else {
// Add missing version information to strategy name
params.Strategy.Name = params.Strategy.Name.Append(enc.NewVersionComponent(strategyVersion))
params.Strategy.Name = params.Strategy.Name.
Append(enc.NewVersionComponent(strategyVersion))
}
table.FibStrategyTable.SetStrategyEnc(params.Name, params.Strategy.Name)

Expand Down
9 changes: 4 additions & 5 deletions std/object/client_produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ func Produce(args ndn.ProduceArgs, store ndn.Store, signer ndn.Signer) (enc.Name

if !args.NoMetadata {
// write metadata packet
name := args.Name.Prefix(-1).Append(
enc.NewKeywordComponent(rdr.MetadataKeyword),
enc.NewVersionComponent(version),
enc.NewSegmentComponent(0),
)
name := args.Name.Prefix(-1).
Append(enc.NewKeywordComponent(rdr.MetadataKeyword)).
Append(enc.NewVersionComponent(version)).
Append(enc.NewSegmentComponent(0))
content := rdr.MetaData{
Name: args.Name,
FinalBlockID: cfg.FinalBlockID.Bytes(),
Expand Down
7 changes: 3 additions & 4 deletions std/security/name_convention.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ func MakeKeyName(name enc.Name) enc.Name {
keyId := make([]byte, 8)
rand.Read(keyId)

return name.Append(
enc.NewGenericComponent("KEY"),
enc.NewGenericBytesComponent(keyId),
)
return name.
Append(enc.NewGenericComponent("KEY")).
Append(enc.NewGenericBytesComponent(keyId))
}

// GetIdentityFromKeyName extracts the identity name from a key name.
Expand Down
8 changes: 4 additions & 4 deletions std/security/ndncert/client_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
func (c *Client) FetchProfile() (*tlv.CaProfile, error) {
// TODO: validate packets received by the client using the cert.
ch := make(chan ndn.ConsumeState)
c.client.Consume(c.caPrefix.Append(
enc.NewGenericComponent("CA"),
enc.NewGenericComponent("INFO"),
), func(status ndn.ConsumeState) {
name := c.caPrefix.
Append(enc.NewGenericComponent("CA")).
Append(enc.NewGenericComponent("INFO"))
c.client.Consume(name, func(status ndn.ConsumeState) {
if status.IsComplete() {
ch <- status
}
Expand Down
10 changes: 5 additions & 5 deletions tools/dvc/dvc_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func (t *Tool) RunDvLinkCreate(cmd *cobra.Command, args []string) {
}

// /localhop/<network>/32=DV/32=ADS/32=ACT
name := enc.LOCALHOP.Append(status.NetworkName.Name.Append(
enc.NewKeywordComponent("DV"),
enc.NewKeywordComponent("ADS"),
enc.NewKeywordComponent("ACT"),
)...)
name := enc.LOCALHOP.
Append(status.NetworkName.Name...).
Append(enc.NewKeywordComponent("DV")).
Append(enc.NewKeywordComponent("ADS")).
Append(enc.NewKeywordComponent("ACT"))

new(nfdc.Tool).ExecCmd(cmd, "rib", "register", []string{
"persistency=permanent",
Expand Down

0 comments on commit dbb0b53

Please sign in to comment.