domain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GITHUB_API_URL     = "https://api.github.com/"
	GITHUB_DEFAULT_URL = "https://github.com/"
)
View Source
const (
	STATUS_OK       = "200 OK"
	STATUS_CREATED  = "201 Created"
	STATUS_ACCEPTED = "202 Accepted"
)
View Source
const (
	FAIL    = "FAIL"
	SUCCESS = "SUCCESS"
)
View Source
const (
	Status_TRANSACTION_UNCONFIRMED TransactionStatus = 0
	Status_TRANSACTION_CONFIRMED   TransactionStatus = 1
	Status_TRANSACTION_UNKNOWN     TransactionStatus = 2

	Invoke TxDataType = "invoke"
	Query  TxDataType = "query"

	General TransactionType = 0 + iota

	Write  = "write"
	Read   = "read"
	Delete = "delete"
)

Variables

This section is empty.

Functions

func ChangeRemote

func ChangeRemote(repos_path string, dir string) error

func CloneRepos

func CloneRepos(repos_path string, dir string) error

func CloneReposWithName

func CloneReposWithName(repos_path string, dir string, dirName string) error

func CommitAll

func CommitAll(dir string, comment string) error

func CommitAndPush

func CommitAndPush(dir string, comment string) error

func MakeHashArg

func MakeHashArg(tx Transaction) []string

func MakeTar

func MakeTar(source string, target string) error

func PullAndCopyAndRunDocker

func PullAndCopyAndRunDocker(imageName string, tarPath string) *docker.Client

Temporary Function. It have to be splited for legibility and maintenance.

func PushRepos

func PushRepos(dir string) error

func ResetWithSHA

func ResetWithSHA(dir string, sha string) error

func ToConsensusProtoMessage

func ToConsensusProtoMessage(consensusMessage ConsensusMessage) *pb.ConsensusMessage

func ToElectionProtoMessage

func ToElectionProtoMessage(electionMessage ElectionMessage) *pb.ElectionMessage

func ToProtoBlock

func ToProtoBlock(block *Block) *pb.Block

todo test

func ToProtoPeer

func ToProtoPeer(pp Peer) *pb.Peer

func ToProtoPeerTable

func ToProtoPeerTable(pt PeerTable) *pb.PeerTable

func ToProtoTransaction

func ToProtoTransaction(t Transaction) *pb.Transaction

todo test

func ToProtoTxData

func ToProtoTxData(t TxData) *pb.TxData

todo test

func ToProtoView

func ToProtoView(view View) *pb.View

todo test

Types

type Block

type Block struct {
	Header           *BlockHeader
	MerkleTree       [][]string
	MerkleTreeHeight int
	TransactionCount int
	Transactions     []*Transaction
}

func BlockDeserialize

func BlockDeserialize(by []byte) (Block, error)

func CreateNewBlock

func CreateNewBlock(prevBlock *Block, createPeerId string) *Block

func FromProtoBlock

func FromProtoBlock(pb *pb.Block) *Block

todo test

func (Block) BlockSerialize

func (s Block) BlockSerialize() ([]byte, error)

func (Block) FindTransactionIndex

func (s Block) FindTransactionIndex(hash string) (idx int, err error)

func (*Block) GenerateBlockHash

func (s *Block) GenerateBlockHash() error

func (Block) MakeMerklePath

func (s Block) MakeMerklePath(idx int) (path []string)

func (*Block) MakeMerkleTree

func (s *Block) MakeMerkleTree()

func (*Block) PutTranscation

func (s *Block) PutTranscation(tx *Transaction) error

func (*Block) Reset

func (s *Block) Reset()

func (Block) VerifyBlock

func (s Block) VerifyBlock() (bool, error)

블럭내의 모든 트랜잭션들이 정당한지 머클패스로 검사함

func (Block) VerifyTx

func (s Block) VerifyTx(tx Transaction) (bool, error)

해당 트랜잭션이 정당한지 머클패스로 검사함

type BlockChain

type BlockChain struct {
	sync.RWMutex              //lock
	Header       *ChainHeader //chain meta information
	Blocks       []*Block     //list of bloc
}

