github.com/annchain/OG@v0.0.9/og/downloader/types.go (about) 1 package downloader 2 3 import ( 4 "fmt" 5 "github.com/annchain/OG/og/protocol/dagmessage" 6 "github.com/annchain/OG/og/types" 7 ) 8 9 // peerDropFn is a callback type for dropping a peer detected as malicious. 10 type peerDropFn func(id string) 11 12 type insertTxsFn func(seq *types.Sequencer, txs types.Txis) error 13 14 // dataPack is a data message returned by a peer for some query. 15 type dataPack interface { 16 PeerId() string 17 Items() int 18 Stats() string 19 } 20 21 // headerPack is a batch of block headers returned by a peer. 22 type headerPack struct { 23 peerID string 24 headers []*dagmessage.SequencerHeader 25 } 26 27 func (p *headerPack) PeerId() string { return p.peerID } 28 func (p *headerPack) Items() int { return len(p.headers) } 29 func (p *headerPack) Stats() string { return fmt.Sprintf("%d", len(p.headers)) } 30 31 // bodyPack is a batch of block bodies returned by a peer. 32 //sequencer[i] includes txs transactions[i] 33 type bodyPack struct { 34 peerID string 35 transactions []types.Txis 36 //sequencer *tx_types.Sequencer 37 sequencers []*types.Sequencer 38 } 39 40 /* 41 func (p *bodyPack) Sequencer() *tx_types.Sequencer { 42 return p.sequencer 43 } 44 */ 45 46 func (p *bodyPack) Sequencers() []*types.Sequencer { 47 return p.sequencers 48 } 49 50 func (p *bodyPack) PeerId() string { return p.peerID } 51 func (p *bodyPack) Items() int { 52 return len(p.transactions) 53 } 54 func (p *bodyPack) Stats() string { return fmt.Sprintf("%d", len(p.transactions)) } 55 56 // statePack is a batch of states returned by a peer. 57 type statePack struct { 58 peerID string 59 states [][]byte 60 } 61 62 func (p *statePack) PeerId() string { return p.peerID } 63 func (p *statePack) Items() int { return len(p.states) } 64 func (p *statePack) Stats() string { return fmt.Sprintf("%d", len(p.states)) }