Skip to content

Commit

Permalink
Merge branch 'main' into svsa
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Feb 6, 2025
2 parents 4514685 + 8ac1029 commit e005807
Show file tree
Hide file tree
Showing 157 changed files with 6,146 additions and 2,712 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Benchmark
on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: write
deployments: write
pull-requests: write

jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: stable

- name: Run benchmark
run: go test ./... -benchmem -bench ^Benchmark -benchtime=300000x | tee bench.log

- name: Check benchmark result
if: github.event_name == 'pull_request'
uses: benchmark-action/github-action-benchmark@v1
with:
name: Go Benchmark
tool: go
github-token: ${{ secrets.GITHUB_TOKEN }}
output-file-path: bench.log
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
summary-always: true
alert-comment-cc-users: '@pulsejet'

- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
if: github.event_name != 'pull_request'
with:
name: Go Benchmark
tool: go
output-file-path: bench.log
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
fail-on-alert: true
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04,
macos-13, macos-14,
windows-2022]
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false
steps:
- name: Checkout repository
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: lint
on:
push:
branches: ["main"]
pull_request:

jobs:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
[![build](https://github.com/named-data/ndnd/actions/workflows/build.yml/badge.svg)](https://github.com/named-data/ndnd/actions/workflows/build.yml)
[![test](https://github.com/named-data/ndnd/actions/workflows/test.yml/badge.svg)](https://github.com/named-data/ndnd/actions/workflows/test.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/named-data/ndnd)](https://goreportcard.com/report/github.com/named-data/ndnd)
[![Benchmark](https://img.shields.io/badge/benchmark-graph-8A2BE2?logo=github)](https://named-data.github.io/ndnd/dev/bench/index.html)

[![release](https://img.shields.io/github/v/release/named-data/ndnd)](https://github.com/named-data/ndnd/releases)
[![MIT license](https://img.shields.io/badge/license-MIT-blue)](./LICENSE.md)
[![Go Reference](https://pkg.go.dev/badge/github.com/named-data/ndnd.svg)](https://pkg.go.dev/github.com/named-data/ndnd)
Expand Down
2 changes: 1 addition & 1 deletion dv/dv/advert_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (a *advertModule) dataHandler(nName enc.Name, seqNo uint64, data enc.Wire)
}

// Parse the advertisement
advert, err := tlv.ParseAdvertisement(enc.NewWireReader(data), false)
advert, err := tlv.ParseAdvertisement(enc.NewWireView(data), false)
if err != nil {
log.Error(a, "Failed to parse advertisement", "err", err)
return
Expand Down
15 changes: 8 additions & 7 deletions dv/dv/advert_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
spec "github.com/named-data/ndnd/std/ndn/spec_2022"
spec_svs "github.com/named-data/ndnd/std/ndn/svs/v3"
"github.com/named-data/ndnd/std/object"
"github.com/named-data/ndnd/std/types/optional"
"github.com/named-data/ndnd/std/utils"
)

Expand Down Expand Up @@ -70,7 +71,7 @@ func (a *advertModule) sendSyncInterestImpl(prefix enc.Name) (err error) {

// Make Data packet
dataCfg := &ndn.DataConfig{
ContentType: utils.IdPtr(ndn.ContentTypeBlob),
ContentType: optional.Some(ndn.ContentTypeBlob),
}
data, err := a.dv.engine.Spec().MakeData(syncName, dataCfg, sv.Encode(), signer)
if err != nil {
Expand All @@ -80,9 +81,9 @@ func (a *advertModule) sendSyncInterestImpl(prefix enc.Name) (err error) {

// Make SVS Sync Interest
intCfg := &ndn.InterestConfig{
Lifetime: utils.IdPtr(1 * time.Second),
Lifetime: optional.Some(1 * time.Second),
Nonce: utils.ConvertNonce(a.dv.engine.Timer().Nonce()),
HopLimit: utils.IdPtr(uint(2)), // use localhop w/ this
HopLimit: utils.IdPtr(byte(2)), // use localhop w/ this
}
interest, err := a.dv.engine.Spec().MakeInterest(syncName, intCfg, data.Wire, nil)
if err != nil {
Expand All @@ -100,7 +101,7 @@ func (a *advertModule) sendSyncInterestImpl(prefix enc.Name) (err error) {

func (a *advertModule) OnSyncInterest(args ndn.InterestHandlerArgs, active bool) {
// If there is no incoming face ID, we can't use this
if args.IncomingFaceId == nil {
if !args.IncomingFaceId.IsSet() {
log.Warn(a, "Received Sync Interest with no incoming face ID, ignoring")
return
}
Expand All @@ -112,7 +113,7 @@ func (a *advertModule) OnSyncInterest(args ndn.InterestHandlerArgs, active bool)
}

// Decode Sync Data
data, sigCov, err := spec.Spec{}.ReadData(enc.NewWireReader(args.Interest.AppParam()))
data, sigCov, err := spec.Spec{}.ReadData(enc.NewWireView(args.Interest.AppParam()))
if err != nil {
log.Warn(a, "Failed to parse Sync Data", "err", err)
return
Expand All @@ -131,14 +132,14 @@ func (a *advertModule) OnSyncInterest(args ndn.InterestHandlerArgs, active bool)

// Decode state vector
svWire := data.Content()
params, err := spec_svs.ParseSvsData(enc.NewWireReader(svWire), false)
params, err := spec_svs.ParseSvsData(enc.NewWireView(svWire), false)
if err != nil || params.StateVector == nil {
log.Warn(a, "Failed to parse StateVec", "err", err)
return
}

// Process the state vector
go a.onStateVector(params.StateVector, *args.IncomingFaceId, active)
go a.onStateVector(params.StateVector, args.IncomingFaceId.Unwrap(), active)
},
})
}
Expand Down
19 changes: 10 additions & 9 deletions dv/dv/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/named-data/ndnd/std/ndn"
mgmt "github.com/named-data/ndnd/std/ndn/mgmt_2022"
sig "github.com/named-data/ndnd/std/security/signer"
"github.com/named-data/ndnd/std/types/optional"
"github.com/named-data/ndnd/std/utils"
)

Expand Down Expand Up @@ -48,8 +49,8 @@ func (dv *Router) mgmtOnStatus(args ndn.InterestHandlerArgs) {

name := args.Interest.Name()
cfg := &ndn.DataConfig{
ContentType: utils.IdPtr(ndn.ContentTypeBlob),
Freshness: utils.IdPtr(time.Second),
ContentType: optional.Some(ndn.ContentTypeBlob),
Freshness: optional.Some(time.Second),
}

data, err := dv.engine.Spec().MakeData(name, cfg, status.Encode(), nil)
Expand All @@ -76,8 +77,8 @@ func (dv *Router) mgmtOnRib(args ndn.InterestHandlerArgs) {
data, err := dv.engine.Spec().MakeData(
args.Interest.Name(),
&ndn.DataConfig{
ContentType: utils.IdPtr(ndn.ContentTypeBlob),
Freshness: utils.IdPtr(1 * time.Second),
ContentType: optional.Some(ndn.ContentTypeBlob),
Freshness: optional.Some(1 * time.Second),
},
res.Encode(),
signer)
Expand All @@ -102,7 +103,7 @@ func (dv *Router) mgmtOnRib(args ndn.InterestHandlerArgs) {
return
}

params, err := mgmt.ParseControlParameters(enc.NewBufferReader(advC.Val), false)
params, err := mgmt.ParseControlParameters(enc.NewBufferView(advC.Val), false)
if err != nil || params.Val == nil || params.Val.Name == nil {
log.Warn(dv, "Failed to parse readvertised name", "err", err)
return
Expand All @@ -126,9 +127,9 @@ func (dv *Router) mgmtOnRib(args ndn.InterestHandlerArgs) {
res.Val.StatusText = "Readvertise command successful"
res.Val.Params = &mgmt.ControlArgs{
Name: params.Val.Name,
FaceId: utils.IdPtr(uint64(1)), // NFD compatibility
Origin: utils.IdPtr(uint64(65)),
Cost: utils.IdPtr(uint64(0)),
Flags: utils.IdPtr(uint64(0)),
FaceId: optional.Some(uint64(1)), // NFD compatibility
Origin: optional.Some(uint64(65)),
Cost: optional.Some(uint64(0)),
Flags: optional.Some(uint64(0)),
}
}
29 changes: 15 additions & 14 deletions dv/dv/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/named-data/ndnd/std/security/keychain"
"github.com/named-data/ndnd/std/security/trust_schema"
ndn_sync "github.com/named-data/ndnd/std/sync"
"github.com/named-data/ndnd/std/types/optional"
"github.com/named-data/ndnd/std/utils"
)

Expand Down Expand Up @@ -223,8 +224,8 @@ func (dv *Router) configureFace() (err error) {
Module: "faces",
Cmd: "update",
Args: &mgmt.ControlArgs{
Mask: utils.IdPtr(mgmt.FaceFlagLocalFieldsEnabled),
Flags: utils.IdPtr(mgmt.FaceFlagLocalFieldsEnabled),
Mask: optional.Some(mgmt.FaceFlagLocalFieldsEnabled),
Flags: optional.Some(mgmt.FaceFlagLocalFieldsEnabled),
},
Retries: -1,
})
Expand Down Expand Up @@ -275,8 +276,8 @@ func (dv *Router) register() (err error) {
Cmd: "register",
Args: &mgmt.ControlArgs{
Name: prefix,
Cost: utils.IdPtr(uint64(0)),
Origin: utils.IdPtr(config.NlsrOrigin),
Cost: optional.Some(uint64(0)),
Origin: optional.Some(config.NlsrOrigin),
},
Retries: -1,
})
Expand Down Expand Up @@ -307,14 +308,14 @@ func (dv *Router) register() (err error) {
// createFaces creates faces to all neighbors.
func (dv *Router) createFaces() {
for i, neighbor := range dv.config.Neighbors {
var mtu *uint64 = nil
var mtu optional.Optional[uint64]
if neighbor.Mtu > 0 {
mtu = utils.IdPtr(neighbor.Mtu)
mtu = optional.Some(neighbor.Mtu)
}

faceId, created, err := dv.nfdc.CreateFace(&mgmt.ControlArgs{
Uri: utils.IdPtr(neighbor.Uri),
FacePersistency: utils.IdPtr(uint64(mgmt.PersistencyPermanent)),
Uri: optional.Some(neighbor.Uri),
FacePersistency: optional.Some(uint64(mgmt.PersistencyPermanent)),
Mtu: mtu,
})
if err != nil {
Expand All @@ -333,9 +334,9 @@ func (dv *Router) createFaces() {
Cmd: "register",
Args: &mgmt.ControlArgs{
Name: dv.config.AdvertisementSyncActivePrefix(),
Cost: utils.IdPtr(uint64(1)),
Origin: utils.IdPtr(config.NlsrOrigin),
FaceId: utils.IdPtr(faceId),
Cost: optional.Some(uint64(1)),
Origin: optional.Some(config.NlsrOrigin),
FaceId: optional.Some(faceId),
},
Retries: 3,
})
Expand All @@ -351,14 +352,14 @@ func (dv *Router) destroyFaces() {

dv.engine.ExecMgmtCmd("rib", "unregister", &mgmt.ControlArgs{
Name: dv.config.AdvertisementSyncActivePrefix(),
Origin: utils.IdPtr(config.NlsrOrigin),
FaceId: utils.IdPtr(neighbor.FaceId),
Origin: optional.Some(config.NlsrOrigin),
FaceId: optional.Some(neighbor.FaceId),
})

// only destroy faces that we created
if neighbor.Created {
dv.engine.ExecMgmtCmd("faces", "destroy", &mgmt.ControlArgs{
FaceId: utils.IdPtr(neighbor.FaceId),
FaceId: optional.Some(neighbor.FaceId),
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions dv/nfdc/nfdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func (m *NfdMgmtThread) CreateFace(args *mgmt.ControlArgs) (uint64, bool, error)
// don't check error here, as the face may already exist (409)

res, ok := raw.(*mgmt.ControlResponse)
if !ok || res == nil || res.Val == nil || res.Val.Params == nil || res.Val.Params.FaceId == nil {
if !ok || res == nil || res.Val == nil || res.Val.Params == nil || !res.Val.Params.FaceId.IsSet() {
return 0, false, fmt.Errorf("failed to create face: %+v", err)
}

faceId := *res.Val.Params.FaceId
faceId := res.Val.Params.FaceId.Unwrap()
created := res.Val.StatusCode == 200

return faceId, created, nil
Expand Down
12 changes: 6 additions & 6 deletions dv/table/fib.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/named-data/ndnd/dv/nfdc"
enc "github.com/named-data/ndnd/std/encoding"
mgmt "github.com/named-data/ndnd/std/ndn/mgmt_2022"
"github.com/named-data/ndnd/std/utils"
"github.com/named-data/ndnd/std/types/optional"
)

type FibEntry struct {
Expand Down Expand Up @@ -116,8 +116,8 @@ func (fib *Fib) UpdateH(nameH uint64, name enc.Name, newEntries []FibEntry) bool
Cmd: "unregister",
Args: &mgmt.ControlArgs{
Name: name,
FaceId: utils.IdPtr(oldEntry.FaceId),
Origin: utils.IdPtr(config.NlsrOrigin),
FaceId: optional.Some(oldEntry.FaceId),
Origin: optional.Some(config.NlsrOrigin),
},
Retries: 3,
})
Expand All @@ -138,9 +138,9 @@ func (fib *Fib) UpdateH(nameH uint64, name enc.Name, newEntries []FibEntry) bool
Cmd: "register",
Args: &mgmt.ControlArgs{
Name: name,
FaceId: utils.IdPtr(entry.FaceId),
Cost: utils.IdPtr(entry.Cost),
Origin: utils.IdPtr(config.NlsrOrigin),
FaceId: optional.Some(entry.FaceId),
Cost: optional.Some(entry.Cost),
Origin: optional.Some(config.NlsrOrigin),
},
Retries: 3,
})
Expand Down
12 changes: 6 additions & 6 deletions dv/table/neighbor_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
enc "github.com/named-data/ndnd/std/encoding"
"github.com/named-data/ndnd/std/log"
mgmt "github.com/named-data/ndnd/std/ndn/mgmt_2022"
"github.com/named-data/ndnd/std/utils"
"github.com/named-data/ndnd/std/types/optional"
)

type NeighborTable struct {
Expand Down Expand Up @@ -158,9 +158,9 @@ func (ns *NeighborState) routeRegister(faceId uint64) {
Cmd: "register",
Args: &mgmt.ControlArgs{
Name: route,
FaceId: utils.IdPtr(faceId),
Origin: utils.IdPtr(config.NlsrOrigin),
Cost: utils.IdPtr(uint64(0)),
FaceId: optional.Some(faceId),
Origin: optional.Some(config.NlsrOrigin),
Cost: optional.Some(uint64(0)),
},
Retries: 3,
})
Expand Down Expand Up @@ -188,8 +188,8 @@ func (ns *NeighborState) routeUnregister() {
Cmd: "unregister",
Args: &mgmt.ControlArgs{
Name: route,
FaceId: utils.IdPtr(ns.faceId),
Origin: utils.IdPtr(config.NlsrOrigin),
FaceId: optional.Some(ns.faceId),
Origin: optional.Some(config.NlsrOrigin),
},
Retries: 1,
})
Expand Down
2 changes: 1 addition & 1 deletion dv/table/prefix_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (pt *PrefixTable) Withdraw(name enc.Name) {

// Applies ops from a list. Returns if dirty.
func (pt *PrefixTable) Apply(wire enc.Wire) (dirty bool) {
ops, err := tlv.ParsePrefixOpList(enc.NewWireReader(wire), true)
ops, err := tlv.ParsePrefixOpList(enc.NewWireView(wire), true)
if err != nil {
log.Warn(pt, "Failed to parse PrefixOpList", "err", err)
return false
Expand Down
Loading

0 comments on commit e005807

Please sign in to comment.