data

package
v0.0.0-...-64ed5c8 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceDbName = "devices.db"
)

implementation of devices/request db in sqlite3

View Source
const (
	OfflineDbName = "offline.db"
)

implementation of devices/request db in sqlite3

Variables

This section is empty.

Functions

func GetIdentities

func GetIdentities() ([]string, error)

func ReadDir

func ReadDir(root string) ([]string, error)

func SetIdentityAsDefault

func SetIdentityAsDefault(name string) bool

Types

type BrokerEvent

type BrokerEvent struct {
	Event   string      `json:"event"`
	Payload interface{} `json:"payload"`
}

type Configuration

type Configuration struct {
	TorPublicAddress string
	PublicKey        string
}

type Conversation

type Conversation struct {
	ConversationID string   `json:"conversation_id"` // it's the conversation name sha
	Name           string   `json:"name"`
	Recipients     []string `json:"recipients"` // recipient's publickey, for now with size 1, this will be used for group chats
	Lastupdate     string   `json:"-"`
}

func GenerateConversation

func GenerateConversation(name string, recipients []string) Conversation

type Device

type Device struct {
	URL       string `json:"url"`   // kxtfrw2fnlnby4nnuh77xeoaiokb6y7vik3nddjfryjk7bdj4xfz3hqd
	Alias     string `json:"alias"` // only local, to display
	PublicKey string `json:"public_key"`
	IsOnline  bool   `json:"is_online"`
	SharedKey string `json:"-"`
}

type DeviceRequest

type DeviceRequest struct {
	URL       string        `json:"url"`
	PublicKey string        `json:"public_key"`
	Alias     string        `json:"alias"`
	Status    RequestStatus `json:"status"`
}

type DevicesDatabase

type DevicesDatabase interface {
	StoreRequest(request DeviceRequest) error
	GetRequests() []DeviceRequest
	GetRequestByURL(url string) *DeviceRequest
	DeleteRequest(request DeviceRequest) error

	StoreDevice(device Device) error
	GetDevices() []Device
	GetDeviceByURL(url string) *Device
	GetDeviceByPublicKey(publicKey string) *Device
	DeleteDevice(device Device) error

	ConfirmRequest(request DeviceRequest, sharedKey string) (*Device, error)
}

type DevicesSqliteDB

type DevicesSqliteDB struct {
	SqliteDB
}

func InitDevicesSqlite

func InitDevicesSqlite(path string) DevicesSqliteDB

func (DevicesSqliteDB) ConfirmRequest

func (d DevicesSqliteDB) ConfirmRequest(request DeviceRequest, sharedKey string) (*Device, error)

func (DevicesSqliteDB) DeleteDevice

func (d DevicesSqliteDB) DeleteDevice(device Device) error

func (DevicesSqliteDB) DeleteRequest

func (d DevicesSqliteDB) DeleteRequest(request DeviceRequest) error

func (DevicesSqliteDB) GetDeviceByPublicKey

func (d DevicesSqliteDB) GetDeviceByPublicKey(publicKey string) *Device

func (DevicesSqliteDB) GetDeviceByURL

func (d DevicesSqliteDB) GetDeviceByURL(url string) *Device

func (DevicesSqliteDB) GetDevices

func (d DevicesSqliteDB) GetDevices() []Device

func (DevicesSqliteDB) GetRequestByURL

func (d DevicesSqliteDB) GetRequestByURL(url string) *DeviceRequest

func (DevicesSqliteDB) GetRequests

func (d DevicesSqliteDB) GetRequests() []DeviceRequest

func (DevicesSqliteDB) StoreDevice

func (d DevicesSqliteDB) StoreDevice(device Device) error

func (DevicesSqliteDB) StoreRequest

func (d DevicesSqliteDB) StoreRequest(request DeviceRequest) error

type Identity

type Identity struct {
	Name               string               `json:"name"`
	PublicServiceKeys  torHiddenServiceKeys `json:"public_service_keys"`
	PrivateServiceKeys torHiddenServiceKeys `json:"private_service_keys"`
	PublicKey          string               `json:"public_key"`
	PrivateKey         string               `json:"private_key"`
}

