From e9b0339b22139d99aa342846298315d3ee4d2955 Mon Sep 17 00:00:00 2001 From: ianshih22856 <114518748+ianshih22856@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:39:31 -0800 Subject: [PATCH 1/2] Update concurrentMap.go Included functionality for checking map updates. --- concurrentMap.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/concurrentMap.go b/concurrentMap.go index cab667a..5827e88 100644 --- a/concurrentMap.go +++ b/concurrentMap.go @@ -39,6 +39,7 @@ type pState []*pStateShared type pStateShared struct { items map[string]*packet_state sync.RWMutex // Read Write mutex, guards access to internal map. + updated bool } // Creates a new concurrent map. @@ -61,6 +62,7 @@ func (m pState) Insert(key string, p * packet_state) { shard.Lock() shard.items[key] = p + shard.updated = true shard.Unlock() } @@ -112,9 +114,33 @@ func (m pState) Remove(key string) { shard := m.GetShard(key) shard.Lock() delete(shard.items, key) + shard.updated = true shard.Unlock() } +// HasUpdates checks if map has been updated +func (m pState) HasUpdates() bool { + for i := 0; i < SHARD_COUNT; i++ { + shard := m[i] + shard.RLock() + if shard.updated { + shard.RUnlock() + return true + } + shard.RUnlock() + } + return false +} + +// ResetUpdates resets all updates to false +func (m pState) ResetUpdates() { + for i := 0; i < SHARD_COUNT; i++ { + shard := m[i] + shard.Lock() + shard.updated = false + shard.Unlock() + } +} /* FOR PACKET_METADATA */ //is Processing for goPackets From 93f033dfcbf67d7afdfb7539a51083aba6785e3e Mon Sep 17 00:00:00 2001 From: ianshih22856 <114518748+ianshih22856@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:44:38 -0800 Subject: [PATCH 2/2] Update bin.go Included functionality for checking and resetting updates to check if LZR is in an infinite loop. --- bin/bin.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/bin.go b/bin/bin.go index fb3aa16..7719a99 100644 --- a/bin/bin.go +++ b/bin/bin.go @@ -81,7 +81,15 @@ func LZRMain() { var intervalLoop = options.Timeout*lzr.NumHandshakes()*2 go func() { for { - time.Sleep(time.Duration(intervalLoop)*time.Second) + startTime := time.Now() + for time.Since(startTime) < time.Duration(intervalLoop)*time.Second { + if (ipMeta.HasUpdates()) { + startTime = time.Now() + ipMeta.ResetUpdates() + continue + } + time.Sleep(time.Duration(intervalLoop)*time.Millisecond) + } if (ipMetaSize == ipMeta.Count()) { fmt.Fprintln(os.Stderr,"Infinite Loop, Breaking.") infiniteLoop = true