github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/neatptc/downloader/types.go (about) 1 package downloader 2 3 import ( 4 "fmt" 5 6 "github.com/neatlab/neatio/chain/core/types" 7 ) 8 9 type peerDropFn func(id string) 10 11 type dataPack interface { 12 PeerId() string 13 Items() int 14 Stats() string 15 } 16 17 type headerPack struct { 18 peerId string 19 headers []*types.Header 20 } 21 22 func (p *headerPack) PeerId() string { return p.peerId } 23 func (p *headerPack) Items() int { return len(p.headers) } 24 func (p *headerPack) Stats() string { return fmt.Sprintf("%d", len(p.headers)) } 25 26 type bodyPack struct { 27 peerId string 28 transactions [][]*types.Transaction 29 uncles [][]*types.Header 30 } 31 32 func (p *bodyPack) PeerId() string { return p.peerId } 33 func (p *bodyPack) Items() int { 34 if len(p.transactions) <= len(p.uncles) { 35 return len(p.transactions) 36 } 37 return len(p.uncles) 38 } 39 func (p *bodyPack) Stats() string { return fmt.Sprintf("%d:%d", len(p.transactions), len(p.uncles)) } 40 41 type receiptPack struct { 42 peerId string 43 receipts [][]*types.Receipt 44 } 45 46 func (p *receiptPack) PeerId() string { return p.peerId } 47 func (p *receiptPack) Items() int { return len(p.receipts) } 48 func (p *receiptPack) Stats() string { return fmt.Sprintf("%d", len(p.receipts)) } 49 50 type statePack struct { 51 peerId string 52 states [][]byte 53 } 54 55 func (p *statePack) PeerId() string { return p.peerId } 56 func (p *statePack) Items() int { return len(p.states) } 57 func (p *statePack) Stats() string { return fmt.Sprintf("%d", len(p.states)) }