Help us shape the future of Go! Take the 2026 Go Developer Survey

node

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const TradeTimeout int64 = 30

TradeTimeout of the transaction phase (in seconds)

Variables

View Source
var TradeMsgChan tradeMsgChan

TradeMsgChan 交易信息通道

Functions

This section is empty.

Types

type JoinData

type JoinData struct {
	KeyType cmCrypto.KeyType
	PubKey  []byte // user public key
	Seed    string // user p2p net seed
}

JoinData join channel data

type JoinResp

type JoinResp struct {
	Success bool
	Reason  string // user p2p net seed
}

JoinResp join channel resp

type Leader

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

Leader off chain epoch leader

type Node

type Node struct {
	Id             string // node id
	ChannelName    string // channel net name
	NodeName       string // node name TODO: 有没有用,待最终确认
	NetAddr        string // node network address
	Balance        int    // node balance
	Joined         bool   // node joined channel
	Exited         bool   // node exited channel
	JoinFailReason string // node exited channel

	Once sync.Once // once send trade phase notify

	NodeLibp2pNet *libp2pnet.LibP2pNet //node network

	sync.RWMutex
	// contains filtered or unexported fields
}

Node off chain node

func CreateNode

func CreateNode(channelName string) (node *Node, err error)

CreateNode create channel node

func (*Node) CheckTxId

func (node *Node) CheckTxId(txId string) (exist bool)

CheckTxId check tx id

func (*Node) CreateChannel

func (node *Node) CreateChannel(balance int) (err error)

CreateChannel create channel

func (*Node) JoinChannel

func (node *Node) JoinChannel(balance int) (isLeader bool, err error)

JoinChannel join channel

func (*Node) LeaderID

func (node *Node) LeaderID() (leaderID string)

LeaderID get LeaderID

func (*Node) Phase

func (node *Node) Phase() (phase Phase)

Phase get phase

func (*Node) PrintStatus

func (node *Node) PrintStatus()

PrintStatus print node status

func (*Node) SendExitRequest

func (node *Node) SendExitRequest() (err error)

SendExitRequest send exit request

func (*Node) SendJoinRequest

func (node *Node) SendJoinRequest()

SendJoinRequest send join request

func (*Node) SendPing

func (node *Node) SendPing(receiverId string) (err error)

SendPing send heart beat ping

func (*Node) SendTradePhaseNotify

func (node *Node) SendTradePhaseNotify()

SendTradePhaseNotify Notifies all nodes to enter the transaction phase (leader)

func (*Node) SendTxRequest

func (node *Node) SendTxRequest(amount int, receiverId string) (txId string, err error)

SendTxRequest the transaction is constructed, signed and sent to the receiver (sender)

func (*Node) SetPhase

func (node *Node) SetPhase(phase Phase)

SetPhase set phase

type NodeEntity

type NodeEntity struct {
	PubKey *crypto.PubKeyEntity
	Seed   string
}

NodeEntity node entity

type Phase

type Phase int

Phase phase

const (
	// InitPhase init phase, no operation can be performed
	InitPhase Phase = iota
	// TradePhase Trades can be made at this stage
	TradePhase
	// ConsensusPhase The trading phase timeout triggers entering the consensus phase
	ConsensusPhase
	// ArbitrationPhase Unable to reach a consensus, all nodes enter the challenge phase
	ArbitrationPhase
	// ExitPhase exit phase
	ExitPhase
)

type State

type State struct {
	Epoch       int
	LeaderId    string
	BalanceSet  map[string]int
	WithdrawSet map[string]int // node exit set
	SigSet      map[string][]byte
}

State state

type TradeMsg

type TradeMsg struct {
	Code int
	TxId string
	Msg  string
}

TradeMsg 交易信息

type Tx

type Tx struct {
	Id          string // tx id
	Epoch       int    // epoch of tx
	Sender      string // sender id
	Receiver    string // receiver id
	Amount      int    // tx amount
	LeaderSig   []byte // leader sig
	SenderSig   []byte // sender sig
	ReceiverSig []byte // receiver sig

	StartTime time.Time     // tx start time
	Duration  time.Duration // tx duration time
}

Tx transaction struct

Source Files

  • handler.go
  • node.go
  • send.go
  • types.go

Jump to

Keyboard shortcuts

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