entity

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: GPL-3.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MESSAGES_BUFFERSIZE = 100
)

Variables

View Source
var (
	ErrEntityIsNil   = errors.New("entity: entity is nil")
	ErrEntityIsEmtpy = errors.New("entity: entity is empty")
	ErrTopicIsNil    = errors.New("entity: topic is nil")
)

Functions

func DeleteNick added in v0.4.0

func DeleteNick(id string)

func Lookup added in v0.2.0

func Lookup(q string) string

Lookup takes an input string that can be either a nick or an ID, and returns the corresponding ID if found; otherwise, it returns the input.

func Nicks added in v0.4.0

func Nicks() map[string]string

func WatchCSV added in v0.4.0

func WatchCSV() error

Types

type Entity

type Entity struct {

	// Live non-stored data
	// Context to be able to clean up entity.
	Ctx    context.Context
	Cancel context.CancelFunc
	Topic  *p2ppubsub.Topic

	//Stored data
	DID did.DID
	Doc *doc.Document

	// Channels
	Messages chan *Message
}

func Fetch added in v0.4.0

func Fetch(d did.DID) (*Entity, error)

Creates a ned Entity from a DID and fetched the live document. This is used mostly for foreign entities.

func GetOrCreate

func GetOrCreate(didString string) (*Entity, error)

GetOrCreate checks if an Entity with the given DID string exists and returns it; otherwise, it creates a new Entity, stores it, and returns it. The boolean signifies whether to use a cached Entity document in IPFS, or to perform a network search. This might take time at the scale of minutes.

func New

func New(d did.DID) (*Entity, error)

Creates a new Entity from a DID, but does not fetch the document. Use this when creating a new actor for instance

func (*Entity) ConnectPeer added in v0.3.0

func (e *Entity) ConnectPeer() (pi p2peer.AddrInfo, err error)

This function connects to a peer using the DHT. The peer is identified by it's DID. The return value is the peer's AddrInfo. But you needn't use that for anything

func (*Entity) FetchAndSetDocument added in v0.0.11

func (e *Entity) FetchAndSetDocument() error

Fetch the document and set it in the entity. If cached is true, the document will be fetched from the IPFS cache, if available.

func (*Entity) FetchDocument added in v0.0.11

func (e *Entity) FetchDocument(cached bool) (*doc.Document, error)

func (*Entity) HandleIncomingMessages added in v0.3.0

func (e *Entity) HandleIncomingMessages(ctx context.Context, msgChan chan *Message)

Handle incoming messages to an entity. The message are recieved in the e|ntity's message channel. And delivered to a channel of your choice.

func (Entity) Nick added in v0.0.6

func (e Entity) Nick() string

Returns the Entity's nick. Uses and sets the DID as fallback. This does not actually save the nick, as it it will always return the same value for the same DID.

func (Entity) SetNick added in v0.2.0

func (e Entity) SetNick(nick string) error

Sets a node in the database takes new did and nick. If an old did for the alias exists it is removed. This makes this the only alias for the DID and the only complex function in this file.

func (*Entity) Verify added in v0.0.6

func (e *Entity) Verify() error

type Message added in v0.4.0

type Message struct {
	Message   *msg.Message
	Enveloped bool
}

func NewMessage added in v0.4.0

func NewMessage(m *msg.Message, enveloped bool) *Message

Wraps a message and a boolean indicating if it was enveloped. Enveloped messages should probably be sent directly to the sender, whereas non-enveloped messages should be sent to the entity it was received from.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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