Skip to content

Commit

Permalink
std: rename svs NodeId -> Name
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jan 7, 2025
1 parent 21c5d79 commit e8bf6fe
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 108 deletions.
18 changes: 9 additions & 9 deletions dv/dv/advert_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func (dv *Router) advertGenerateNew() {
go dv.advertSyncSendInterest()
}

func (dv *Router) advertDataFetch(nodeId enc.Name, seqNo uint64) {
func (dv *Router) advertDataFetch(nName enc.Name, seqNo uint64) {
// debounce; wait before fetching, then check if this is still the latest
// sequence number known for this neighbor
time.Sleep(10 * time.Millisecond)
if ns := dv.neighbors.Get(nodeId); ns == nil || ns.AdvertSeq != seqNo {
if ns := dv.neighbors.Get(nName); ns == nil || ns.AdvertSeq != seqNo {
return
}

// Fetch the advertisement
advName := enc.LOCALHOP.Append(nodeId.Append(
advName := enc.LOCALHOP.Append(nName.Append(
enc.NewStringComponent(enc.TypeKeywordNameComponent, "DV"),
enc.NewStringComponent(enc.TypeKeywordNameComponent, "ADV"),
enc.NewVersionComponent(seqNo),
Expand All @@ -59,32 +59,32 @@ func (dv *Router) advertDataFetch(nodeId enc.Name, seqNo uint64) {
if fetchErr != nil {
log.Warnf("advert-data: failed to fetch advertisement %s: %+v", state.Name(), fetchErr)
time.Sleep(1 * time.Second) // wait on error
dv.advertDataFetch(nodeId, seqNo)
dv.advertDataFetch(nName, seqNo)
return
}

// Process the advertisement
dv.advertDataHandler(nodeId, seqNo, state.Content())
dv.advertDataHandler(nName, seqNo, state.Content())
}()

return true
})
}

// Received advertisement Data
func (dv *Router) advertDataHandler(nodeId enc.Name, seqNo uint64, data []byte) {
func (dv *Router) advertDataHandler(nName enc.Name, seqNo uint64, data []byte) {
// Lock DV state
dv.mutex.Lock()
defer dv.mutex.Unlock()

// Check if this is the latest advertisement
ns := dv.neighbors.Get(nodeId)
ns := dv.neighbors.Get(nName)
if ns == nil {
log.Warnf("advert-handler: unknown advertisement %s", nodeId)
log.Warnf("advert-handler: unknown advertisement %s", nName)
return
}
if ns.AdvertSeq != seqNo {
log.Debugf("advert-handler: old advertisement for %s (%d != %d)", nodeId, ns.AdvertSeq, seqNo)
log.Debugf("advert-handler: old advertisement for %s (%d != %d)", nName, ns.AdvertSeq, seqNo)
return
}

Expand Down
18 changes: 9 additions & 9 deletions dv/dv/advert_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (dv *Router) advertSyncSendInterestImpl(prefix enc.Name) (err error) {
sv := &svs_2024.StateVectorAppParam{
StateVector: &svs_2024.StateVector{
Entries: []*svs_2024.StateVectorEntry{{
NodeId: dv.config.RouterName(),
SeqNo: dv.advertSyncSeq,
Name: dv.config.RouterName(),
SeqNo: dv.advertSyncSeq,
}},
},
}
Expand Down Expand Up @@ -102,15 +102,15 @@ func (dv *Router) advertSyncOnInterest(args ndn.InterestHandlerArgs, active bool

// There should only be one entry in the StateVector, but check all anyway
for _, entry := range params.StateVector.Entries {
// Parse name from NodeId
nodeId := entry.NodeId
if nodeId == nil {
log.Warnf("advertSyncOnInterest: failed to parse NodeId: %+v", err)
// Parse name from entry
nName := entry.Name
if nName == nil {
log.Warnf("advertSyncOnInterest: failed to parse neighbor name: %+v", err)
continue
}

// Check if the entry is newer than what we know
ns := dv.neighbors.Get(nodeId)
ns := dv.neighbors.Get(nName)
if ns != nil {
if ns.AdvertSeq >= entry.SeqNo {
// Nothing has changed, skip
Expand All @@ -121,13 +121,13 @@ func (dv *Router) advertSyncOnInterest(args ndn.InterestHandlerArgs, active bool
// Create new neighbor entry cause none found
// This is the ONLY place where neighbors are created
// In all other places, quit if not found
ns = dv.neighbors.Add(nodeId)
ns = dv.neighbors.Add(nName)
}

markRecvPing(ns)
ns.AdvertSeq = entry.SeqNo

go dv.advertDataFetch(nodeId, entry.SeqNo)
go dv.advertDataFetch(nName, entry.SeqNo)
}

// Update FIB if needed
Expand Down
14 changes: 7 additions & 7 deletions dv/dv/prefix_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@ func (dv *Router) prefixDataFetchAll() {
func (dv *Router) onPfxSyncUpdate(ssu ndn_sync.SvSyncUpdate) {
// Update the prefix table
dv.mutex.Lock()
dv.pfx.GetRouter(ssu.NodeId).Latest = ssu.High
dv.pfx.GetRouter(ssu.Name).Latest = ssu.High
dv.mutex.Unlock()

// Start a fetching thread (if needed)
dv.prefixDataFetch(ssu.NodeId)
dv.prefixDataFetch(ssu.Name)
}

// Fetch prefix data
func (dv *Router) prefixDataFetch(nodeId enc.Name) {
func (dv *Router) prefixDataFetch(nName enc.Name) {
dv.mutex.Lock()
defer dv.mutex.Unlock()

// Check if the RIB has this destination
if !dv.rib.Has(nodeId) {
if !dv.rib.Has(nName) {
return
}

// At any given time, there is only one thread fetching
// prefix data for a node. This thread recursively calls itself.
router := dv.pfx.GetRouter(nodeId)
router := dv.pfx.GetRouter(nName)
if router == nil || router.Fetching || router.Known >= router.Latest {
return
}
router.Fetching = true

// Fetch the prefix data object
log.Debugf("prefix-table: fetching object for %s [%d => %d]", nodeId, router.Known, router.Latest)
log.Debugf("prefix-table: fetching object for %s [%d => %d]", nName, router.Known, router.Latest)

name := router.GetNextDataName()
dv.client.Consume(name, func(state *object.ConsumeState) bool {
Expand All @@ -78,7 +78,7 @@ func (dv *Router) prefixDataFetch(nodeId enc.Name) {

// Done fetching, restart if needed
router.Fetching = false
go dv.prefixDataFetch(nodeId)
go dv.prefixDataFetch(nName)
}()

return true
Expand Down
6 changes: 3 additions & 3 deletions std/examples/low-level/svs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func main() {
logger := log.WithField("module", "main")

if len(os.Args) < 2 {
log.Fatalf("Usage: %s <nodeId>", os.Args[0])
log.Fatalf("Usage: %s <name>", os.Args[0])
}

// Parse command line arguments
nodeId, err := enc.NameFromStr(os.Args[1])
name, err := enc.NameFromStr(os.Args[1])
if err != nil {
log.Fatalf("Invalid node ID: %s", os.Args[1])
}
Expand Down Expand Up @@ -63,7 +63,7 @@ func main() {
ticker := time.NewTicker(3 * time.Second)

for range ticker.C {
new := svsync.IncrSeqNo(nodeId)
new := svsync.IncrSeqNo(name)
logger.Infof("Published new sequence number: %d", new)
}
}
10 changes: 5 additions & 5 deletions std/examples/schema-test/chat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const SchemaJson = `{
"ChannelSize": 1000,
"SyncInterval": 15000,
"SuppressionInterval": 100,
"SelfNodeId": "$nodeId",
"SelfName": "$nodeId",
"BaseMatching": {}
}
}
Expand Down Expand Up @@ -238,15 +238,15 @@ func main() {
select {
case missData := <-ch:
for i := missData.StartSeq; i < missData.EndSeq; i++ {
dataName := syncNode.Call("GetDataName", missData.NodeId, i).(enc.Name)
dataName := syncNode.Call("GetDataName", missData.Name, i).(enc.Name)
mLeafNode := tree.Match(dataName)
result := <-mLeafNode.Call("NeedChan").(chan schema.NeedResult)
if result.Status != ndn.InterestResultData {
fmt.Printf("Data fetching failed for (%s, %d): %+v\n", missData.NodeId.String(), i, result.Status)
fmt.Printf("Data fetching failed for (%s, %d): %+v\n", missData.Name, i, result.Status)
} else {
dataLock.Lock()
fmt.Printf("Fetched (%s, %d): %s\n", missData.NodeId.String(), i, string(result.Content.Join()))
msg := fmt.Sprintf("%s[%d]: %s", missData.NodeId.String(), i, string(result.Content.Join()))
fmt.Printf("Fetched (%s, %d): %s\n", missData.Name.String(), i, string(result.Content.Join()))
msg := fmt.Sprintf("%s[%d]: %s", missData.Name.String(), i, string(result.Content.Join()))
msgList = append(msgList, msg)
if wsConn != nil {
wsConn.WriteMessage(websocket.TextMessage, []byte(msg))
Expand Down
2 changes: 1 addition & 1 deletion std/examples/schema-test/chat/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ChannelSize": 1000,
"SyncInterval": 15000,
"SuppressionInterval": 100,
"SelfNodeId": "$nodeId",
"SelfName": "$nodeId",
"BaseMatching": {}
}
}
Expand Down
8 changes: 4 additions & 4 deletions std/examples/schema-test/sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const SchemaJson = `{
"ChannelSize": 1000,
"SyncInterval": 2000,
"SuppressionInterval": 100,
"SelfNodeId": "$nodeId",
"SelfName": "$nodeId",
"BaseMatching": {}
}
}
Expand Down Expand Up @@ -132,13 +132,13 @@ func main() {
select {
case missData := <-ch:
for i := missData.StartSeq; i < missData.EndSeq; i++ {
dataName := mNode.Call("GetDataName", missData.NodeId, i).(enc.Name)
dataName := mNode.Call("GetDataName", missData.Name, i).(enc.Name)
mLeafNode := tree.Match(dataName)
result := <-mLeafNode.Call("NeedChan").(chan schema.NeedResult)
if result.Status != ndn.InterestResultData {
fmt.Printf("Data fetching failed for (%s, %d): %+v\n", missData.NodeId.String(), i, result.Status)
fmt.Printf("Data fetching failed for (%s, %d): %+v\n", missData.Name.String(), i, result.Status)
} else {
fmt.Printf("Fetched (%s, %d): %s", missData.NodeId.String(), i, string(result.Content.Join()))
fmt.Printf("Fetched (%s, %d): %s", missData.Name.String(), i, string(result.Content.Join()))
}
}
case <-ctx.Done():
Expand Down
2 changes: 1 addition & 1 deletion std/examples/schema-test/sync/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ChannelSize": 1000,
"SyncInterval": 2000,
"SuppressionInterval": 100,
"SelfNodeId": "$nodeId",
"SelfName": "$nodeId",
"BaseMatching": {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion std/ndn/svs_2024/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type StateVector struct {

type StateVectorEntry struct {
//+field:name
NodeId enc.Name `tlv:"0x07"`
Name enc.Name `tlv:"0x07"`
//+field:natural
SeqNo uint64 `tlv:"0xcc"`
}
40 changes: 20 additions & 20 deletions std/ndn/svs_2024/zz_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e8bf6fe

Please sign in to comment.