Documentation
¶
Overview ¶
Package network is the facade of the network module: admin-side server and node management, the node-facing server API and the edge client manifest. See docs/design/adr-001-modular-monolith.md.
Index ¶
- Variables
- func NewRepoBuilder(rds *redis.Client) repository.NetworkBuilder
- type Access
- type Accounts
- type Deps
- type MultiplierManager
- type MultiplierPeriod
- type RequestMeta
- type ResponseMeta
- type Service
- type Snapshot
- type Statistics
- type Store
- type SubscriptionReader
- type TrafficAggregator
- type TrafficAggregatorAppStore
- type TrafficAggregatorDeps
- type TrafficAggregatorStore
- type UserTraffic
Constants ¶
This section is empty.
Variables ¶
var ErrManifestNotFound = edge.ErrManifestNotFound
ErrManifestNotFound re-exports the edge subdomain's not-found sentinel for the transport handler's status mapping.
Functions ¶
func NewRepoBuilder ¶ added in v1.15.2
func NewRepoBuilder(rds *redis.Client) repository.NetworkBuilder
NewRepoBuilder exports the module-owned repository implementations for store assembly. The node cache retrier is a background singleton that survives per-transaction rebuilds, so it lives in this closure (ADR-001 step-6 preparation).
Types ¶
type Access ¶ added in v1.21.0
type Access interface {
// ListEnabledNodesByScope lists the enabled nodes, with their servers,
// that a plan scope selects (an explicit node id or any of the tags) in
// sort order. An empty scope selects every enabled node.
ListEnabledNodesByScope(ctx context.Context, nodeIDs []int64, tags []string) ([]*node.Node, error)
// ListEnabledNodes lists up to limit enabled nodes, with their servers,
// in sort order.
ListEnabledNodes(ctx context.Context, limit int) ([]*node.Node, error)
// SubscriptionTrafficLogs pages the traffic records of a user's
// subscription and counts them.
SubscriptionTrafficLogs(ctx context.Context, userID, subscribeID int64, page, size int) ([]*traffic.TrafficLog, int64, error)
// ClearServerCachesByNodeScope drops the node-facing caches (user lists
// and configs) of every server carrying a node the scope selects, an
// explicit node id or any of the tags, enabled or not. An empty scope
// clears nothing.
ClearServerCachesByNodeScope(ctx context.Context, nodeIDs []int64, tags []string) error
}
Access is the part of the facade the other modules compose (ADR-001 rule 4): entity-typed reads they assemble in memory instead of reading the network tables, and the invalidation of the node-facing caches.
type Accounts ¶ added in v1.21.0
type Accounts interface {
edge.AccountStateReader
serverapi.AccountReader
}
Accounts is the module's port onto the identity domain: the account gate of the edge manifest and the enabled owners of the node user lists. The composition root passes the identity facade.
type Deps ¶
type Deps struct {
Store Store
TrafficUsage subscription.TrafficUsage
// Subscription is the subscription read port (the subscription facade).
Subscription SubscriptionReader
Redis *redis.Client
// Config snapshots the runtime-mutable settings per request.
Config func() Snapshot
// Multiplier returns the node traffic multiplier in effect at the given
// time; nil means no multiplier is configured.
Multiplier func(at time.Time) float32
// Accounts reads the subscription owners' account state from the
// identity domain.
Accounts Accounts
// Logs is the platform's system log, where the daily traffic statistics
// are recorded.
Logs repository.LogRepo
}
Deps declares everything the module needs; the composition root (internal/app) provides them.
type MultiplierManager ¶ added in v1.20.2
type MultiplierManager = multiplier.Manager
MultiplierManager and MultiplierPeriod expose the network-owned runtime configuration to application assembly without exporting its implementation.
func NewMultiplierManager ¶ added in v1.20.2
func NewMultiplierManager(periods []MultiplierPeriod) *MultiplierManager
NewMultiplierManager returns a manager applying the multipliers of periods.
type MultiplierPeriod ¶ added in v1.20.2
type MultiplierPeriod = multiplier.TimePeriod
type RequestMeta ¶
type RequestMeta = serverapi.RequestMeta
RequestMeta and ResponseMeta re-export the server API's conditional-request negotiation types for the transport handlers.
type ResponseMeta ¶
type ResponseMeta = serverapi.ResponseMeta
RequestMeta and ResponseMeta re-export the server API's conditional-request negotiation types for the transport handlers.
type Service ¶
type Service interface {
// Admin-side server and node management.
CreateServer(ctx context.Context, req *dto.CreateServerRequest) error
UpdateServer(ctx context.Context, req *dto.UpdateServerRequest) error
DeleteServer(ctx context.Context, req *dto.DeleteServerRequest) error
FilterServerList(ctx context.Context, req *dto.FilterServerListRequest) (*dto.FilterServerListResponse, error)
ResetSortWithServer(ctx context.Context, req *dto.ResetSortRequest) error
GetServerProtocols(ctx context.Context, req *dto.GetServerProtocolsRequest) (*dto.GetServerProtocolsResponse, error)
GetServerNodeConfig(ctx context.Context, req *dto.GetServerNodeConfigRequest) (*dto.GetServerNodeConfigResponse, error)
UpdateServerNodeConfig(ctx context.Context, req *dto.UpdateServerNodeConfigRequest) error
CreateNode(ctx context.Context, req *dto.CreateNodeRequest) error
UpdateNode(ctx context.Context, req *dto.UpdateNodeRequest) error
DeleteNode(ctx context.Context, req *dto.DeleteNodeRequest) error
FilterNodeList(ctx context.Context, req *dto.FilterNodeListRequest) (*dto.FilterNodeListResponse, error)
ToggleNodeStatus(ctx context.Context, req *dto.ToggleNodeStatusRequest) error
ResetSortWithNode(ctx context.Context, req *dto.ResetSortRequest) error
QueryNodeTag(ctx context.Context) (*dto.QueryNodeTagResponse, error)
// Statistics serves the platform's reads of the node and traffic
// figures.
Statistics
// The node-facing server API. The ETag negotiation flows through
// RequestMeta/ResponseMeta; node authentication stays in the handlers.
GetServerConfig(ctx context.Context, req *dto.GetServerConfigRequest, meta RequestMeta) (*dto.GetServerConfigResponse, ResponseMeta, error)
GetServerUserList(ctx context.Context, req *dto.GetServerUserListRequest, meta RequestMeta) (*dto.GetServerUserListResponse, ResponseMeta, error)
QueryServerProtocolConfig(ctx context.Context, req *dto.QueryServerConfigRequest) (*dto.QueryServerConfigResponse, error)
PushOnlineUsers(ctx context.Context, req *dto.OnlineUsersRequest) error
ServerPushStatus(ctx context.Context, req *dto.ServerPushStatusRequest) error
ServerPushUserTraffic(ctx context.Context, req *dto.ServerPushUserTrafficRequest) error
// EdgeManifest serves the token-authenticated edge client manifest.
EdgeManifest(ctx context.Context, token string) (*dto.EdgeManifestResponse, error)
// RecordDailyTrafficStatistics records the previous day's traffic
// statistics in the system log, once per day however often it runs.
RecordDailyTrafficStatistics(ctx context.Context) error
// PruneTrafficLogs deletes the raw traffic log older than before and
// returns how many rows it deleted.
PruneTrafficLogs(ctx context.Context, before time.Time) (int64, error)
// Access serves the other modules' reads and cache invalidation (see
// access.go).
Access
}
Service is the only surface other code may depend on; the implementation lives under internal/ where the compiler seals it off.
type Snapshot ¶
type Snapshot struct {
Node config.NodeConfig
Subscribe config.SubscribeConfig
}
Snapshot is the per-request view of the runtime-mutable settings the network flows consume.
type Statistics ¶ added in v1.21.0
type Statistics interface {
// CountEnabledNodes counts the enabled nodes.
CountEnabledNodes(ctx context.Context) (int64, error)
// ListServerAddresses returns the address of every server.
ListServerAddresses(ctx context.Context) ([]string, error)
// ListEnabledNodeProtocols returns the protocol of every enabled node.
ListEnabledNodeProtocols(ctx context.Context) ([]string, error)
// CountServersByReportStatus counts the servers that reported after
// cutoff (online) and the others (offline).
CountServersByReportStatus(ctx context.Context, cutoff time.Time) (online, offline int64, err error)
// CountOnlineUsers counts the subscriptions online on any server.
CountOnlineUsers(ctx context.Context) (int64, error)
// FindServers returns the servers among ids that exist.
FindServers(ctx context.Context, ids []int64) ([]*node.Server, error)
// TrafficSummary sums the traffic logged in [start, end).
TrafficSummary(ctx context.Context, start, end time.Time) (*traffic.TotalTraffic, error)
// TopServersTrafficByDay and TopUsersTrafficByDay rank the servers and
// the subscriptions by the traffic of date's day, at most limit of them.
TopServersTrafficByDay(ctx context.Context, date time.Time, limit int) ([]traffic.ServerTrafficRanking, error)
TopUsersTrafficByDay(ctx context.Context, date time.Time, limit int) ([]traffic.UserTrafficRanking, error)
// ServerTrafficRanking and UserTrafficRanking rank every server and every
// subscription by its traffic in [start, end).
ServerTrafficRanking(ctx context.Context, start, end time.Time) ([]traffic.ServerTrafficRanking, error)
UserTrafficRanking(ctx context.Context, start, end time.Time) ([]traffic.UserTrafficRanking, error)
// TrafficLogDetails pages the traffic log entries filter selects.
TrafficLogDetails(ctx context.Context, filter *traffic.TrafficLogDetailsFilter) ([]*traffic.TrafficLog, int64, error)
}
Statistics is the part of the facade the platform's dashboards, audit views and public statistics read network's figures through, instead of network's repositories (ADR-001 rule 4). The reads return the repositories' results and errors as they are.
type Store ¶ added in v1.20.3
type Store interface {
adminserver.Store
edge.Store
// TrafficLog serves the traffic-log reads of the other modules.
TrafficLog() repository.TrafficRepo
}
Store is the persistence capability required by this package. It excludes unrelated repositories and application-wide transactions.
type SubscriptionReader ¶ added in v1.21.0
type SubscriptionReader interface {
adminserver.OnlineSubscriptionReader
serverapi.SubscriptionReader
edge.SubscriptionReader
}
SubscriptionReader is the subscription module's read surface the network flows compose (ADR-001 rule 4); the subscription facade satisfies it.
type TrafficAggregator ¶ added in v1.20.3
type TrafficAggregator = trafficagg.Aggregator
TrafficAggregator is the network-owned pipeline shared by node reports and scheduled flush tasks. Queue adapters enter through this facade.
func NewTrafficAggregator ¶ added in v1.20.3
func NewTrafficAggregator(deps TrafficAggregatorDeps) *TrafficAggregator
NewTrafficAggregator returns the traffic pipeline over deps.
type TrafficAggregatorAppStore ¶ added in v1.21.0
type TrafficAggregatorAppStore = trafficagg.AppStore
TrafficAggregatorStore is the pipeline's network persistence, and TrafficAggregatorAppStore the part of the application store that NewTrafficAggregatorStore adapts to it.
type TrafficAggregatorDeps ¶ added in v1.20.3
type TrafficAggregatorDeps = trafficagg.Deps
type TrafficAggregatorStore ¶ added in v1.21.0
type TrafficAggregatorStore = trafficagg.Store
TrafficAggregatorStore is the pipeline's network persistence, and TrafficAggregatorAppStore the part of the application store that NewTrafficAggregatorStore adapts to it.
func NewTrafficAggregatorStore ¶ added in v1.21.0
func NewTrafficAggregatorStore(store TrafficAggregatorAppStore) TrafficAggregatorStore
NewTrafficAggregatorStore adapts the application store to the pipeline's network persistence.
type UserTraffic ¶ added in v1.20.3
type UserTraffic = trafficagg.UserTraffic
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dto is the network module's contract: the requests and responses of the admin server and node management, the node-facing server API and the edge manifest.
|
Package dto is the network module's contract: the requests and responses of the admin server and node management, the node-facing server API and the edge manifest. |
|
entity
|
|
|
node
Package node holds the network module's server and node entities: the servers with the protocols they offer, stored as JSON and normalized for storage and distribution, the nodes that expose them, the per-server node configuration overrides, and the Redis keys of the node-facing caches.
|
Package node holds the network module's server and node entities: the servers with the protocols they offer, stored as JSON and normalized for storage and distribution, the nodes that expose them, the per-server node configuration overrides, and the Redis keys of the node-facing caches. |
|
traffic
Package traffic holds the network module's traffic log entity, the per-server and per-subscription usage rows the traffic pipeline writes, and the aggregates read from it.
|
Package traffic holds the network module's traffic log entity, the per-server and per-subscription usage rows the traffic pipeline writes, and the aggregates read from it. |
|
internal
|
|
|
adminserver
Package adminserver is the network module's admin-side management of the servers and nodes: their creation, updates and removal, their sort order, the protocols a server offers and its node configuration overrides, and the node-facing caches these changes invalidate.
|
Package adminserver is the network module's admin-side management of the servers and nodes: their creation, updates and removal, their sort order, the protocols a server offers and its node configuration overrides, and the node-facing caches these changes invalidate. |
|
edge
Package edge is the network module's edge subdomain: the manifest a trusted edge-subscribe Worker fetches for a subscription token, listing the subscription's state and the proxies of its plan's nodes.
|
Package edge is the network module's edge subdomain: the manifest a trusted edge-subscribe Worker fetches for a subscription token, listing the subscription's state and the proxies of its plan's nodes. |
|
edgeauth
Package edgeauth authenticates Cloudflare edge-subscribe Workers.
|
Package edgeauth authenticates Cloudflare edge-subscribe Workers. |
|
geolocation
Package geolocation locates a server address through public IP geolocation services, filling in a server's country and city.
|
Package geolocation locates a server address through public IP geolocation services, filling in a server's country and city. |
|
multiplier
Package multiplier applies the node traffic multipliers an administrator sets for times of day.
|
Package multiplier applies the node traffic multipliers an administrator sets for times of day. |
|
nodeconfig
Package nodeconfig resolves the node configuration a server's nodes run with: the global node settings and the server's override of them, whose fields each either inherit (NULL) or replace a global value.
|
Package nodeconfig resolves the node configuration a server's nodes run with: the global node settings and the server's override of them, whose fields each either inherit (NULL) or replace a global value. |
|
protocolmap
Package protocolmap is the one mapping between a server protocol as stored (node.Protocol, the servers.protocols JSON) and as the API shows it (dto.Protocol).
|
Package protocolmap is the one mapping between a server protocol as stored (node.Protocol, the servers.protocols JSON) and as the API shows it (dto.Protocol). |
|
repo
Package repo holds the network module's repository implementations: the servers and nodes with their Redis caches, and the traffic log.
|
Package repo holds the network module's repository implementations: the servers and nodes with their Redis caches, and the traffic log. |
|
serverapi
Package serverapi is the network module's node-facing server API: the configuration and user lists the nodes pull, cached per server and negotiated with ETags, and the status, online-user and traffic reports they push.
|
Package serverapi is the network module's node-facing server API: the configuration and user lists the nodes pull, cached per server and negotiated with ETags, and the status, online-user and traffic reports they push. |
|
trafficagg
Package trafficagg is the network module's traffic pipeline.
|
Package trafficagg is the network module's traffic pipeline. |
|
trafficstat
Package trafficstat keeps the records derived from the raw traffic log: the daily traffic statistics the dashboard and the admin log views read, and the retention of the raw log itself.
|
Package trafficstat keeps the records derived from the raw traffic log: the daily traffic statistics the dashboard and the admin log views read, and the retention of the raw log itself. |
|
transport
|
|
|
http/admin/server
Package server holds the admin HTTP handlers of the server and node management.
|
Package server holds the admin HTTP handlers of the server and node management. |
|
http/edge
Package edge holds the HTTP handler of the edge manifest, authenticated by the edge credential.
|
Package edge holds the HTTP handler of the edge manifest, authenticated by the edge credential. |
|
http/server
Package server holds the HTTP handlers of the node-facing server API, authenticated by the node secret and answering in JSON or Protobuf.
|
Package server holds the HTTP handlers of the node-facing server API, authenticated by the node secret and answering in JSON or Protobuf. |