func CreateNewBlockChain

func CreateNewBlockChain(channelID string, peerId string) *BlockChain

type BlockHeader

type BlockHeader struct {
	Number             uint64
	PreviousHash       string
	Version            string
	MerkleTreeRootHash string
	TimeStamp          time.Time
	BlockHeight        int
	BlockStatus        Block_Status
	CreatedPeerID      string
	Signature          []byte
	PeerId             string
	BlockHash          string
}

type Block_Status

type Block_Status int
const (
	Status_BLOCK_UNCONFIRMED Block_Status = 0
	Status_BLOCK_CONFIRMED   Block_Status = 1
)

type ChainHeader

type ChainHeader struct {
	ChainHeight int    //height of chain
	ChannelName string //channel name
	PeerID      string //owner peer id of chain
}

type ConsensusMessage

type ConsensusMessage struct {
	ConsensusID string
	View        View
	SequenceID  int64
	Block       *Block
	SenderID    string
	MsgType     MsgType
	TimeStamp   time.Time
}

consesnsus message can has 3 types

func FromConsensusProtoMessage

func FromConsensusProtoMessage(consensusMessage pb.ConsensusMessage) *ConsensusMessage

todo block을 넣어야함 todo test

func NewConsesnsusMessage

func NewConsesnsusMessage(consensusID string, view View, sequenceID int64, block *Block, peerID string, msgType MsgType) ConsensusMessage

tested

type ConsensusState

type ConsensusState struct {
	ID           string
	View         *View
	CurrentStage Stage
	Block        *Block
	PrepareMsgs  map[string]ConsensusMessage
	CommitMsgs   map[string]ConsensusMessage

	IsEnd int32

	sync.RWMutex
	// contains filtered or unexported fields
}

동시에 여러개의 consensus가 진행될 수 있다. 한개의 consensus는 1개의 state를 갖는다.

func NewConsensusState

func NewConsensusState(view *View, consensusID string, block *Block, currentStage Stage, endConsensusHandler EndConsensusHandle, periodSeconds int32) *ConsensusState

tested

func (*ConsensusState) AddMessage

func (cs *ConsensusState) AddMessage(consensusMessage ConsensusMessage)

message 종류에 따라서 다르게 넣어야함

func (*ConsensusState) CommitReady

func (cs *ConsensusState) CommitReady() bool

func (*ConsensusState) End

func (cs *ConsensusState) End()

func (*ConsensusState) PrepareReady

func (cs *ConsensusState) PrepareReady() bool

type ConsensusStateBuilder

type ConsensusStateBuilder interface {
	ConsensusID(string) ConsensusStateBuilder
	CurrentStage(Stage) ConsensusStateBuilder
	View(*View) ConsensusStateBuilder
	EndConsensusHandler(EndConsensusHandle) ConsensusStateBuilder
	Period(int32) ConsensusStateBuilder
	Block(*Block) ConsensusStateBuilder
	Build() *ConsensusState
}

func NewConsensusStateBuilder

func NewConsensusStateBuilder() ConsensusStateBuilder

type ElectionMessage

type ElectionMessage struct {
	LastBlockHash string
	SenderID      string
	MsgType       ElectionMsgType
	Term          int64
	PeerIDs       []string
}

func FromElectionProtoMessage

func FromElectionProtoMessage(electionMessage pb.ElectionMessage) *ElectionMessage

func NewElectionMessage

func NewElectionMessage(r *Raft) ElectionMessage

type ElectionMsgType

type ElectionMsgType int32
const (
	HeartBeatMsg ElectionMsgType = iota
	RequestVoteMsg
	VoteMsg
)

type EndConsensusHandle

type EndConsensusHandle func(*ConsensusState)

type FunctionType

type FunctionType string

type GithubRepoInfoResponse

type GithubRepoInfoResponse struct {
	Name     string `json:"name"`
	FullName string `json:"full_name"`
}

func GetRepositoryList

func GetRepositoryList(userName string) ([]GithubRepoInfoResponse, error)

type GithubRequestCreateRepos

type GithubRequestCreateRepos struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type GithubResponse

