prototree

package
v0.0.0-...-2c4dd60 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolName = "prototree"

Variables

View Source
var DefaultACLMembersKeypath = state.Keypath("Members")

Functions

func NewAnnounceP2PStateURIsTask

func NewAnnounceP2PStateURIsTask(
	interval time.Duration,
	treeProto *treeProtocol,
) *announceP2PStateURIsTask

func NewAnnounceStateURIsTask

func NewAnnounceStateURIsTask(
	interval time.Duration,
	treeProto *treeProtocol,
) *announceStateURIsTask

func NewPruneTxsTask

func NewPruneTxsTask(
	interval time.Duration,
	store Store,
) *pruneTxsTask

func NewStore

func NewStore(db *state.DBTree) (*store, error)

func NewTreeProtocol

func NewTreeProtocol(
	transports []swarm.Transport,
	hushProto protohush.HushProtocol,
	controllerHub tree.ControllerHub,
	txStore tree.TxStore,
	keyStore identity.KeyStore,
	peerStore swarm.PeerStore,
	store Store,
) *treeProtocol

Types

type ACL

type ACL interface {
	TypeOf(stateURI string) StateURIType
	MembersOf(stateURI string) (types.Set[types.Address], error)
	HasReadAccess(stateURI string, keypath state.Keypath, addresses types.Set[types.Address]) (bool, error)
}

type AckReceivedCallback

type AckReceivedCallback func(stateURI string, txID state.Version, peerConn TreePeerConn)

type BaseTreeTransport

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

func (*BaseTreeTransport) HandleAckReceived

func (t *BaseTreeTransport) HandleAckReceived(stateURI string, txID state.Version, peerConn TreePeerConn)

func (*BaseTreeTransport) HandleP2PStateURIReceived

func (t *BaseTreeTransport) HandleP2PStateURIReceived(stateURI string, peerConn TreePeerConn)

func (*BaseTreeTransport) HandlePrivateTxReceived

func (t *BaseTreeTransport) HandlePrivateTxReceived(encryptedTx EncryptedTx, peerConn TreePeerConn)

func (*BaseTreeTransport) HandleTxReceived

func (t *BaseTreeTransport) HandleTxReceived(tx tree.Tx, peerConn TreePeerConn)

func (*BaseTreeTransport) HandleWritableSubscriptionOpened

func (t *BaseTreeTransport) HandleWritableSubscriptionOpened(req SubscriptionRequest, writeSubImplFactory WritableSubscriptionImplFactory) (<-chan struct{}, error)

func (*BaseTreeTransport) OnAckReceived

func (t *BaseTreeTransport) OnAckReceived(handler AckReceivedCallback)

func (*BaseTreeTransport) OnP2PStateURIReceived

func (t *BaseTreeTransport) OnP2PStateURIReceived(handler P2PStateURIReceivedCallback)

func (*BaseTreeTransport) OnPrivateTxReceived

func (t *BaseTreeTransport) OnPrivateTxReceived(handler PrivateTxReceivedCallback)

func (*BaseTreeTransport) OnTxReceived

func (t *BaseTreeTransport) OnTxReceived(handler TxReceivedCallback)

func (*BaseTreeTransport) OnWritableSubscriptionOpened

func (t *BaseTreeTransport) OnWritableSubscriptionOpened(handler WritableSubscriptionOpenedCallback)

type DefaultACL

type DefaultACL struct {
	ControllerHub tree.ControllerHub
}

func (DefaultACL) HasReadAccess

func (acl DefaultACL) HasReadAccess(stateURI string, keypath state.Keypath, addresses types.Set[types.Address]) (bool, error)

func (DefaultACL) MembersOf

func (acl DefaultACL) MembersOf(stateURI string) (types.Set[types.Address], error)

func (DefaultACL) TypeOf

func (acl DefaultACL) TypeOf(stateURI string) StateURIType

type EncryptedTx

type EncryptedTx = protohush.GroupMessage

type FetchHistoryOpts

type FetchHistoryOpts struct {
	FromTxID state.Version
	ToTxID   state.Version
}

type P2PStateURIReceivedCallback

type P2PStateURIReceivedCallback func(stateURI string, peerConn TreePeerConn)

type PrivateTxReceivedCallback

type PrivateTxReceivedCallback func(encryptedTx EncryptedTx, peerConn TreePeerConn)

type ReadableSubscription

type ReadableSubscription interface {
	Read() (SubscriptionMsg, error)
	Close() error
}

type StateURISubscription

type StateURISubscription interface {
	Read(ctx context.Context) (string, error)
	Close() error
}

type StateURIType

type StateURIType int
const (
	StateURIType_Invalid StateURIType = iota
	StateURIType_DeviceLocal
	// StateURIType_UserLocal
	StateURIType_Private
	StateURIType_Public
)

