hub

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: 10 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 hub 负责把开发机与手机接起来,并在两者之间原样转发密文帧。

Index

Constants

View Source
const ChannelIDLen = protocol.ChannelIDLen

Variables

View Source
var (
	ErrHostOffline   = errors.New("开发机当前不在线")
	ErrFrameTooShort = protocol.ErrFrameTooShort
	ErrTooManyPeers  = errors.New("这台开发机连接的设备过多")
	ErrQuota         = errors.New("超出配额")
	ErrBadGeneration = errors.New("注册代次已失效")
	ErrAttachPrimary = errors.New("不能把主连接当附着通道")
)

Functions

func ChannelHex

func ChannelHex(id [ChannelIDLen]byte) string

Types

type ByteRecorder

type ByteRecorder func(accountID string, n int64)

type Host

type Host struct {
	ID         string
	Name       string
	AccountID  string
	BundleID   string
	Version    byte
	MaxPeers   int
	NodeID     string
	Generation uint64
	Since      time.Time
	// contains filtered or unexported fields
}

type Hub

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

func New

func New(push PushSender) *Hub

func (*Hub) AccountOnline

func (h *Hub) AccountOnline(accountID string) int

func (*Hub) AttachDevice

func (h *Hub) AttachDevice(hostID string, sink Sink) ([ChannelIDLen]byte, error)

func (*Hub) AttachDeviceLane

func (h *Hub) AttachDeviceLane(hostID, lane string, sink Sink) ([ChannelIDLen]byte, error)

func (*Hub) AttachHostLane

func (h *Hub) AttachHostLane(id string, generation uint64, lane string, sink Sink) (*Host, uint64, error)

AttachHostLane binds an authenticated extra socket to an existing registration generation. It never replaces the primary registration. The returned attachID must be passed to DetachHostLane so a deferred cleanup from an older socket cannot close its replacement.

func (*Hub) DetachDevice

func (h *Hub) DetachDevice(host *Host, id [ChannelIDLen]byte)

func (*Hub) DetachHostLane

func (h *Hub) DetachHostLane(id, lane string, generation, attachID uint64)

DetachHostLane drops an extra lane without touching the primary registration. attachID must match the current lane owner; stale deferred cleanups are no-ops.

func (*Hub) FromDevice

func (h *Hub) FromDevice(host *Host, id [ChannelIDLen]byte, frame []byte) error

func (*Hub) FromHost

func (h *Hub) FromHost(host *Host, frame []byte) error

func (*Hub) FromHostLane

func (h *Hub) FromHostLane(host *Host, lane string, frame []byte) error

func (*Hub) HostCount

func (h *Hub) HostCount() int

func (*Hub) NodeID

func (h *Hub) NodeID() string

func (*Hub) Online

func (h *Hub) Online(id string) (*Host, bool)

func (*Hub) RegisterHost

func (h *Hub) RegisterHost(id, name, accountID, bundleID string, version byte, maxPeers int, sink Sink) *Host

func (*Hub) SetByteRecorder

func (h *Hub) SetByteRecorder(fn ByteRecorder)

func (*Hub) SetNodeID

func (h *Hub) SetNodeID(nodeID string)

func (*Hub) UnregisterHost

func (h *Hub) UnregisterHost(host *Host)

type PushSender

type PushSender interface {
	Send(token, env, hostID, bundleID string, payload []byte) (push.Result, error)
}

type Sink

type Sink interface {
	Send(frame []byte) error
	Close()
}

Jump to

Keyboard shortcuts

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