type GithubResponse struct {
	Message   string
	Id        int    `json:"id"`
	Name      string `json:"name"`
	Full_name string `json:"full_name"`
	Html_url  string `json:"html_url"`
	Owner     struct {
		Login string `json:"login"`
	} `json:"owner"`
	Source struct {
		Id        int    `json:"id"`
		Name      string `json:"name"`
		Full_name string `json:"full_name"`
		Html_url  string `json:"html_url"`
		Owner     struct {
			Login string `json:"login"`
		} `json:"owner"`
	} `json:"source"`
}

func CreateRepos

func CreateRepos(repos_name string, token string) (GithubResponse, error)

func ForkRepos

func ForkRepos(repos_path string, token string) (GithubResponse, error)

func GetRepos

func GetRepos(repos_path string) (GithubResponse, error)

type GithubResponseCommits

type GithubResponseCommits struct {
	Message string
	Sha     string `json:"sha"`
	Author  struct {
		Login string `json:"login"`
	} `json:"author"`
	Committer struct {
		Login string `json:"login"`
	} `json:"committer"`
}

func GetReposCommits

func GetReposCommits(repos_path string) ([]GithubResponseCommits, error)

type Identity

type Identity struct {
}

type MsgType

type MsgType int
const (
	PreprepareMsg MsgType = iota
	PrepareMsg
	CommitMsg
)

type Params

type Params struct {
	ParamsType int
	Function   string
	Args       []string
}

func SetTxMethodParameters

func SetTxMethodParameters(params_type int, function string, args []string) Params

type Peer

type Peer struct {
	IpAddress string
	Port      string
	PeerID    string
	HeartBeat int
	TimeStamp time.Time
	PubKey    []byte
}

func FromProtoPeer

func FromProtoPeer(pp pb.Peer) *Peer

func (*Peer) GetEndPoint

func (pi *Peer) GetEndPoint() string

func (Peer) String

func (pi Peer) String() string

func (*Peer) Update

func (pi *Peer) Update(Peer *Peer) error

func (*Peer) UpdateTimeStamp

func (pi *Peer) UpdateTimeStamp()

type PeerTable

type PeerTable struct {
	PeerMap   map[string]*Peer
	Leader    *Peer
	TimeStamp time.Time
	MyID      string
	sync.RWMutex
}

func FromProtoPeerTable

func FromProtoPeerTable(pt pb.PeerTable) *PeerTable

func NewPeerTable

func NewPeerTable(myInfo *Peer) (*PeerTable, error)

func (*PeerTable) AddPeer

func (pt *PeerTable) AddPeer(Peer *Peer)

tested if does not exist insert if exist update all

func (*PeerTable) FindPeerByPeerID

func (pt *PeerTable) FindPeerByPeerID(peerID string) *Peer

tested

func (*PeerTable) GetAllPeerList

func (pt *PeerTable) GetAllPeerList() []*Peer

func (*PeerTable) GetMyInfo

func (pt *PeerTable) GetMyInfo() Peer

tested

func (*PeerTable) GetPeerList

func (pt *PeerTable) GetPeerList() []*Peer

tested 나자신을 제외한 Peer의 list를 return

func (*PeerTable) IncrementHeartBeat

func (pt *PeerTable) IncrementHeartBeat() error

//tested

func (*PeerTable) SelectRandomPeers

func (pt *PeerTable) SelectRandomPeers(percent float64) ([]Peer, error)

//tested

func (PeerTable) String

func (pt PeerTable) String() string

func (*PeerTable) UpdatePeerTable

func (pt *PeerTable) UpdatePeerTable(peerTable PeerTable)

tested

func (*PeerTable) UpdateTimeStamp

func (pt *PeerTable) UpdateTimeStamp()

tested

type Raft

