Documentation ¶
Index ¶
- Constants
- Variables
- func VerifyMsg(msg Message) (bool, error)
- type Auth
- type ContentBirth
- type ContentEvidence
- type Message
- type MsgReference
- type MsgValue
- type ParentSig
- type SpaceTime
- type Universe
- func (u *Universe) AddMsg(msg *Message) error
- func (u *Universe) AddSpaceTime(msg *Message, ref *MsgReference) error
- func (u Universe) CheckUserExist(userID common.Hash) bool
- func (u Universe) GetMaxSeq(spacetimeID common.Hash) uint64
- func (u Universe) GetMsgByID(msgID interface{}) *Message
- func (u *Universe) GetSpaceTimeIDs() []common.Hash
- func (u Universe) GetUserByID(userID common.Hash) *User
- func (u Universe) GetUserIDs(spacetimeID common.Hash) []common.Hash
- func (u Universe) GetUserInfo(userID common.Hash, spacetimeID common.Hash) *UserInfo
- type User
- func (u User) Distance(location common.Hash, dimension int, perimeter *big.Int) (distance *big.Int, err error)
- func (u User) Gender() bool
- func (u User) GetCoordinates(location common.Hash, dimension int, perimeter *big.Int) ([]*big.Int, error)
- func (u User) ID() common.Hash
- func (u *User) MarshalJSON() ([]byte, error)
- func (u User) ParentsID() [2]common.Hash
- func (u User) StandardDistance(location common.Hash) (distance *big.Int, err error)
- func (u *User) UnmarshalJSON(input []byte) error
- func (u User) Value() interface{}
- type UserInfo
Constants ¶
const ( // LeakedPrivateKey is the evidence can prove a private key has been leaked. // Usually contain 1 anonymous msg(TypeText), the content is private key // and 1 msg sign by this private key. LeakedPrivateKey = iota // ExcessiveBirth is the evidence can prove a user build msg try to create next // new user against the nature rule. ExcessiveBirth )
const ( // TypeText is the content without any functions, not just text TypeText = iota // TypeBirth is the type which contain the cosign to create new user in pdu TypeBirth // TypeEvidence is the type which contain the illegal evidence of user TypeEvidence )
const ( // DefaultDimensionNum is the default number of demension for calculating distance DefaultDimensionNum = 4 // DefaultPerimeter is the default perimeter of universe for calculating distance DefaultPerimeter = 1e+10 // MaxDimensionNum is the max number of demension MaxDimensionNum = 11 )
const ( // UserStatusNormal is the status of user, will be add more later, like punished... UserStatusNormal = iota )
Variables ¶
var ( // ErrUserNotExist returns fail to find a user ErrUserNotExist = errors.New("user not exist") // ErrMsgAlreadyExist returns try to add a message which already exist in universe ErrMsgAlreadyExist = errors.New("msg already exist") // ErrMsgNotFound returns fail to find a message ErrMsgNotFound = errors.New("msg not found") // ErrTPAlreadyExist returns time proof message already exist ErrTPAlreadyExist = errors.New("time proof already exist") // ErrUserAlreadyExist returns try a add a user who is already exist in unverse ErrUserAlreadyExist = errors.New("user already exist") // ErrNotSupportYet returns not support temp ErrNotSupportYet = errors.New("not error, just not support yet") // ErrNewUserAddFail returns add new user fail for unknown reason ErrNewUserAddFail = errors.New("new user add fail") // ErrCreateSpaceTimeFail returns when create space time fail ErrCreateSpaceTimeFail = errors.New("create space time fail") // ErrAddUserToSpaceTimeFail returns when add user to space time fail ErrAddUserToSpaceTimeFail = errors.New("add user to space time fail") // ErrCreateRootUserFail returns when create root user fail ErrCreateRootUserFail = errors.New("create root user fail") // ErrContentTypeNotBirth returns when try to add user from a not birth message ErrContentTypeNotBirth = errors.New("content type is not TypeBirth") // ErrDimensionNumberNotSuitable returns if the dimension is zero or too large ErrDimensionNumberNotSuitable = errors.New("number of dimension is not suitable") // ErrPerimeterIsZero returns if perimeter is zero ErrPerimeterIsZero = errors.New("perimeter should not be zero") )
Functions ¶
Types ¶
type Auth ¶
Auth contain public key
func (Auth) MarshalJSON ¶
MarshalJSON marshal public key to json
func (*Auth) UnmarshalJSON ¶
UnmarshalJSON is used to unmarshal json
type ContentBirth ¶ added in v0.1.0
ContentBirth is the birth msg content, which can create new user
func CreateContentBirth ¶ added in v0.1.0
func CreateContentBirth(name string, extra string, auth *Auth) (*ContentBirth, error)
CreateContentBirth create the birth msg content , which usually from the new user, not sign by parents yet
func (*ContentBirth) SignByParent ¶ added in v0.1.0
func (mv *ContentBirth) SignByParent(user *User, privKey crypto.PrivateKey) error
SignByParent used to sign the birth msg by both parents
type ContentEvidence ¶ added in v0.1.0
ContentEvidence is the evidence of user illegal behavior, Recevier can punish the user by there own will. SenderID can be nil, for anonymous evidence
func CreateContentEvidence ¶ added in v0.1.0
func CreateContentEvidence(evidenceType int, msgs []*Message) *ContentEvidence
CreateContentEvidence create the evidence msg content contain proof of user illeagal behavior
func CreateEBCE ¶ added in v0.1.0
func CreateEBCE(msgs ...*Message) (*ContentEvidence, error)
CreateEBCE creaste the evidence of ExcessiveBirth
func CreateLPCE ¶ added in v0.1.0
func CreateLPCE(privKey crypto.PrivateKey, msg *Message) (*ContentEvidence, error)
CreateLPCE create the evidence of leaked privatekey
type Message ¶
type Message struct { SenderID common.Hash `json:"senderID"` Reference []*MsgReference `json:"reference"` Value *MsgValue `json:"value"` Signature *crypto.Signature `json:"signature"` }
Message is valid msg in pdu
func CreateMsg ¶
func CreateMsg(user *User, value *MsgValue, priKey *crypto.PrivateKey, refs ...*MsgReference) (*Message, error)
CreateMsg used to create a new msg by user in universe
func (Message) ChildrenID ¶
ChildrenID always return nil for msg (useless in pdu)
type MsgReference ¶
type MsgReference struct { SenderID common.Hash `json:"senderID"` MsgID common.Hash `json:"msgID"` }
MsgReference is the msg before current msg
type SpaceTime ¶ added in v0.1.0
type SpaceTime struct {
// contains filtered or unexported fields
}
SpaceTime contain time proof of this space time and the user info who is valid in this space time
func NewSpaceTime ¶ added in v0.1.0
func NewSpaceTime(u *Universe, msg *Message, ref *MsgReference) (*SpaceTime, error)
NewSpaceTime create the new space-time
func (*SpaceTime) AddUser ¶ added in v0.1.0
func (s *SpaceTime) AddUser(ref *MsgReference, contentBirth ContentBirth, user *User) error
AddUser add user info to this space time
func (SpaceTime) GetUserIDs ¶ added in v0.1.0
GetUserIDs returns users ID of space-time
func (SpaceTime) GetUserInfo ¶ added in v0.1.0
GetUserInfo returns userInfo in current space-time by userID
func (*SpaceTime) UpdateTimeProof ¶ added in v0.1.0
UpdateTimeProof update the tp info
type Universe ¶
type Universe struct {
// contains filtered or unexported fields
}
Universe is the struct contain all the information can be received and validated. It is built with two precreate users as root users. Any message should be validated before add into msgD, which is a DAG used to store message. If new user create from valid message, the user should add into userD, a DAG used to store all users. The universe contain at least one spacetime, each spacetime base on one user msg as time line. validation of message mean this message should be valid at least in one of spacetime in stD. Information in local universe is only part of information in whole decentralized system.
func NewUniverse ¶
NewUniverse create Universe with two user with diff gender as root users
func (*Universe) AddMsg ¶ added in v0.1.0
AddMsg will check if the message from valid user, who is validated in at least one spacetime (in stD). Then new message will be added into Universe and update time proof if msg.SenderID is any spacetime based on.
func (*Universe) AddSpaceTime ¶ added in v0.1.0
func (u *Universe) AddSpaceTime(msg *Message, ref *MsgReference) error
AddSpaceTime will add spacetime in Universe with msg.SenderID, and follow the time sequence from ref.
func (Universe) CheckUserExist ¶ added in v0.1.0
CheckUserExist check if the user valid in the Universe
func (Universe) GetMsgByID ¶
GetMsgByID will return the msg by msg.ID() nil will be return if msg not exist
func (*Universe) GetSpaceTimeIDs ¶ added in v0.1.0
GetSpaceTimeIDs get ids in of spacetime (list of msg.SenderID of each spacetime)
func (Universe) GetUserByID ¶ added in v0.1.0
GetUserByID return the user from userD, not userInfo by space time
func (Universe) GetUserIDs ¶ added in v0.1.0
GetUserIDs return userIDs in this space time
type User ¶
type User struct { Name string `json:"name"` BirthExtra string `json:"extra"` Auth *Auth `json:"auth"` BirthMsg *Message `json:"birthMsg"` LifeTime uint64 `json:"lifeTime"` }
User is the author of any msg in pdu
func CreateNewUser ¶
CreateNewUser create new user by cosign message The msg must be signed by user in local user dag. Both parents must be in the local use dag. Both parents fit the nature rules. The Birth struct signed by both parents.
func CreateRootUser ¶ added in v0.1.0
CreateRootUser try to create root user by public key Gender of the root user is depend on key,name and extra
func (User) Distance ¶ added in v0.1.0
func (u User) Distance(location common.Hash, dimension int, perimeter *big.Int) (distance *big.Int, err error)
Distance return the distance from user to common.Hash base on setting perimeter and dimension
func (User) GetCoordinates ¶ added in v0.1.0
func (u User) GetCoordinates(location common.Hash, dimension int, perimeter *big.Int) ([]*big.Int, error)
GetCoordinates returns the coordinates of location, use u.ID as origin point
func (User) ID ¶
ID return the vertex.id, related to parents and value of the vertex ID cloud use as address of user account
func (*User) MarshalJSON ¶
MarshalJSON marshal user to json
func (User) ParentsID ¶
ParentsID return the ID of user parents, res[0] should be the female parent (id end by even) res[1] should be the male parent (id end by odd)
func (User) StandardDistance ¶ added in v0.1.0
StandardDistance return the distance from user to common.Hash base on default setting perimeter and dimension
func (*User) UnmarshalJSON ¶
UnmarshalJSON is used to unmarshal json
type UserInfo ¶ added in v0.1.0
type UserInfo struct {
// contains filtered or unexported fields
}
UserInfo contain the information except pass by BirthMsg the state related to nature rule is start by nature the other state start by local
func NewUserInfo ¶ added in v0.1.0
NewUserInfo create new user info for userstate in space time