Unverified Commit 95cb1a00 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #447 from ipfs/fix/panic-and-leak

fix: set the score ledger on start
parents b4720fab ed0f4edf
...@@ -178,6 +178,10 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger, ...@@ -178,6 +178,10 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger,
func newEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger, self peer.ID, func newEngine(ctx context.Context, bs bstore.Blockstore, peerTagger PeerTagger, self peer.ID,
maxReplaceSize int, scoreLedger ScoreLedger) *Engine { maxReplaceSize int, scoreLedger ScoreLedger) *Engine {
if scoreLedger == nil {
scoreLedger = NewDefaultScoreLedger()
}
e := &Engine{ e := &Engine{
ledgerMap: make(map[peer.ID]*ledger), ledgerMap: make(map[peer.ID]*ledger),
scoreLedger: scoreLedger, scoreLedger: scoreLedger,
...@@ -221,9 +225,6 @@ func (e *Engine) UseScoreLedger(scoreLedger ScoreLedger) { ...@@ -221,9 +225,6 @@ func (e *Engine) UseScoreLedger(scoreLedger ScoreLedger) {
// if it is unset, initializes the scoreLedger with the default // if it is unset, initializes the scoreLedger with the default
// implementation. // implementation.
func (e *Engine) startScoreLedger(px process.Process) { func (e *Engine) startScoreLedger(px process.Process) {
if e.scoreLedger == nil {
e.scoreLedger = NewDefaultScoreLedger()
}
e.scoreLedger.Start(func(p peer.ID, score int) { e.scoreLedger.Start(func(p peer.ID, score int) {
if score == 0 { if score == 0 {
e.peerTagger.UntagPeer(p, e.tagUseful) e.peerTagger.UntagPeer(p, e.tagUseful)
......
...@@ -102,8 +102,6 @@ func (l *scoreledger) Receipt() *Receipt { ...@@ -102,8 +102,6 @@ func (l *scoreledger) Receipt() *Receipt {
// DefaultScoreLedger is used by Engine as the default ScoreLedger. // DefaultScoreLedger is used by Engine as the default ScoreLedger.
type DefaultScoreLedger struct { type DefaultScoreLedger struct {
// a sample counting ticker
ticker *time.Ticker
// the score func // the score func
scorePeer ScorePeerFunc scorePeer ScorePeerFunc
// is closed on Close // is closed on Close
...@@ -333,7 +331,6 @@ func (dsl *DefaultScoreLedger) PeerDisconnected(p peer.ID) { ...@@ -333,7 +331,6 @@ func (dsl *DefaultScoreLedger) PeerDisconnected(p peer.ID) {
func NewDefaultScoreLedger() *DefaultScoreLedger { func NewDefaultScoreLedger() *DefaultScoreLedger {
return &DefaultScoreLedger{ return &DefaultScoreLedger{
ledgerMap: make(map[peer.ID]*scoreledger), ledgerMap: make(map[peer.ID]*scoreledger),
ticker: time.NewTicker(time.Millisecond * 100),
closing: make(chan struct{}), closing: make(chan struct{}),
peerSampleInterval: shortTerm, peerSampleInterval: shortTerm,
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment