owl

package
v0.0.0-...-1704659 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: GPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirectMessageV0 = "directmsg@v0"
)

Variables

This section is empty.

Functions

func CheckContactName

func CheckContactName(x string) error

func ForEachChannel

func ForEachChannel(ctx context.Context, s ChannelAPI, persona string, fn func(string) error) error

func ForEachEntry

func ForEachEntry(ctx context.Context, s ChannelAPI, cid ChannelID, fn func(Entry) error) error

func OpenDB

func OpenDB(dbPath string) (*sqlx.DB, error)

Types

type API

type API interface {
	PersonaAPI
	ContactAPI
	ChannelAPI
	BlockingAPI
}

type BlockingAPI

type BlockingAPI interface {
	// Sync blocks until all of the targets have completed a sync.
	// It returns the first error encountered syncing any of the targets
	Sync(ctx context.Context, req *SyncReq) error
	// Wait blocks until any of the targets have changed, then it returns the target that changed.
	Wait(ctx context.Context, req *WaitReq) (*WaitRes, error)
}

type ChannelAPI

type ChannelAPI interface {
	// CreateChannel creates a new channel with name
	CreateChannel(ctx context.Context, req *CreateChannelReq) error
	// JoinChannel joins an existing channel
	JoinChannel(ctx context.Context, req *JoinChannelReq) error
	// DeleteChannel deletes the channel with name if it exists
	DeleteChannel(ctx context.Context, cid *ChannelID) error
	// ListChannels lists channels starting with begin
	ListChannels(ctx context.Context, req *ListChannelReq) ([]string, error)
	// GetLatest returns the latest EntryIndex
	GetChannel(ctx context.Context, cid *ChannelID) (*ChannelInfo, error)

	// Send, sends a message to a channel.
	Send(ctx context.Context, req *SendReq) error
	// Read reads events from a channel
	Read(ctx context.Context, req *ReadReq) ([]Entry, error)
}

type ChannelID

type ChannelID struct {
	Persona string `json:"persona"`
	Name    string `json:"name"`
}

ChannelID uniquely identifies a channel

func (ChannelID) Compare

func (a ChannelID) Compare(b ChannelID) int

type ChannelInfo

type ChannelInfo struct {
	Scheme string    `json:"scheme"`
	Latest EntryPath `json:"latest"`
}

type ChannelWT

type ChannelWT struct {
	ID       ChannelID `json:"id"`
	LastPath EntryPath `json:"last_path"`
	LastID   cadata.ID `json:"last_id"`
}

type Contact

type Contact struct {
	Addrs []inet256.Addr `json:"addrs"`
}

type ContactAPI

type ContactAPI interface {
	// CreateContact adds a contact to the contact list for persona
	CreateContact(ctx context.Context, req *CreateContactReq) error
	// RemoveContact removes a contact.
	DeleteContact(ctx context.Context, req *DeleteContactReq) error
	// ListContacts lists contacts starting with begin.
	ListContact(ctx context.Context, res *ListContactReq) ([]string, error)
	// GetContact returns information about a contact.
	GetContact(ctx context.Context, req *GetContactReq) (*Contact, error)
}

type CreateChannelReq

type CreateChannelReq struct {
	Persona string `json:"persona"`
	Name    string `json:"name"`

	Scheme  string   `json:"scheme"`
	Members []string `json:"members"`
}

type CreateContactReq

type CreateContactReq struct {
	Persona string   `json:"persona"`
	Name    string   `json:"name"`
	Peers   []PeerID `json:"peers"`
}

type CreatePersonaReq

type CreatePersonaReq struct {
	Name string `json:"name"`
}

type DeleteContactReq

type DeleteContactReq struct {
	Persona string `json:"persona"`
	Name    string `json:"name"`
}

type Entry

type Entry struct {
	Path EntryPath
	ID   cadata.ID

	PeerAdded   *PeerAdded
	PeerRemoved *PeerRemoved
	Message     *Message
}

Entry is an element in a Channel. Entries each have a unique Path.

type EntryPath

type EntryPath = Path

type ExpandPersonaReq

type ExpandPersonaReq struct {
	Name  string   `json:"name"`
	Peers []PeerID `json:"peers"`
}

type GetContactReq

type GetContactReq struct {
	Persona string `json:"persona"`
	Name    string `json:"name"`
}

type GetPersonaReq

type GetPersonaReq struct {
	Name string `json:"name"`
}

type JoinChannelReq

type JoinChannelReq struct {
	Persona string     `json:"persona"`
	Name    string     `json:"name"`
	Epoch   owldag.Ref `json:"epoch"`
}

type ListChannelReq

type ListChannelReq struct {
	Persona string `json:"persona"`
	Begin   string `json:"begin"`
	Limit   int    `json:"limit"`
}

type ListContactReq

type ListContactReq struct {
	Persona string `json:"persona"`
}

type Message

type Message struct {
	// AuthorPeer is the PeerID that wrote the message
	AuthorPeer PeerID
	// AuthorContact is the name of the contact which the peer corresponds to (if any).
	AuthorContact string
	After         []EntryPath

	Timestamp time.Time
	Type      string
	Body      json.RawMessage
}

Message is a type of Entry

func (*Message) AsString

func (m *Message) AsString() (ret string)

type MessageParams

type MessageParams struct {
	Thread EntryPath
	Parent EntryPath

	Type string
	Body json.RawMessage
}

MessageParams are used to create a message

func NewText

func NewText(x string) MessageParams

NewText creates parameters for a simple text message

type Path

type Path []uint64

Path identifies an event within a channel Paths will always have a length > 0. If the length is > 1, then all but the last element are considered the ThreadID

func (Path) Marshal

func (mi Path) Marshal() []byte

func (Path) String

func (mi Path) String() string

func (Path) ThreadID

func (mi Path) ThreadID() []uint64

ThreadID is the component of the index which referes to a thread. ThreadID will be nil for messages in the root.

func (Path) Value

func (p Path) Value() (driver.Value, error)

type PeerAdded

type PeerAdded struct {
	Peer, AddedBy PeerID
}

PeerAdded is a type of Entry

type PeerID

type PeerID = owlnet.PeerID

PeerID uniquely identifies peers on the network.

func ParseB64PeerID

func ParseB64PeerID(x []byte) (PeerID, error)

type PeerRemoved

type PeerRemoved struct {
	Peer, RemovedBy PeerID
}

PeerRemoved is a type of Entry

type Persona

type Persona struct {
	LocalIDs  []PeerID `json:"local_ids"`
	RemoteIDs []PeerID `json:"remote_ids"`
}

A Persona is a collection of inet256.IDs LocalIDs are IDs which the instance has a private key for, and can therefore send as those Peers.

type PersonaAPI

type PersonaAPI interface {
	// CreatePersona creates a new persona called name.
	// If any ids are provided then the persona will not have a feed, and will attempt to join
	// a feed provided by one of the IDs.
	CreatePersona(ctx context.Context, req *CreatePersonaReq) error
	// GetPersona retrieves the Persona at name
	GetPersona(ctx context.Context, req *GetPersonaReq) (*Persona, error)
	// DropPersona drops all the state on the local instance associated with a persona
	DropPersona(ctx context.Context, name string) error
	// ListPersonas lists personas on the instance.
	ListPersonas(ctx context.Context) ([]string, error)
	// ExpandPersona adds a peer to the Persona at name.
	ExpandPersona(ctx context.Context, req *ExpandPersonaReq) error
	// ShrinkPersona removes a peer from the Persona at name
	ShrinkPersona(ctx context.Context, req *ShrinkPersonaReq) error
}

type ReadReq

type ReadReq struct {
	Persona string    `json:"persona"`
	Name    string    `json:"name"`
	Begin   EntryPath `json:"begin"`
	Limit   int       `json:"limit"`
}

type Scheme

type Scheme[T any] struct {
	// contains filtered or unexported fields
}

func (Scheme[T]) CanRead

func (sch Scheme[T]) CanRead(ctx context.Context, s cadata.Getter, data json.RawMessage, peer PeerID) (bool, error)

func (Scheme[T]) ListPeers

func (sch Scheme[T]) ListPeers(ctx context.Context, s cadata.Getter, data json.RawMessage) ([]PeerID, error)

func (Scheme[T]) Merge

func (sch Scheme[T]) Merge(ctx context.Context, s cadata.Store, datas []json.RawMessage) (*json.RawMessage, error)

func (Scheme[T]) Sync

func (sch Scheme[T]) Sync(ctx context.Context, src cadata.Getter, dst cadata.Store, data json.RawMessage) error

