state

package
v0.0.0-...-2e66602 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2021 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

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 BalaceMessage struct {
	Balance  string `json:"balance"`
	VBalance string `json:"vBalance"`
}

type BalanceInfoDb

type BalanceInfoDb struct {
	Second  int64
	Balance int64
}

type ChunkDeliverInfo

type ChunkDeliverInfo map[enode.ID]*ChunkDeliverItem

type ChunkDeliverItem

type ChunkDeliverItem struct {
	FromTime  time.Time //从某个时间点开始
	FromCount uint32    //从某个数值开始
	Delivered uint32    //已经发送的数据包
	// contains filtered or unexported fields
}

type DBStore

type DBStore struct {
	// contains filtered or unexported fields
}

DBStore uses LevelDB to store values.

func NewDBStore

func NewDBStore(path string) (s *DBStore, err error)

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.

func (*DBStore) Close

func (s *DBStore) Close() error

Close releases the resources used by the underlying LevelDB.

func (*DBStore) Delete

func (s *DBStore) Delete(key string) (err error)

Delete removes entries stored under a specific key.

func (*DBStore) Get

func (s *DBStore) Get(key string, i interface{}) (err error)

Get retrieves a persisted value for a specific key. If there is no results ErrNotFound is returned. The provided parameter should be either a byte slice or a struct that implements the encoding.BinaryUnmarshaler interface

func (*DBStore) Put

func (s *DBStore) Put(key string, i interface{}) (err error)

Put stores an object that implements Binary for a specific key.

type Hash

type Hash [32]byte

type Receipt

type Receipt struct {
	ReceiptBody
	Sign []byte
}

某个单个的收据

func (*Receipt) Signature

func (r *Receipt) Signature(prvKey *ecdsa.PrivateKey) error

* 签名

func (*Receipt) Verify

func (r *Receipt) Verify() (*ecdsa.PublicKey, bool)

* 验证签名是否正确,并且返回签名者的公钥

type ReceiptBody

type ReceiptBody struct {
	Account [20]byte //数据提供者
	Stime   time.Time
	Amount  uint32
}

收据的数据

func (*ReceiptBody) DecodeRLP

func (rs *ReceiptBody) DecodeRLP(s *rlp.Stream) error

func (ReceiptBody) EncodeRLP

func (r ReceiptBody) EncodeRLP(w io.Writer) error

type ReceiptData

type ReceiptData struct {
	Stime     time.Time
	Amount    uint32
	Signature []byte
}

收据的数据

func (*ReceiptData) DecodeRLP

func (rs *ReceiptData) DecodeRLP(s *rlp.Stream) error

func (ReceiptData) EncodeRLP

func (r ReceiptData) EncodeRLP(w io.Writer) error

type ReceiptInStore

type ReceiptInStore struct {
	Stime  time.Time
	Amount uint32
}

type ReceiptItem

type ReceiptItem struct {
	Amount uint32
	Sign   []byte
}

type ReceiptItems

type ReceiptItems map[time.Time]ReceiptItem

func (*ReceiptItems) Amount

func (rs *ReceiptItems) Amount() (amount uint32)

func (*ReceiptItems) DecodeRLP

func (rs *ReceiptItems) DecodeRLP(s *rlp.Stream) error

func (*ReceiptItems) EncodeRLP

func (rs *ReceiptItems) EncodeRLP(w io.Writer) error

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 (rs *ReceiptStore) SendDataToServer(url string, timeout time.Duration, result []byte) error

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 ReceiptWatcher interface {
	//收到了receipts
	OnNewReceipts(address common.Address, id enode.ID, length int)
	ID() string
}

type Receipts

type Receipts map[[20]byte]ReceiptItems

func (Receipts) Amount

func (rs Receipts) Amount() (amount uint32)

*

  • 测试用,计算总的收据的数量

func (*Receipts) CurrentReceipt

func (rs *Receipts) CurrentReceipt(account [20]byte) *ReceiptData

func (*Receipts) DecodeRLP

func (rs *Receipts) DecodeRLP(s *rlp.Stream) error

func (Receipts) EncodeRLP

func (rs Receipts) EncodeRLP(w io.Writer) error

type ReceiptsOfNode

type ReceiptsOfNode struct {
	NodeId   [20]byte
	Receipts []*ReceiptData
}

某个来源节点的收据集

type ReceiptsOfReport

type ReceiptsOfReport struct {
	Version  byte
	Account  [20]byte
	Receipts []rlpRD
}

type Store

type Store interface {
	Get(key string, i interface{}) (err error)
	Put(key string, i interface{}) (err error)
	Delete(key string) (err error)
	Close() error
}

Store defines methods required to get, set, delete values for different keys and close the underlying resources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL