mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-25 02:55:26 +00:00
better cleanup of maps
This commit is contained in:
parent
8d6beebac4
commit
4e156bd4f7
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export GOPATH=$PWD
|
export GOPATH=$PWD
|
||||||
go get -d yggdrasil
|
go get -d yggdrasil
|
||||||
go run -tags debug misc/sim/treesim.go
|
go run -tags debug misc/sim/treesim.go "$@"
|
||||||
|
@ -8,6 +8,7 @@ import "strconv"
|
|||||||
import "time"
|
import "time"
|
||||||
import "log"
|
import "log"
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
import "runtime/pprof"
|
import "runtime/pprof"
|
||||||
import "flag"
|
import "flag"
|
||||||
|
|
||||||
@ -280,17 +281,7 @@ func pingNodes(store map[[32]byte]*Node) {
|
|||||||
}
|
}
|
||||||
destAddr := dest.core.DEBUG_getAddr()[:]
|
destAddr := dest.core.DEBUG_getAddr()[:]
|
||||||
ticker := time.NewTicker(150 * time.Millisecond)
|
ticker := time.NewTicker(150 * time.Millisecond)
|
||||||
ch := make(chan bool, 1)
|
sendTo(payload, destAddr)
|
||||||
ch <- true
|
|
||||||
doTicker := func() {
|
|
||||||
for range ticker.C {
|
|
||||||
select {
|
|
||||||
case ch <- true:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
go doTicker()
|
|
||||||
for loop := true; loop; {
|
for loop := true; loop; {
|
||||||
select {
|
select {
|
||||||
case packet := <-dest.recv:
|
case packet := <-dest.recv:
|
||||||
@ -299,7 +290,7 @@ func pingNodes(store map[[32]byte]*Node) {
|
|||||||
loop = false
|
loop = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case <-ch:
|
case <-ticker.C:
|
||||||
sendTo(payload, destAddr)
|
sendTo(payload, destAddr)
|
||||||
//dumpDHTSize(store) // note that this uses racey functions to read things...
|
//dumpDHTSize(store) // note that this uses racey functions to read things...
|
||||||
}
|
}
|
||||||
@ -458,4 +449,5 @@ func main() {
|
|||||||
var block chan struct{}
|
var block chan struct{}
|
||||||
<-block
|
<-block
|
||||||
}
|
}
|
||||||
|
runtime.GC()
|
||||||
}
|
}
|
||||||
|
@ -273,19 +273,23 @@ func (t *dht) ping(info *dhtInfo, target *NodeID) {
|
|||||||
// Periodic maintenance work to keep important DHT nodes alive.
|
// Periodic maintenance work to keep important DHT nodes alive.
|
||||||
func (t *dht) doMaintenance() {
|
func (t *dht) doMaintenance() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
newReqs := make(map[boxPubKey]map[NodeID]time.Time, len(t.reqs))
|
||||||
for key, dests := range t.reqs {
|
for key, dests := range t.reqs {
|
||||||
|
newDests := make(map[NodeID]time.Time, len(dests))
|
||||||
for nodeID, start := range dests {
|
for nodeID, start := range dests {
|
||||||
if now.Sub(start) > 6*time.Second {
|
if now.Sub(start) > 6*time.Second {
|
||||||
if info, isIn := t.table[*getNodeID(&key)]; isIn {
|
if info, isIn := t.table[*getNodeID(&key)]; isIn {
|
||||||
info.pings++
|
info.pings++
|
||||||
}
|
}
|
||||||
delete(dests, nodeID)
|
continue
|
||||||
}
|
|
||||||
if len(dests) == 0 {
|
|
||||||
delete(t.reqs, key)
|
|
||||||
}
|
}
|
||||||
|
newDests[nodeID] = start
|
||||||
|
}
|
||||||
|
if len(newDests) > 0 {
|
||||||
|
newReqs[key] = newDests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
t.reqs = newReqs
|
||||||
for infoID, info := range t.table {
|
for infoID, info := range t.table {
|
||||||
if now.Sub(info.recv) > time.Minute || info.pings > 3 {
|
if now.Sub(info.recv) > time.Minute || info.pings > 3 {
|
||||||
delete(t.table, infoID)
|
delete(t.table, infoID)
|
||||||
|
@ -175,7 +175,6 @@ func (p *peer) doSendSwitchMsgs() {
|
|||||||
// This must be launched in a separate goroutine by whatever sets up the peer struct.
|
// This must be launched in a separate goroutine by whatever sets up the peer struct.
|
||||||
// It handles link protocol traffic.
|
// It handles link protocol traffic.
|
||||||
func (p *peer) linkLoop() {
|
func (p *peer) linkLoop() {
|
||||||
go p.doSendSwitchMsgs()
|
|
||||||
tick := time.NewTicker(time.Second)
|
tick := time.NewTicker(time.Second)
|
||||||
defer tick.Stop()
|
defer tick.Stop()
|
||||||
for {
|
for {
|
||||||
|
@ -311,6 +311,11 @@ func (ss *sessions) createSession(theirPermKey *boxPubKey) *sessionInfo {
|
|||||||
|
|
||||||
func (ss *sessions) cleanup() {
|
func (ss *sessions) cleanup() {
|
||||||
// Time thresholds almost certainly could use some adjusting
|
// Time thresholds almost certainly could use some adjusting
|
||||||
|
for k := range ss.permShared {
|
||||||
|
// Delete a key, to make sure this eventually shrinks to 0
|
||||||
|
delete(ss.permShared, k)
|
||||||
|
break
|
||||||
|
}
|
||||||
if time.Since(ss.lastCleanup) < time.Minute {
|
if time.Since(ss.lastCleanup) < time.Minute {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -319,6 +324,36 @@ func (ss *sessions) cleanup() {
|
|||||||
s.close()
|
s.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
permShared := make(map[boxPubKey]*boxSharedKey, len(ss.permShared))
|
||||||
|
for k, v := range ss.permShared {
|
||||||
|
permShared[k] = v
|
||||||
|
}
|
||||||
|
ss.permShared = permShared
|
||||||
|
sinfos := make(map[handle]*sessionInfo, len(ss.sinfos))
|
||||||
|
for k, v := range ss.sinfos {
|
||||||
|
sinfos[k] = v
|
||||||
|
}
|
||||||
|
ss.sinfos = sinfos
|
||||||
|
byMySes := make(map[boxPubKey]*handle, len(ss.byMySes))
|
||||||
|
for k, v := range ss.byMySes {
|
||||||
|
byMySes[k] = v
|
||||||
|
}
|
||||||
|
ss.byMySes = byMySes
|
||||||
|
byTheirPerm := make(map[boxPubKey]*handle, len(ss.byTheirPerm))
|
||||||
|
for k, v := range ss.byTheirPerm {
|
||||||
|
byTheirPerm[k] = v
|
||||||
|
}
|
||||||
|
ss.byTheirPerm = byTheirPerm
|
||||||
|
addrToPerm := make(map[address]*boxPubKey, len(ss.addrToPerm))
|
||||||
|
for k, v := range ss.addrToPerm {
|
||||||
|
addrToPerm[k] = v
|
||||||
|
}
|
||||||
|
ss.addrToPerm = addrToPerm
|
||||||
|
subnetToPerm := make(map[subnet]*boxPubKey, len(ss.subnetToPerm))
|
||||||
|
for k, v := range ss.subnetToPerm {
|
||||||
|
subnetToPerm[k] = v
|
||||||
|
}
|
||||||
|
ss.subnetToPerm = subnetToPerm
|
||||||
ss.lastCleanup = time.Now()
|
ss.lastCleanup = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,5 +86,10 @@ func (m *sigManager) cleanup() {
|
|||||||
delete(m.checked, s)
|
delete(m.checked, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newChecked := make(map[sigBytes]knownSig, len(m.checked))
|
||||||
|
for s, k := range m.checked {
|
||||||
|
newChecked[s] = k
|
||||||
|
}
|
||||||
|
m.checked = newChecked
|
||||||
m.lastCleaned = time.Now()
|
m.lastCleaned = time.Now()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user