func GenerateIdentity

func GenerateIdentity(name string) (*Identity, error)

func GetOrGenerateDefaultIdentity

func GetOrGenerateDefaultIdentity() (*Identity, error)

func (*Identity) GetDataDir

func (identity *Identity) GetDataDir() string

type Message

type Message struct {
	MessageID      string `json:"message_id"` // nonce
	ConversationID string `json:"conversation_id"`
	Recipient      string `json:"recipient"` // it's the device public key, "SELF" for your own messages
	Content        string `json:"content"`
	Timestamp      string `json:"timestamp"`
}

type MessageDB

type MessageDB interface {
	GetConversations() []Conversation //sorted by lastupdate
	GetConversationByID(conversationID string) *Conversation
	GetConversationsByRecipient(recipient string) []Conversation
	StoreConversation(conversation Conversation) error
	RefreshConversationLastUpdate(conversationID string, timestamp string) error

	GetNewestMessages(conversationID string, count int) []Message
	//GetMessagesPage(conversationID string, limit int, offset int) []Message
	StoreMessage(message Message) error
}

type MessagesSqliteDB

type MessagesSqliteDB struct {
	SqliteDB
}

func InitMessagesSqlite

func InitMessagesSqlite(path string) MessagesSqliteDB

func (MessagesSqliteDB) GetConversationByID

func (m MessagesSqliteDB) GetConversationByID(conversationID string) *Conversation

func (MessagesSqliteDB) GetConversations

func (m MessagesSqliteDB) GetConversations() []Conversation

func (MessagesSqliteDB) GetConversationsByRecipient

func (m MessagesSqliteDB) GetConversationsByRecipient(recipient string) []Conversation

func (MessagesSqliteDB) GetNewestMessages

func (m MessagesSqliteDB) GetNewestMessages(conversationID string, count int) []Message

func (MessagesSqliteDB) RefreshConversationLastUpdate

func (m MessagesSqliteDB) RefreshConversationLastUpdate(conversationID string, timestamp string) error

func (MessagesSqliteDB) StoreConversation

func (m MessagesSqliteDB) StoreConversation(conversation Conversation) error

func (MessagesSqliteDB) StoreMessage

func (m MessagesSqliteDB) StoreMessage(message Message) error

type OfflineRequest

type OfflineRequest struct {
	ID        int
	Host      string
	Path      string
	Method    string
	Payload   []byte
	Encrypted bool
}

type OfflineSqliteDB

type OfflineSqliteDB struct {
	SqliteDB
}

func InitOfflineSqlite

func InitOfflineSqlite(path string) OfflineSqliteDB

func (OfflineSqliteDB) DeleteRequest

func (d OfflineSqliteDB) DeleteRequest(request OfflineRequest) bool

func (OfflineSqliteDB) GetRequests

func (d OfflineSqliteDB) GetRequests(publicKey string) []OfflineRequest

func (OfflineSqliteDB) StoreRequest

func (d OfflineSqliteDB) StoreRequest(publicKey string, request OfflineRequest) bool

type Presence

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

func InitPresence

func InitPresence() *Presence

func (*Presence) Get

func (p *Presence) Get() []string

func (*Presence) Remove

func (p *Presence) Remove(publicKey string)

func (*Presence) Store

func (p *Presence) Store(publicKey string)

type PrimalInterface

type PrimalInterface interface {
	GetPublicURL() string
	GetPublicKey() string
	Notify(event BrokerEvent)
	Send(request http.Request, encrypt bool) (*http.Response, error)
	GetMiddleware(next http.Handler) func(w http.ResponseWriter, r *http.Request)
	ComputeSharedKey(publicKey string) string
	GetDevices() []Device
	GetOfflineQueue() OfflineSqliteDB
	SendPendingRequests(publicKey string)
	IsURLOnline(url string) bool
}

type RequestStatus

type RequestStatus int
const (
	RequestSentStatus RequestStatus = iota + 1
	RequestPendingStatus
)

type SqliteDB

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

Jump to

Keyboard shortcuts

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