store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store 保存中继需要记住的极少量状态。

中继刻意不存会话、消息、设备清单。接口让单租户(JSON 文件)和多租户 (Postgres)走同一套调用,调用方不关心底下是哪种。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenMismatch   = errors.New("注册凭据不匹配")
	ErrKeyMismatch     = errors.New("开发机注册密钥不匹配")
	ErrHostUnknown     = errors.New("开发机尚未登记")
	ErrHostBanned      = errors.New("开发机已被封禁")
	ErrAccountMismatch = errors.New("这台开发机属于另一个账号")
	ErrNotSupported    = errors.New("当前运行模式不支持此操作")
	ErrUnauthorized    = errors.New("凭据无效")
	ErrDevicePending   = errors.New("authorization_pending")
	ErrDeviceExpired   = errors.New("设备码已过期")
	ErrDeviceDenied    = errors.New("access_denied")
	ErrQuota           = errors.New("超出配额")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID       string
	Login    string
	Provider string
}

type DeviceCode

type DeviceCode struct {
	DeviceCode string
	UserCode   string
	AccountID  string
	ExpiresAt  time.Time
	Interval   int
	Approved   bool
}

type Host

type Host struct {
	ID           string
	Name         string
	TokenHash    string // 仅 v1
	Ed25519Pub   []byte // v2 原始 32 字节
	AccountID    string
	NodeID       string
	BundleID     string
	BannedAt     *time.Time
	RegisteredAt int64
	LastSeenAt   int64
}

Host 是一台已登记开发机。

func (*Host) Banned

func (h *Host) Banned() bool

func (*Host) PubHex

func (h *Host) PubHex() string

type Quota

type Quota struct {
	MaxHosts          int
	MaxDevicesPerHost int
	MonthlyBytes      int64
	DailyPushes       int
	HostsUsed         int
	BytesUsed         int64
	PushesToday       int
}

func (Quota) Unlimited

func (q Quota) Unlimited() bool

type Store

type Store interface {
	Lookup(id string) (*Host, bool)
	AuthenticateV1(id, name, tokenHash string, online bool) (*Host, error)
	// AuthenticateV2 校验 v2 开发机。
	//
	// tofu:单租户首次见到即登记。
	// replaceWhenOffline 已废弃:离线也不允许用另一把钥匙抢走坑位。
	// 轮换走 RotateEd25519(须先验证旧钥匙签名)。
	// 多租户必须已经 POST /v2/hosts 登记过,tofu 为 false。
	AuthenticateV2(id, name string, pub []byte, online, tofu, replaceWhenOffline bool) (*Host, error)
	RotateEd25519(id string, pub []byte) error
	RegisterHost(accountID, id, name string, pub []byte, bundleID string) (*Host, error)
	SetNode(id, nodeID string) error
	TouchSeen(id, name string) error
	Ban(id string, banned bool) error
	ListHosts(accountID string) ([]*Host, error)
	Count() int
	Flush() error

	UpsertAccount(provider, providerID, login string) (*Account, error)
	CreateCLIToken(accountID string) (string, error)
	AccountByToken(token string) (*Account, error)
	CreateDeviceCode(userCode, deviceCode string, ttl time.Duration) (*DeviceCode, error)
	LookupDeviceCode(deviceCode string) (*DeviceCode, error)
	LookupUserCode(userCode string) (*DeviceCode, error)
	ApproveDeviceCode(userCode, accountID string) error
	ConsumeDeviceCode(deviceCode string) (*Account, string, error)

	QuotaFor(accountID string) Quota
	SetQuotaDefaults(q Quota)
	AddBytes(accountID string, n int64)
	AddPushes(accountID string, n int)
}

Directories

Path Synopsis
Package file 是单租户存储:一份 hosts.json,没有账号。
Package file 是单租户存储:一份 hosts.json,没有账号。

Jump to

Keyboard shortcuts

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