move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// Package cluster contains Telegram multi-DC setup utilities.
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/exchange"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tdsync"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/dcs"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tgtest"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tgtest/services/config"
|
||||
)
|
||||
|
||||
type setup struct {
|
||||
srv *tgtest.Server
|
||||
dispatch *tgtest.Dispatcher
|
||||
}
|
||||
|
||||
// Cluster is a cluster of multiple servers, representing multiple Telegram datacenters.
|
||||
type Cluster struct {
|
||||
// denotes to use websocket listener
|
||||
web bool
|
||||
|
||||
setups map[int]setup
|
||||
keys []exchange.PublicKey
|
||||
|
||||
// DCs config state.
|
||||
cfg tg.Config
|
||||
cdnCfg tg.CDNConfig
|
||||
domains map[int]string
|
||||
|
||||
// Signal for readiness.
|
||||
ready *tdsync.Ready
|
||||
|
||||
// RPC dispatcher.
|
||||
common *tgtest.Dispatcher
|
||||
|
||||
log *zap.Logger
|
||||
random io.Reader
|
||||
protocol dcs.Protocol
|
||||
}
|
||||
|
||||
// NewCluster creates new server Cluster.
|
||||
func NewCluster(opts Options) *Cluster {
|
||||
opts.setDefaults()
|
||||
|
||||
q := &Cluster{
|
||||
web: opts.Web,
|
||||
setups: map[int]setup{},
|
||||
keys: nil,
|
||||
cfg: opts.Config,
|
||||
cdnCfg: opts.CDNConfig,
|
||||
domains: map[int]string{},
|
||||
ready: tdsync.NewReady(),
|
||||
common: tgtest.NewDispatcher(),
|
||||
log: opts.Logger,
|
||||
random: opts.Random,
|
||||
protocol: opts.Protocol,
|
||||
}
|
||||
config.NewService(&q.cfg, &q.cdnCfg).Register(q.common)
|
||||
q.common.Fallback(q.fallback())
|
||||
|
||||
return q
|
||||
}
|
||||
|
||||
// List returns DCs list.
|
||||
func (c *Cluster) List() dcs.List {
|
||||
return dcs.List{
|
||||
Options: c.cfg.DCOptions,
|
||||
Domains: c.domains,
|
||||
}
|
||||
}
|
||||
|
||||
// Resolver returns dcs.Resolver to use.
|
||||
func (c *Cluster) Resolver() dcs.Resolver {
|
||||
if c.web {
|
||||
return dcs.Websocket(dcs.WebsocketOptions{})
|
||||
}
|
||||
|
||||
return dcs.Plain(dcs.PlainOptions{
|
||||
Protocol: c.protocol,
|
||||
})
|
||||
}
|
||||
|
||||
// Keys returns all servers public keys.
|
||||
func (c *Cluster) Keys() []exchange.PublicKey {
|
||||
return c.keys
|
||||
}
|
||||
|
||||
// Ready returns signal channel to await readiness.
|
||||
func (c *Cluster) Ready() <-chan struct{} {
|
||||
return c.ready.Ready()
|
||||
}
|
||||
Reference in New Issue
Block a user