Documentation ¶
Index ¶
- Constants
- Variables
- type BalaceMessage
- type BalanceInfoDb
- type ChunkDeliverInfo
- type ChunkDeliverItem
- type DBStore
- type Hash
- type Receipt
- type ReceiptBody
- type ReceiptData
- type ReceiptInStore
- type ReceiptItem
- type ReceiptItems
- type ReceiptStore
- func (rs *ReceiptStore) Account() [20]byte
- func (rs *ReceiptStore) CalcReceipts() error
- func (rs *ReceiptStore) CheckBalance(nodeId [20]byte) int64
- func (rs *ReceiptStore) GetReceiptsLogs() []Receipts
- func (rs *ReceiptStore) GetReceiptsToReport() (Receipts, int)
- func (rs *ReceiptStore) Init()
- func (rs *ReceiptStore) OnChunkDelivered(nodeId [20]byte, amount4k uint32) uint32
- func (rs *ReceiptStore) OnNewReceipt(id enode.ID, receipt *Receipt) error
- func (rs *ReceiptStore) OnNodeChunkReceived(account [20]byte, dataLength int64) (*Receipt, error)
- func (rs *ReceiptStore) SendDataToServer(url string, timeout time.Duration, result []byte) error
- func (rs *ReceiptStore) SetNewWather(watcher ReceiptWatcher)
- func (rs *ReceiptStore) Start()
- func (rs *ReceiptStore) Stop()
- type ReceiptWatcher
- type Receipts
- type ReceiptsOfNode
- type ReceiptsOfReport
- type Store
Constants ¶
View Source
const ( MAX_C_REC_LIMIT = 4096 //当超过这个数目时,最长时间不用的C_记录,就是找了最久没有连接的节点 ReportRoute = "/receipts" AccountRoute = "/account" )
View Source
const InvalidBalance = 0xFFFFFFFFFFFFFFF
Variables ¶
View Source
var ( ErrInvalidNode = errors.New("InvalidNodeId") ErrUnexpectedReceipt = errors.New("UnexpectedReceipt") ErrInvalidSignature = errors.New("InvalidSignature") ErrInvalidSTime = errors.New("InvalidSignTime") )
View Source
var ( CPREF = []byte("IN_CHUNK") HPREF = []byte("IN_RECEIPT") RPREF = []byte("UNREPORTED") SDATE = []byte("SDATE") SFORMAT = "2010-01-01 03:11:15" BALNACE_PREFIX = "BL" MAX_STIME_DURATION = 60 * time.Minute //生成收据时,一个STIME允许的最长时间 MAX_STIME_JITTER = 2 * MAX_STIME_DURATION //接收收据时,允许最长的时间差,超过这个时间的不再接收 MAX_ITEM_PER_REPORT = 2000 )
View Source
var ErrNotFound = errors.New("ErrorNotFound")
ErrNotFound is returned when no results are returned from the database
Functions ¶
This section is empty.
Types ¶
type BalaceMessage ¶
type BalanceInfoDb ¶
type ChunkDeliverInfo ¶
type ChunkDeliverInfo map[enode.ID]*ChunkDeliverItem
type ChunkDeliverItem ¶
type DBStore ¶
type DBStore struct {
// contains filtered or unexported fields
}
DBStore uses LevelDB to store values.
func NewDBStore ¶
NewDBStore creates a new instance of DBStore.
func NewInmemoryStore ¶
func NewInmemoryStore() *DBStore
NewInmemoryStore returns a new instance of DBStore. To be used only in tests and simulations.
type ReceiptBody ¶
收据的数据
type ReceiptData ¶
收据的数据
type ReceiptInStore ¶
type ReceiptItem ¶
type ReceiptItems ¶
type ReceiptItems map[time.Time]ReceiptItem
func (*ReceiptItems) Amount ¶
func (rs *ReceiptItems) Amount() (amount uint32)
type ReceiptStore ¶
type ReceiptStore struct {
// contains filtered or unexported fields
}
func NewReceiptsStore ¶
func NewReceiptsStore(filePath string, prvKey *ecdsa.PrivateKey, serverAddrs []string, duration time.Duration, checkBalance bool, lightNode bool) (*ReceiptStore, error)
func (*ReceiptStore) Account ¶
func (rs *ReceiptStore) Account() [20]byte
func (*ReceiptStore) CalcReceipts ¶
func (rs *ReceiptStore) CalcReceipts() error
func (*ReceiptStore) CheckBalance ¶
func (rs *ReceiptStore) CheckBalance(nodeId [20]byte) int64
检查余额,以10^-12次方为单位
func (*ReceiptStore) GetReceiptsLogs ¶
func (rs *ReceiptStore) GetReceiptsLogs() []Receipts
func (*ReceiptStore) GetReceiptsToReport ¶
func (rs *ReceiptStore) GetReceiptsToReport() (Receipts, int)
func (*ReceiptStore) Init ¶
func (rs *ReceiptStore) Init()
func (*ReceiptStore) OnChunkDelivered ¶
func (rs *ReceiptStore) OnChunkDelivered(nodeId [20]byte, amount4k uint32) uint32
*
每次数据传输完成后,用这个通知ReceiptStore,用于计数某些节点发送的总Chunk和收到的收据 本函数返回一个unpayed的值,用于表示该节点目前有多少个未支付(收据)的数据了 调用者可以根据这个返回决定对相应节点的操作 TODO 根据unpaidAmount的设计黑名单
func (*ReceiptStore) OnNewReceipt ¶
func (rs *ReceiptStore) OnNewReceipt(id enode.ID, receipt *Receipt) error
服务端新到了一个收据
func (*ReceiptStore) OnNodeChunkReceived ¶
func (rs *ReceiptStore) OnNodeChunkReceived(account [20]byte, dataLength int64) (*Receipt, error)
新收到了一个数据,在C记录中记录,并且返回一个签过名的收据 如果nodeId不合法,返回的收据为空,error为ErrInvalidNode
func (*ReceiptStore) SendDataToServer ¶
func (*ReceiptStore) SetNewWather ¶
func (rs *ReceiptStore) SetNewWather(watcher ReceiptWatcher)
func (*ReceiptStore) Start ¶
func (rs *ReceiptStore) Start()
func (*ReceiptStore) Stop ¶
func (rs *ReceiptStore) Stop()
type ReceiptWatcher ¶
type Receipts ¶
type Receipts map[[20]byte]ReceiptItems
func (*Receipts) CurrentReceipt ¶
func (rs *Receipts) CurrentReceipt(account [20]byte) *ReceiptData
type ReceiptsOfNode ¶
type ReceiptsOfNode struct { NodeId [20]byte Receipts []*ReceiptData }
某个来源节点的收据集
type ReceiptsOfReport ¶
Click to show internal directories.
Click to hide internal directories.