peercache

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package peercache provides a file-backed implementation of peers.Storage.

StringSession/FileStorage sessions keep no entity cache, so resolved access-hashes would be lost between CLI invocations. This storage persists them as JSON in the session directory, keyed per account, so peer resolution is cheap and survives restarts.

Index

Constants

View Source
const (
	KindUser    = "user"
	KindChat    = "chat"
	KindChannel = "channel"
)

Peer kinds returned by Kind, matching the type names used in CLI output.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage is a JSON-file-backed peers.Storage.

func Open

func Open(path string) (*Storage, error)

Open loads the cache at path, creating an empty one if it does not exist.

func (*Storage) Find

func (s *Storage) Find(_ context.Context, key peers.Key) (peers.Value, bool, error)

Find implements peers.Storage.

func (*Storage) FindPhone

func (s *Storage) FindPhone(_ context.Context, phone string) (peers.Key, peers.Value, bool, error)

FindPhone implements peers.Storage.

func (*Storage) GetContactsHash

func (s *Storage) GetContactsHash(_ context.Context) (int64, error)

GetContactsHash implements peers.Storage.

func (*Storage) Kind added in v0.8.0

func (s *Storage) Kind(id int64) (string, bool)

Kind reports the cached peer kind ("user", "chat" or "channel") for a numeric id, if the peer has been seen before (e.g. via `tg chats list`). Users and channels are checked before chats so a populated access hash wins.

gotd's peers.Storage keys entries as "<prefix>:<id>"; the prefixes are unexported there (telegram/peers/storage.go), so we mirror them here.

func (*Storage) Save

func (s *Storage) Save(_ context.Context, key peers.Key, value peers.Value) error

Save implements peers.Storage.

func (*Storage) SaveContactsHash

func (s *Storage) SaveContactsHash(_ context.Context, hash int64) error

SaveContactsHash implements peers.Storage.

func (*Storage) SavePhone

func (s *Storage) SavePhone(_ context.Context, phone string, key peers.Key) error

SavePhone implements peers.Storage.

Jump to

Keyboard shortcuts

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