Skip to content

Commit 6a1f7d0

Browse files
author
Miga Labs
authored
Merge pull request #34 from migalabs/feature/limit-array-sizes
Feature/limit array sizes
2 parents 70958c1 + 8f37d93 commit 6a1f7d0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/db/peer.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
"github.com/sirupsen/logrus"
1717
)
1818

19+
var (
20+
MaxArraySize int = 10
21+
)
22+
1923
// Stores all the information related to a peer
2024
type Peer struct {
2125

@@ -202,13 +206,23 @@ func (pm *Peer) FetchConnectionsFromNewPeer(newPeer Peer) {
202206

203207
pm.ConnectionEvent(newConnectedDirection, time)
204208
}
209+
210+
if len(pm.ConnectedDirection) > MaxArraySize {
211+
tmpConnDirection := pm.ConnectedDirection[len(pm.ConnectedDirection)-MaxArraySize-1 : len(pm.ConnectedDirection)-1]
212+
pm.ConnectedDirection = tmpConnDirection
213+
}
214+
205215
for _, time := range newPeer.DisconnectionTimes {
206216
pm.DisconnectionEvent(time)
207217
}
208218

209219
for _, errorTmp := range newPeer.Error {
210220
pm.Error = append(pm.Error, errorTmp)
211221
}
222+
if len(pm.Error) > MaxArraySize {
223+
tmpError := pm.Error[len(pm.Error)-MaxArraySize-1 : len(pm.Error)-1]
224+
pm.Error = tmpError
225+
}
212226

213227
if newPeer.LastErrorTimestamp.After(pm.LastErrorTimestamp) {
214228
pm.LastErrorTimestamp = newPeer.LastErrorTimestamp

src/peering/pruning_strategy.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,11 @@ func (c *PrunedPeer) NextConnection() time.Time {
614614
if c.DelayObj.GetType() == Minus1DelayType { // in case of Minus1, this is new peer and we want it to connect as soon as possible
615615
return time.Time{}
616616
}
617+
618+
if c.DelayObj.CalculateDelay() > MaxDelayTime {
619+
return c.BaseConnectionTimestamp.Add(MaxDelayTime)
620+
}
621+
617622
// nextConnection should be from first event + the applied delay
618623
return c.BaseConnectionTimestamp.Add(c.DelayObj.CalculateDelay())
619624
}
@@ -657,10 +662,7 @@ func (c *PrunedPeer) UpdateDelay(newDelayType string) {
657662
c.BaseDeprecationTimestamp = time.Now()
658663
}
659664

660-
// only add degree in case we have not exceeded the MaxDelay allowed
661-
if c.DelayObj.CalculateDelay() < MaxDelayTime {
662-
c.DelayObj.AddDegree()
663-
}
665+
c.DelayObj.AddDegree()
664666
}
665667

666668
// ErrorToDelayType:

0 commit comments

Comments
 (0)