提交 b36670df 作者: Brian Tiger Chow

refac(bitswap) privatize ledger

temporarily. at least until refactor is complete
上级 e4bceca2
......@@ -48,7 +48,7 @@ type bitswap struct {
// The Ledger has the peer.ID, and the peer connection works through net.
// Ledgers of known relationships (active or inactive) stored in datastore.
// Changes to the Ledger should be committed to the datastore.
partners LedgerMap
partners ledgerMap
// haveList is the set of keys we have values for. a map for fast lookups.
// haveList KeySet -- not needed. all values in datastore?
......@@ -68,7 +68,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
bs := &bitswap{
peer: p,
blockstore: blockstore.NewBlockstore(d),
partners: LedgerMap{},
partners: ledgerMap{},
wantList: KeySet{},
routing: r,
sender: bsnet.NewNetworkAdapter(s, &receiver),
......@@ -196,13 +196,13 @@ func (bs *bitswap) blockReceive(p *peer.Peer, blk blocks.Block) {
ledger.ReceivedBytes(len(blk.Data))
}
func (bs *bitswap) getLedger(p *peer.Peer) *Ledger {
func (bs *bitswap) getLedger(p *peer.Peer) *ledger {
l, ok := bs.partners[p.Key()]
if ok {
return l
}
l = new(Ledger)
l = new(ledger)
l.Strategy = bs.strategy
l.Partner = p
bs.partners[p.Key()] = l
......
......@@ -8,8 +8,8 @@ import (
u "github.com/jbenet/go-ipfs/util"
)
// Ledger stores the data exchange relationship between two peers.
type Ledger struct {
// ledger stores the data exchange relationship between two peers.
type ledger struct {
lock sync.RWMutex
// Partner is the remote Peer.
......@@ -34,16 +34,16 @@ type Ledger struct {
}
// LedgerMap lists Ledgers by their Partner key.
type LedgerMap map[u.Key]*Ledger
type ledgerMap map[u.Key]*ledger
func (l *Ledger) ShouldSend() bool {
func (l *ledger) ShouldSend() bool {
l.lock.Lock()
defer l.lock.Unlock()
return l.Strategy(l)
}
func (l *Ledger) SentBytes(n int) {
func (l *ledger) SentBytes(n int) {
l.lock.Lock()
defer l.lock.Unlock()
......@@ -52,7 +52,7 @@ func (l *Ledger) SentBytes(n int) {
l.Accounting.BytesSent += uint64(n)
}
func (l *Ledger) ReceivedBytes(n int) {
func (l *ledger) ReceivedBytes(n int) {
l.lock.Lock()
defer l.lock.Unlock()
......@@ -62,14 +62,14 @@ func (l *Ledger) ReceivedBytes(n int) {
}
// TODO: this needs to be different. We need timeouts.
func (l *Ledger) Wants(k u.Key) {
func (l *ledger) Wants(k u.Key) {
l.lock.Lock()
defer l.lock.Unlock()
l.wantList[k] = struct{}{}
}
func (l *Ledger) WantListContains(k u.Key) bool {
func (l *ledger) WantListContains(k u.Key) bool {
l.lock.RLock()
defer l.lock.RUnlock()
......@@ -77,7 +77,7 @@ func (l *Ledger) WantListContains(k u.Key) bool {
return ok
}
func (l *Ledger) ExchangeCount() uint64 {
func (l *ledger) ExchangeCount() uint64 {
l.lock.RLock()
defer l.lock.RUnlock()
return l.exchangeCount
......
......@@ -7,7 +7,7 @@ import (
func TestRaceConditions(t *testing.T) {
const numberOfExpectedExchanges = 10000
l := new(Ledger)
l := new(ledger)
var wg sync.WaitGroup
for i := 0; i < numberOfExpectedExchanges; i++ {
wg.Add(1)
......
......@@ -5,13 +5,13 @@ import (
"math/rand"
)
type strategyFunc func(*Ledger) bool
type strategyFunc func(*ledger) bool
func standardStrategy(l *Ledger) bool {
func standardStrategy(l *ledger) bool {
return rand.Float64() <= probabilitySend(l.Accounting.Value())
}
func yesManStrategy(l *Ledger) bool {
func yesManStrategy(l *ledger) bool {
return true
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论