type Raft struct {
	ElectionTimer  time.Timer
	HeartbeatTimer time.Timer

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRaft

func NewRaft(nodeId string) *Raft

func (*Raft) AppendPeerId

func (r *Raft) AppendPeerId(peerId string)

func (*Raft) CountTerm

func (r *Raft) CountTerm()

func (*Raft) CountVote

func (r *Raft) CountVote()

func (*Raft) GetLastBlockHash

func (r *Raft) GetLastBlockHash() string

func (*Raft) GetLeaderId

func (r *Raft) GetLeaderId() string

func (*Raft) GetNodeId

func (r *Raft) GetNodeId() string

func (*Raft) GetPeerId

func (r *Raft) GetPeerId() []string

func (*Raft) GetState

func (r *Raft) GetState() RaftState

func (*Raft) GetTerm

func (r *Raft) GetTerm() int64

func (*Raft) GetVoteCount

func (r *Raft) GetVoteCount() int

func (*Raft) GetVotedFor

func (r *Raft) GetVotedFor() string

func (*Raft) ResetElectionTimer

func (r *Raft) ResetElectionTimer()

func (*Raft) ResetVote

func (r *Raft) ResetVote()

func (*Raft) SetHeartbeatTimer

func (r *Raft) SetHeartbeatTimer(t time.Duration)

func (*Raft) SetLastBlockHash

func (r *Raft) SetLastBlockHash(hash string)

func (*Raft) SetLeaderId

func (r *Raft) SetLeaderId(leaderId string)

func (*Raft) SetPeerId

func (r *Raft) SetPeerId(peerids []string)

func (*Raft) SetState

func (r *Raft) SetState(state RaftState)

func (*Raft) SetTerm

func (r *Raft) SetTerm(term int64)

func (*Raft) StopElectionTimer

func (r *Raft) StopElectionTimer()

func (*Raft) StopHeartbeatTimer

func (r *Raft) StopHeartbeatTimer()

func (*Raft) VoteValidate

func (r *Raft) VoteValidate(candidateRaft *Raft) (bool, error)

func (*Raft) VotesForItself

func (r *Raft) VotesForItself()

func (*Raft) Voting

func (r *Raft) Voting(peerId string)

type RaftState

type RaftState int32
const (
	Follower RaftState = iota
	Candidate
	Leader
	ShutDown
)

type SmartContractResponse

type SmartContractResponse struct {
	Result string            `json:"result"`
	Method string            `json:"method"` // query, invoke
	Data   map[string]string `json:"data"`
	Error  string            `json:"error"` // It's set when the result is fail
}

type Stage

type Stage int
const (
	Idle        Stage = iota
	PrePrepared       // The ReqMsgs is processed successfully. The node is ready to head to the Prepare stage.
	Prepared          // Same with `prepared` stage explained in the original paper.
	Committed         // Same with `committed-local` stage explained in the original paper.
)

type Transaction

type Transaction struct {
	InvokePeerID      string
	TransactionID     string
	TransactionStatus TransactionStatus
	TransactionType   TransactionType
	TransactionHash   string
	TimeStamp         time.Time
	TxData            *TxData
}

func CreateNewTransaction

func CreateNewTransaction(peer_id string, tx_id string, tx_type TransactionType, t time.Time, data *TxData) *Transaction

func FromProtoTransaction

func FromProtoTransaction(t pb.Transaction) *Transaction

todo test

func (*Transaction) GenerateHash

func (tx *Transaction) GenerateHash()

func (Transaction) GenerateTransactionHash

func (tx Transaction) GenerateTransactionHash() string

func (*Transaction) GetTxHash

func (tx *Transaction) GetTxHash() string

func (Transaction) Validate

func (tx Transaction) Validate() bool

type TransactionStatus

type TransactionStatus int

type TransactionType

type TransactionType int

type TxData

type TxData struct {
	Jsonrpc    string
	Method     TxDataType
	Params     Params
	ContractID string
}

func FromProtoTxData

func FromProtoTxData(ptxData pb.TxData) *TxData

todo test

func SetTxData

func SetTxData(jsonrpc string, method TxDataType, params Params, contract_id string) *TxData

type TxDataType

type TxDataType string

type View

type View struct {
	ID       string
	LeaderID string
	PeerID   []string
}

현재 Consensus에 참여하는 leader와 peer정보

func FromProtoView

func FromProtoView(protoView *pb.View) View

todo test

Jump to

Keyboard shortcuts

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