const ( MaxMessageSubjectLen = 128 MaxMessageTextLen = 1024 MaxMessageDepth = 1024 MinMessagePostDelay = 1 * time.Minute )
const ( OperationTypeRemoveMessageStr string = "RemoveMessage" OperationTypeBanUserStr string = "BanUser" )
const ( OperationReasonProtocolViolationStr string = "ProtocolViolation" OperationReasonSpamStr string = "SPAM" OperationReasonOfftopicStr string = "Offtopic" OperationReasonAbuseStr string = "Abuse" OperationReasonDuplicateStr string = "Duplicate" )
const ( MaxOperationCommentLen int = 1024 MinOperationPostDelay = 1 * time.Minute )
const ( MaxUsernameLen = 64 EpochTimestamp = 1546300800000000000 // 2019 Jan 01 )
var ( Epoch = time.Unix(0, EpochTimestamp) )
func IsNicknameValid(nickname string) bool
type Descriptor struct { Type Type `json:"type"` ID ID `json:"id"` }
Entity is a logical unit of data for communication between peers.
type Entity interface { Type() Type ID() *ID ShortID() string String() string }
type EntityProvider interface { AttachObserver(c chan<- Entity) DetachObserver(c chan<- Entity) }
type ID [32]byte
var ZeroID ID
func NewID(data []byte) ID
func (i *ID) IsZero() bool
func (i ID) MarshalJSON() ([]byte, error)
func (i *ID) ParseSlice(s []byte) error
func (i *ID) ParseString(s string) error
func (i *ID) Shorten() string
func (i *ID) String() string
func (i *ID) UnmarshalJSON(b []byte) error
Message is some text information published by a user.
type Message struct { UnsignedMessage Sig crypto.Signature }
func EmergeMessage( subject string, text string, authorID *ID, parentID *ID, signer *crypto.Signer, topic subs.Topic, ) (*Message, error)
EmergeMessage creates a new message. It should be called when owner wants to post a new message. Signature will be created using the provided signer.
func NewMessage( subject string, text string, authorID *ID, parentID *ID, dateWritten time.Time, sig crypto.Signature, topic subs.Topic, ) (*Message, error)
NewMessage composes a new message entity object from the specified data.
func (m *Message) Copy() *Message
func (m *Message) IsReply() bool
func (m *Message) IsSigValid(pubKey *crypto.PublicKey) bool
func (m *Message) IsUnsignedPartValid() bool
func (m *Message) IsValid(pubKey *crypto.PublicKey) bool
You have either Topic or ParentID, never both.
type MessageContent struct { Subject string Text string AuthorID ID ParentID ID DateWritten time.Time Topic subs.Topic }
func (mc *MessageContent) ToID() *ID
Operation is an action performed on a user or a message.
type Operation struct { UnsignedOperation Sig crypto.Signature }
func EmergeOperation( typ OperationType, reason OperationReason, comment string, authorID *ID, objectID *ID, signer *crypto.Signer, ) (*Operation, error)
EmergeOperation creates a new operation. It will be called when owner wants to perform a new operation and automatically by the protocol implementation (for example, for blocking malicious peers). Signature will be created using the provided signer.
func NewOperation( typ OperationType, reason OperationReason, comment string, authorID *ID, objectID *ID, datePerformed time.Time, sig crypto.Signature, ) (*Operation, error)
NewOperation composes a new operation entity object from the specified data.
func (o *Operation) IsSigValid(pubKey *crypto.PublicKey) bool
func (o *Operation) IsUnsignedPartValid() bool
func (o *Operation) IsValid(pubKey *crypto.PublicKey) bool
type OperationContent struct { Type OperationType Reason OperationReason Comment string AuthorID ID ObjectID ID DatePerformed time.Time }
func (oc *OperationContent) ToID() *ID
type OperationReason int
const ( OperationReasonProtocolViolation OperationReason = iota OperationReasonSpam OperationReasonOfftopic OperationReasonAbuse OperationReasonDuplicate )
func (or *OperationReason) ParseString(s string) error
func (or OperationReason) String() string
type OperationType int
const ( OperationTypeRemoveMessage OperationType = iota OperationTypeBanUser )
func (ot OperationType) String() string
type StoredMessage struct { M *Message Stored time.Time }
type StoredOperation struct { O *Operation Stored time.Time }
type StoredUser struct { U *User Stored time.Time }
type Type int
const ( // User registers, post messages and performs operations. TypeUser Type = iota // Some information published by a user. TypeMessage // An action performed on a user or a message. TypeOperation )
type UnsignedMessage struct { Descriptor MessageContent }
func (um *UnsignedMessage) ID() *ID
func (um *UnsignedMessage) ShortID() string
func (um *UnsignedMessage) String() string
func (um *UnsignedMessage) Type() Type
type UnsignedOperation struct { Descriptor OperationContent }
func (uo *UnsignedOperation) ID() *ID
func (uo *UnsignedOperation) OperationType() OperationType
func (uo *UnsignedOperation) ShortID() string
func (uo *UnsignedOperation) String() string
func (uo *UnsignedOperation) Type() Type
type UnsignedUser struct { Descriptor UserContent }
func (uu *UnsignedUser) String() string
User identifies and describes a user. It's suitable for sending to the network. Implements Entity interface.
type User struct { UnsignedUser Sig crypto.Signature }
func EmergeUser( nickname string, info string, proof crypto.ProofOfWork, signer *crypto.Signer, ) (*User, error)
EmergeUser creates a new user entity. It should only be called when signature is not known yet. Signature will be created using the provided signer.
func NewUser( nickname string, info string, pubkey *crypto.PublicKey, proof crypto.ProofOfWork, regdate time.Time, sig crypto.Signature, ) *User
func (u *User) Dump() string
func (u *User) ID() *ID
func (u *User) IsValid() bool
func (u *User) ShortID() string
func (u *User) Type() Type
type UserContent struct { PubKey crypto.PublicKey Proof crypto.ProofOfWork Nickname string Info string RegDate time.Time }
func (uc *UserContent) ToID() *ID
type UserHistory struct { ID *ID Disconnected time.Time Subs subs.Subscriptions }