Documentation
¶
Index ¶
- Constants
- func ChangeRemote(repos_path string, dir string) error
- func CloneRepos(repos_path string, dir string) error
- func CloneReposWithName(repos_path string, dir string, dirName string) error
- func CommitAll(dir string, comment string) error
- func CommitAndPush(dir string, comment string) error
- func MakeHashArg(tx Transaction) []string
- func MakeTar(source string, target string) error
- func PullAndCopyAndRunDocker(imageName string, tarPath string) *docker.Client
- func PushRepos(dir string) error
- func ResetWithSHA(dir string, sha string) error
- func ToConsensusProtoMessage(consensusMessage ConsensusMessage) *pb.ConsensusMessage
- func ToElectionProtoMessage(electionMessage ElectionMessage) *pb.ElectionMessage
- func ToProtoBlock(block *Block) *pb.Block
- func ToProtoPeer(pp Peer) *pb.Peer
- func ToProtoPeerTable(pt PeerTable) *pb.PeerTable
- func ToProtoTransaction(t Transaction) *pb.Transaction
- func ToProtoTxData(t TxData) *pb.TxData
- func ToProtoView(view View) *pb.View
- type Block
- func (s Block) BlockSerialize() ([]byte, error)
- func (s Block) FindTransactionIndex(hash string) (idx int, err error)
- func (s *Block) GenerateBlockHash() error
- func (s Block) MakeMerklePath(idx int) (path []string)
- func (s *Block) MakeMerkleTree()
- func (s *Block) PutTranscation(tx *Transaction) error
- func (s *Block) Reset()
- func (s Block) VerifyBlock() (bool, error)
- func (s Block) VerifyTx(tx Transaction) (bool, error)
- type BlockChain
- type BlockHeader
- type Block_Status
- type ChainHeader
- type ConsensusMessage
- type ConsensusState
- type ConsensusStateBuilder
- type ElectionMessage
- type ElectionMsgType
- type EndConsensusHandle
- type FunctionType
- type GithubRepoInfoResponse
- type GithubRequestCreateRepos
- type GithubResponse
- type GithubResponseCommits
- type Identity
- type MsgType
- type Params
- type Peer
- type PeerTable
- func (pt *PeerTable) AddPeer(Peer *Peer)
- func (pt *PeerTable) FindPeerByPeerID(peerID string) *Peer
- func (pt *PeerTable) GetAllPeerList() []*Peer
- func (pt *PeerTable) GetMyInfo() Peer
- func (pt *PeerTable) GetPeerList() []*Peer
- func (pt *PeerTable) IncrementHeartBeat() error
- func (pt *PeerTable) SelectRandomPeers(percent float64) ([]Peer, error)
- func (pt PeerTable) String() string
- func (pt *PeerTable) UpdatePeerTable(peerTable PeerTable)
- func (pt *PeerTable) UpdateTimeStamp()
- type Raft
- func (r *Raft) AppendPeerId(peerId string)
- func (r *Raft) CountTerm()
- func (r *Raft) CountVote()
- func (r *Raft) GetLastBlockHash() string
- func (r *Raft) GetLeaderId() string
- func (r *Raft) GetNodeId() string
- func (r *Raft) GetPeerId() []string
- func (r *Raft) GetState() RaftState
- func (r *Raft) GetTerm() int64
- func (r *Raft) GetVoteCount() int
- func (r *Raft) GetVotedFor() string
- func (r *Raft) ResetElectionTimer()
- func (r *Raft) ResetVote()
- func (r *Raft) SetHeartbeatTimer(t time.Duration)
- func (r *Raft) SetLastBlockHash(hash string)
- func (r *Raft) SetLeaderId(leaderId string)
- func (r *Raft) SetPeerId(peerids []string)
- func (r *Raft) SetState(state RaftState)
- func (r *Raft) SetTerm(term int64)
- func (r *Raft) StopElectionTimer()
- func (r *Raft) StopHeartbeatTimer()
- func (r *Raft) VoteValidate(candidateRaft *Raft) (bool, error)
- func (r *Raft) VotesForItself()
- func (r *Raft) Voting(peerId string)
- type RaftState
- type SmartContractResponse
- type Stage
- type Transaction
- type TransactionStatus
- type TransactionType
- type TxData
- type TxDataType
- type View
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 CloneRepos ¶
func CloneReposWithName ¶
func CommitAndPush ¶
func MakeHashArg ¶
func MakeHashArg(tx Transaction) []string
func PullAndCopyAndRunDocker ¶
Temporary Function. It have to be splited for legibility and maintenance.
func ResetWithSHA ¶
func ToConsensusProtoMessage ¶
func ToConsensusProtoMessage(consensusMessage ConsensusMessage) *pb.ConsensusMessage
func ToElectionProtoMessage ¶
func ToElectionProtoMessage(electionMessage ElectionMessage) *pb.ElectionMessage
func ToProtoPeer ¶
func ToProtoPeerTable ¶
Types ¶
type Block ¶
type Block struct {
Header *BlockHeader
MerkleTree [][]string
MerkleTreeHeight int
TransactionCount int
Transactions []*Transaction
}
func BlockDeserialize ¶
func CreateNewBlock ¶
func (Block) BlockSerialize ¶
func (Block) FindTransactionIndex ¶
func (*Block) GenerateBlockHash ¶
func (Block) MakeMerklePath ¶
func (*Block) MakeMerkleTree ¶
func (s *Block) MakeMerkleTree()
func (*Block) PutTranscation ¶
func (s *Block) PutTranscation(tx *Transaction) 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 Block_Status ¶
type Block_Status int
const ( Status_BLOCK_UNCONFIRMED Block_Status = 0 Status_BLOCK_CONFIRMED Block_Status = 1 )
type ChainHeader ¶
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 ¶
func GetRepositoryList ¶
func GetRepositoryList(userName string) ([]GithubRepoInfoResponse, error)
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 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 Peer ¶
type Peer struct {
IpAddress string
Port string
PeerID string
HeartBeat int
TimeStamp time.Time
PubKey []byte
}
func FromProtoPeer ¶
func (*Peer) GetEndPoint ¶
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 NewPeerTable ¶
func (*PeerTable) FindPeerByPeerID ¶
tested
func (*PeerTable) GetAllPeerList ¶
func (*PeerTable) GetPeerList ¶
tested 나자신을 제외한 Peer의 list를 return
func (*PeerTable) SelectRandomPeers ¶
//tested
func (*PeerTable) UpdatePeerTable ¶
tested
type Raft ¶
type Raft struct {
ElectionTimer time.Timer
HeartbeatTimer time.Timer
sync.RWMutex
// contains filtered or unexported fields
}
func (*Raft) AppendPeerId ¶
func (*Raft) GetLastBlockHash ¶
func (*Raft) GetLeaderId ¶
func (*Raft) GetVoteCount ¶
func (*Raft) GetVotedFor ¶
func (*Raft) ResetElectionTimer ¶
func (r *Raft) ResetElectionTimer()
func (*Raft) SetHeartbeatTimer ¶
func (*Raft) SetLastBlockHash ¶
func (*Raft) SetLeaderId ¶
func (*Raft) StopElectionTimer ¶
func (r *Raft) StopElectionTimer()
func (*Raft) StopHeartbeatTimer ¶
func (r *Raft) StopHeartbeatTimer()
func (*Raft) VotesForItself ¶
func (r *Raft) VotesForItself()
type SmartContractResponse ¶
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 (*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
}
type TxDataType ¶
type TxDataType string
Click to show internal directories.
Click to hide internal directories.