func (Scheme[T]) Validate

func (sch Scheme[T]) Validate(ctx context.Context, s cadata.Getter, consult owldag.ConsultFunc, data json.RawMessage) error

func (Scheme[T]) ValidateStep

func (sch Scheme[T]) ValidateStep(ctx context.Context, s cadata.Getter, consult owldag.ConsultFunc, d1, d2 json.RawMessage) error

type SendReq

type SendReq struct {
	Persona string `json:"persona"`
	Name    string `json:"name"`

	Params MessageParams `json:"params"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(db *sqlx.DB, inet256srv inet256.Service) *Server

func (*Server) Close

func (s *Server) Close() (retErr error)

func (*Server) CreateChannel

func (s *Server) CreateChannel(ctx context.Context, req *CreateChannelReq) error

CreateChannel creates a new channel

func (*Server) CreateContact

func (s *Server) CreateContact(ctx context.Context, req *CreateContactReq) error

CreateContact looks up the contactset for persona, then puts an entry (name, contact) in that set.

func (*Server) CreatePersona

func (s *Server) CreatePersona(ctx context.Context, req *CreatePersonaReq) error

func (*Server) DeleteChannel

func (s *Server) DeleteChannel(ctx context.Context, cid *ChannelID) error

func (*Server) DeleteContact

func (s *Server) DeleteContact(ctx context.Context, req *DeleteContactReq) error

func (*Server) DropPersona

func (s *Server) DropPersona(ctx context.Context, name string) error

func (*Server) ExpandPersona

func (s *Server) ExpandPersona(ctx context.Context, req *ExpandPersonaReq) error

func (*Server) GetChannel

func (s *Server) GetChannel(ctx context.Context, cid *ChannelID) (*ChannelInfo, error)

func (*Server) GetContact

func (s *Server) GetContact(ctx context.Context, req *GetContactReq) (*Contact, error)

func (*Server) GetLocalPeer

func (s *Server) GetLocalPeer(ctx context.Context, persona string) (*PeerID, error)

GetLocalPeer returns a PeerID to use for communication

func (*Server) GetPersona

func (s *Server) GetPersona(ctx context.Context, req *GetPersonaReq) (*Persona, error)

func (*Server) Init

func (s *Server) Init(ctx context.Context) (err error)

func (*Server) JoinChannel

func (s *Server) JoinChannel(ctx context.Context, req *JoinChannelReq) error

JoinChannel adds an existing channel feed identified by cid.

func (*Server) ListChannels

func (s *Server) ListChannels(ctx context.Context, req *ListChannelReq) ([]string, error)

func (*Server) ListContact

func (s *Server) ListContact(ctx context.Context, req *ListContactReq) ([]string, error)

func (*Server) ListPersonas

func (s *Server) ListPersonas(ctx context.Context) (ret []string, _ error)

func (*Server) Read

func (s *Server) Read(ctx context.Context, req *ReadReq) ([]Entry, error)

func (*Server) Send

func (s *Server) Send(ctx context.Context, req *SendReq) error

func (*Server) ShrinkPersona

func (s *Server) ShrinkPersona(ctx context.Context, req *ShrinkPersonaReq) error

func (*Server) Sync

func (s *Server) Sync(ctx context.Context, req *SyncReq) error

func (*Server) Wait

func (s *Server) Wait(ctx context.Context, req *WaitReq) (*WaitRes, error)

func (*Server) WhoIs

func (s *Server) WhoIs(ctx context.Context, persona string, peerID PeerID) (string, error)

WhoIs returns the contact name for a peer

type ShrinkPersonaReq

type ShrinkPersonaReq struct {
	Name string `json:"name"`
	Peer PeerID `json:"peer"`
}

type SyncReq

type SyncReq struct {
	Targets []SyncTarget `json:"targets"`
}

type SyncTarget

type SyncTarget struct {
	Contacts  *string    `json:"contacts"`
	Directory *string    `json:"directory"`
	Channel   *ChannelID `json:"channel"`
}

type WaitReq

type WaitReq struct {
	Targets []WaitTarget `json:"target"`
}

type WaitRes

type WaitRes struct {
	Channel *ChannelID `json:"channel"`
}

type WaitTarget

type WaitTarget struct {
	Channel *ChannelWT `json:"channel"`
}

Jump to

Keyboard shortcuts

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