...

Package entity

import "vminko.org/dscuss/entity"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func IsNicknameValid(nickname string) bool
type Descriptor
type Entity
type EntityProvider
type 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
type Message
    func EmergeMessage(subject string, text string, authorID *ID, parentID *ID, signer *crypto.Signer, topic subs.Topic) (*Message, error)
    func NewMessage(subject string, text string, authorID *ID, parentID *ID, dateWritten time.Time, sig crypto.Signature, topic subs.Topic) (*Message, error)
    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
type MessageContent
    func (mc *MessageContent) ToID() *ID
type Operation
    func EmergeOperation(typ OperationType, reason OperationReason, comment string, authorID *ID, objectID *ID, signer *crypto.Signer) (*Operation, error)
    func NewOperation(typ OperationType, reason OperationReason, comment string, authorID *ID, objectID *ID, datePerformed time.Time, sig crypto.Signature) (*Operation, error)
    func (o *Operation) IsSigValid(pubKey *crypto.PublicKey) bool
    func (o *Operation) IsUnsignedPartValid() bool
    func (o *Operation) IsValid(pubKey *crypto.PublicKey) bool
type OperationContent
    func (oc *OperationContent) ToID() *ID
type OperationReason
    func (or *OperationReason) ParseString(s string) error
    func (or OperationReason) String() string
type OperationType
    func (ot OperationType) String() string
type StoredMessage
type StoredOperation
type StoredUser
type Type
type UnsignedMessage
    func (um *UnsignedMessage) ID() *ID
    func (um *UnsignedMessage) ShortID() string
    func (um *UnsignedMessage) String() string
    func (um *UnsignedMessage) Type() Type
type UnsignedOperation
    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
    func (uu *UnsignedUser) String() string
type User
    func EmergeUser(nickname string, info string, proof crypto.ProofOfWork, signer *crypto.Signer) (*User, error)
    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
    func (uc *UserContent) ToID() *ID
type UserHistory

Package files

entity.go message.go operation.go user.go

Constants

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

)

Variables

var (
    Epoch = time.Unix(0, EpochTimestamp)
)

func IsNicknameValid

func IsNicknameValid(nickname string) bool

type Descriptor

type Descriptor struct {
    Type Type `json:"type"`
    ID   ID   `json:"id"`
}

type Entity

Entity is a logical unit of data for communication between peers.

type Entity interface {
    Type() Type
    ID() *ID
    ShortID() string
    String() string
}

type EntityProvider

type EntityProvider interface {
    AttachObserver(c chan<- Entity)
    DetachObserver(c chan<- Entity)
}

type ID

type ID [32]byte
var ZeroID ID

func NewID

func NewID(data []byte) ID

func (*ID) IsZero

func (i *ID) IsZero() bool

func (ID) MarshalJSON

func (i ID) MarshalJSON() ([]byte, error)

func (*ID) ParseSlice

func (i *ID) ParseSlice(s []byte) error

func (*ID) ParseString

func (i *ID) ParseString(s string) error

func (*ID) Shorten

func (i *ID) Shorten() string

func (*ID) String

func (i *ID) String() string

func (*ID) UnmarshalJSON

func (i *ID) UnmarshalJSON(b []byte) error

type Message

Message is some text information published by a user.

type Message struct {
    UnsignedMessage
    Sig crypto.Signature
}

func EmergeMessage

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

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 (*Message) Copy

func (m *Message) Copy() *Message

func (*Message) IsReply

func (m *Message) IsReply() bool

func (*Message) IsSigValid

func (m *Message) IsSigValid(pubKey *crypto.PublicKey) bool

func (*Message) IsUnsignedPartValid

func (m *Message) IsUnsignedPartValid() bool

func (*Message) IsValid

func (m *Message) IsValid(pubKey *crypto.PublicKey) bool

type MessageContent

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 (*MessageContent) ToID

func (mc *MessageContent) ToID() *ID

type Operation

Operation is an action performed on a user or a message.

type Operation struct {
    UnsignedOperation
    Sig crypto.Signature
}

func EmergeOperation

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

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 (*Operation) IsSigValid

func (o *Operation) IsSigValid(pubKey *crypto.PublicKey) bool

func (*Operation) IsUnsignedPartValid

func (o *Operation) IsUnsignedPartValid() bool

func (*Operation) IsValid

func (o *Operation) IsValid(pubKey *crypto.PublicKey) bool

type OperationContent

type OperationContent struct {
    Type          OperationType
    Reason        OperationReason
    Comment       string
    AuthorID      ID
    ObjectID      ID
    DatePerformed time.Time
}

func (*OperationContent) ToID

func (oc *OperationContent) ToID() *ID

type OperationReason

type OperationReason int
const (
    OperationReasonProtocolViolation OperationReason = iota
    OperationReasonSpam
    OperationReasonOfftopic
    OperationReasonAbuse
    OperationReasonDuplicate
)

func (*OperationReason) ParseString

func (or *OperationReason) ParseString(s string) error

func (OperationReason) String

func (or OperationReason) String() string

type OperationType

type OperationType int
const (
    OperationTypeRemoveMessage OperationType = iota
    OperationTypeBanUser
)

func (OperationType) String

func (ot OperationType) String() string

type StoredMessage

type StoredMessage struct {
    M      *Message
    Stored time.Time
}

type StoredOperation

type StoredOperation struct {
    O      *Operation
    Stored time.Time
}

type StoredUser

type StoredUser struct {
    U      *User
    Stored time.Time
}

type Type

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

type UnsignedMessage struct {
    Descriptor
    MessageContent
}

func (*UnsignedMessage) ID

func (um *UnsignedMessage) ID() *ID

func (*UnsignedMessage) ShortID

func (um *UnsignedMessage) ShortID() string

func (*UnsignedMessage) String

func (um *UnsignedMessage) String() string

func (*UnsignedMessage) Type

func (um *UnsignedMessage) Type() Type

type UnsignedOperation

type UnsignedOperation struct {
    Descriptor
    OperationContent
}

func (*UnsignedOperation) ID

func (uo *UnsignedOperation) ID() *ID

func (*UnsignedOperation) OperationType

func (uo *UnsignedOperation) OperationType() OperationType

func (*UnsignedOperation) ShortID

func (uo *UnsignedOperation) ShortID() string

func (*UnsignedOperation) String

func (uo *UnsignedOperation) String() string

func (*UnsignedOperation) Type

func (uo *UnsignedOperation) Type() Type

type UnsignedUser

type UnsignedUser struct {
    Descriptor
    UserContent
}

func (*UnsignedUser) String

func (uu *UnsignedUser) String() string

type User

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

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

func NewUser(
    nickname string,
    info string,
    pubkey *crypto.PublicKey,
    proof crypto.ProofOfWork,
    regdate time.Time,
    sig crypto.Signature,
) *User

func (*User) Dump

func (u *User) Dump() string

func (*User) ID

func (u *User) ID() *ID

func (*User) IsValid

func (u *User) IsValid() bool

func (*User) ShortID

func (u *User) ShortID() string

func (*User) Type

func (u *User) Type() Type

type UserContent

type UserContent struct {
    PubKey   crypto.PublicKey
    Proof    crypto.ProofOfWork
    Nickname string
    Info     string
    RegDate  time.Time
}

func (*UserContent) ToID

func (uc *UserContent) ToID() *ID

type UserHistory

type UserHistory struct {
    ID           *ID
    Disconnected time.Time
    Subs         subs.Subscriptions
}