github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/eth/downloader/types.go (about)

     1  // Copyright 2015 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package downloader
    18  
    19  import (
    20  	"fmt"
    21  	"github.com/PlatONnetwork/PlatON-Go/common"
    22  	"github.com/PlatONnetwork/PlatON-Go/core/types"
    23  )
    24  
    25  // peerDropFn is a callback type for dropping a peer detected as malicious.
    26  type peerDropFn func(id string)
    27  
    28  // dataPack is a data message returned by a peer for some query.
    29  type dataPack interface {
    30  	PeerId() string
    31  	Items() int
    32  	Stats() string
    33  }
    34  
    35  // headerPack is a batch of block headers returned by a peer.
    36  type headerPack struct {
    37  	peerID  string
    38  	headers []*types.Header
    39  }
    40  
    41  func (p *headerPack) PeerId() string { return p.peerID }
    42  func (p *headerPack) Items() int     { return len(p.headers) }
    43  func (p *headerPack) Stats() string  { return fmt.Sprintf("%d", len(p.headers)) }
    44  
    45  // bodyPack is a batch of block bodies returned by a peer.
    46  type bodyPack struct {
    47  	peerID       string
    48  	transactions [][]*types.Transaction
    49  	uncles       [][]*types.Header
    50  	signatures 	 [][]*common.BlockConfirmSign
    51  }
    52  
    53  func (p *bodyPack) PeerId() string { return p.peerID }
    54  func (p *bodyPack) Items() int {
    55  	if len(p.transactions) <= len(p.uncles) {
    56  		return len(p.transactions)
    57  	}
    58  	return len(p.uncles)
    59  }
    60  func (p *bodyPack) Stats() string { return fmt.Sprintf("%d:%d", len(p.transactions), len(p.uncles)) }
    61  
    62  // receiptPack is a batch of receipts returned by a peer.
    63  type receiptPack struct {
    64  	peerID   string
    65  	receipts [][]*types.Receipt
    66  }
    67  
    68  func (p *receiptPack) PeerId() string { return p.peerID }
    69  func (p *receiptPack) Items() int     { return len(p.receipts) }
    70  func (p *receiptPack) Stats() string  { return fmt.Sprintf("%d", len(p.receipts)) }
    71  
    72  // statePack is a batch of states returned by a peer.
    73  type statePack struct {
    74  	peerID string
    75  	states [][]byte
    76  }
    77  
    78  func (p *statePack) PeerId() string { return p.peerID }
    79  func (p *statePack) Items() int     { return len(p.states) }
    80  func (p *statePack) Stats() string  { return fmt.Sprintf("%d", len(p.states)) }
    81  
    82  
    83  // pposStoragePack is a batch of ppos storage returned by a peer.
    84  type pposStoragePack struct {
    85  	peerID 	string
    86  	latest  *types.Header
    87  	pivot	*types.Header
    88  	storage	[]byte
    89  }
    90  
    91  func (p *pposStoragePack) PeerId() string { return p.peerID }
    92  func (p *pposStoragePack) Items() int     { return 1 }
    93  func (p *pposStoragePack) Stats() string  { return fmt.Sprintf("%d", 1) }