func (StateURIType) String

func (t StateURIType) String() string

type Store

type Store interface {
	SubscribedStateURIs() types.Set[string]
	AddSubscribedStateURI(stateURI string) error
	RemoveSubscribedStateURI(stateURI string) error
	OnNewSubscribedStateURI(handler func(stateURI string)) (unsubscribe func())

	MaxPeersPerSubscription() uint64
	SetMaxPeersPerSubscription(max uint64) error

	TxSeenByPeer(deviceUniqueID, stateURI string, txID state.Version) bool
	MarkTxSeenByPeer(deviceUniqueID, stateURI string, txID state.Version) error
	PruneTxSeenRecordsOlderThan(threshold time.Duration) error

	EncryptedTx(stateURI string, txID state.Version) (EncryptedTx, error)
	SaveEncryptedTx(stateURI string, txID state.Version, etx EncryptedTx) error

	DebugPrint()
}

type SubscriptionMsg

type SubscriptionMsg struct {
	StateURI    string          `json:"stateURI"`
	Tx          *tree.Tx        `json:"tx,omitempty"`
	EncryptedTx *EncryptedTx    `json:"encryptedTx,omitempty"`
	State       state.Node      `json:"state,omitempty"`
	Leaves      []state.Version `json:"leaves,omitempty"`
	Error       error           `json:"error,omitempty"`
}

type SubscriptionRequest

type SubscriptionRequest struct {
	StateURI         string
	Keypath          state.Keypath
	Type             SubscriptionType
	FetchHistoryOpts *FetchHistoryOpts
	Addresses        types.Set[types.Address]
}

type SubscriptionType

type SubscriptionType uint8
const (
	SubscriptionType_Txs SubscriptionType = 1 << iota
	SubscriptionType_States
)

func (SubscriptionType) Includes

func (t SubscriptionType) Includes(x SubscriptionType) bool

func (SubscriptionType) MarshalText

func (t SubscriptionType) MarshalText() ([]byte, error)

func (SubscriptionType) String

func (t SubscriptionType) String() string

func (*SubscriptionType) UnmarshalText

func (t *SubscriptionType) UnmarshalText(bs []byte) error

type TreePeerConn

type TreePeerConn interface {
	swarm.PeerConn
	Subscribe(ctx context.Context, stateURI string) (ReadableSubscription, error)
	SendTx(ctx context.Context, tx tree.Tx) error
	SendPrivateTx(ctx context.Context, encryptedTx EncryptedTx) (err error)
	Ack(stateURI string, txID state.Version) error
	AnnounceP2PStateURI(ctx context.Context, stateURI string) error
}

type TreeProtocol

type TreeProtocol interface {
	process.Interface
	ProvidersOfStateURI(ctx context.Context, stateURI string) <-chan TreePeerConn
	Subscribe(ctx context.Context, stateURI string) error
	InProcessSubscription(ctx context.Context, stateURI string, subscriptionType SubscriptionType, keypath state.Keypath, fetchHistoryOpts *FetchHistoryOpts) (ReadableSubscription, error)
	Unsubscribe(stateURI string) error
	SubscribeStateURIs() (StateURISubscription, error)
	SendTx(ctx context.Context, tx tree.Tx) error
}

type TreeTransport

type TreeTransport interface {
	swarm.Transport
	ProvidersOfStateURI(ctx context.Context, stateURI string) (<-chan TreePeerConn, error)
	AnnounceStateURIs(ctx context.Context, stateURIs types.Set[string])
	OnTxReceived(handler TxReceivedCallback)
	OnPrivateTxReceived(handler PrivateTxReceivedCallback)
	OnAckReceived(handler AckReceivedCallback)
	OnWritableSubscriptionOpened(handler WritableSubscriptionOpenedCallback)
	OnP2PStateURIReceived(handler P2PStateURIReceivedCallback)
}

type TxReceivedCallback

type TxReceivedCallback func(tx tree.Tx, peerConn TreePeerConn)

type WritableSubscription

type WritableSubscription interface {
	process.Interface
	StateURI() string
	Keypath() state.Keypath
	Type() SubscriptionType
	Addresses() types.Set[types.Address]
	EnqueueWrite(msg SubscriptionMsg)
	String() string
}

type WritableSubscriptionImpl

type WritableSubscriptionImpl interface {
	process.Interface
	Put(ctx context.Context, msg SubscriptionMsg) error
	String() string
}

type WritableSubscriptionImplFactory

type WritableSubscriptionImplFactory func() (WritableSubscriptionImpl, error)

type WritableSubscriptionOpenedCallback

type WritableSubscriptionOpenedCallback func(req SubscriptionRequest, writeSubImplFactory WritableSubscriptionImplFactory) (<-chan struct{}, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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