Documentation
¶
Overview ¶
Package fcmrecv registers a process as a Firebase Cloud Messaging (FCM) web-push client and receives FCM data messages over Google's MCS protocol. It is the device-side receiver, not the admin/send SDK.
Index ¶
- Constants
- type Client
- type Config
- type ConfigSnapshot
- type CredentialStore
- type Credentials
- type FCMRecord
- type FileStore
- type GCMIdentity
- type InstallationRecord
- type KeyMaterial
- type Message
- type Option
- func OnCredentialsUpdated(fn func(*Credentials)) Option
- func OnMessage(fn func(Message) error) Option
- func WithAbortOnSequentialErrors(n int) Option
- func WithAckTimeout(d time.Duration) Option
- func WithBackoffBase(d time.Duration) Option
- func WithCallbackContext(v any) Option
- func WithConnectionRetry(n int) Option
- func WithCredentialStore(s CredentialStore) Option
- func WithHTTPTimeout(d time.Duration) Option
- func WithHeartbeat(server, client time.Duration) Option
- func WithLogWarnLimit(n int) Option
- func WithLogger(l *slog.Logger) Option
- func WithMonitorInterval(d time.Duration) Option
- func WithResetInterval(d time.Duration) Option
- func WithSeededPersistentIDs(ids []string) Option
- func WithSelectiveAcks(b bool) Option
- func WithVerboseDebug(b bool) Option
- type RunState
- type Tunables
Constants ¶
View Source
const ( GCMServerKey = "BDOU99-h67HcA6JeFXHbSNMu7e2yNNu3RzoMj8TM4W88jITfq7ZmPvIM1Iv-4_l2LxQcYwhqby2xGpWwzjfAnG4" ChromeVersion = "94.0.4606.51" SDKVersion = "w:0.6.6" AuthVersion = "FIS_v2" GCMRegisterApp = "org.chromium.linux" DefaultBundleID = "receiver.push.com" MCSHost = "mtalk.google.com" MCSPort = "5228" MCSVersion = 41 // raw byte; server also accepts legacy 38 HostCheckin = "https://android.clients.google.com/checkin" HostRegister3 = "https://android.clients.google.com/c2dm/register3" HostFIS = "https://firebaseinstallations.googleapis.com/v1/projects/%s/installations" HostFCMReg = "https://fcmregistrations.googleapis.com/v1/projects/%s/registrations" )
View Source
const ( TagHeartbeatPing = 0 TagHeartbeatAck = 1 TagLoginRequest = 2 TagLoginResponse = 3 TagClose = 4 TagIqStanza = 7 TagDataMessageStanza = 8 TagStreamErrorStanza = 10 )
MCS stanza tags (ordinal, not proto field numbers)
View Source
const ( SelectiveAckExtensionID = 12 StreamAckExtensionID = 13 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Listen ¶
Listen connects, logs in, and delivers messages until ctx is cancelled, reconnecting with quadratic backoff on a reset up to the retry limit.
func (*Client) Register ¶
func (c *Client) Register(ctx context.Context) (*Credentials, error)
Register loads or mints credentials. With a valid stored install token it does a check-in only and reuses everything; near expiry it tries an install-token refresh and otherwise falls back to a full re-registration.
type ConfigSnapshot ¶
type CredentialStore ¶
type CredentialStore interface {
Load(ctx context.Context) (*Credentials, error)
Save(ctx context.Context, c *Credentials) error
}
type Credentials ¶
type Credentials struct {
Keys KeyMaterial `json:"keys"`
GCM GCMIdentity `json:"gcm"`
FCM FCMRecord `json:"fcm"`
Config ConfigSnapshot `json:"config"`
PersistentIDs []string `json:"persistent_ids,omitempty"`
}
func (Credentials) FCMToken ¶
func (c Credentials) FCMToken() string
func (Credentials) LogValue ¶
func (c Credentials) LogValue() slog.Value
type FCMRecord ¶
type FCMRecord struct {
Registration map[string]any `json:"registration"`
Installation InstallationRecord `json:"installation"`
}
type GCMIdentity ¶
type GCMIdentity struct {
Token string `json:"token"`
AppID string `json:"app_id"`
AndroidID uint64 `json:"android_id"`
SecurityToken uint64 `json:"security_token"`
}
func (GCMIdentity) LogValue ¶
func (g GCMIdentity) LogValue() slog.Value
type InstallationRecord ¶
type InstallationRecord struct {
Token string `json:"token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
FID string `json:"fid"`
CreatedAt int64 `json:"created_at"`
}
func (InstallationRecord) LogValue ¶
func (r InstallationRecord) LogValue() slog.Value
type KeyMaterial ¶
type KeyMaterial struct {
Public string `json:"public"`
Private string `json:"private"`
Secret string `json:"secret"`
}
func (KeyMaterial) LogValue ¶
func (k KeyMaterial) LogValue() slog.Value
type Option ¶
type Option func(*Client)
func OnCredentialsUpdated ¶
func OnCredentialsUpdated(fn func(*Credentials)) Option
func WithAckTimeout ¶
func WithBackoffBase ¶
func WithCallbackContext ¶
func WithConnectionRetry ¶
func WithCredentialStore ¶
func WithCredentialStore(s CredentialStore) Option
func WithHTTPTimeout ¶
func WithHeartbeat ¶
func WithLogWarnLimit ¶
func WithLogger ¶
func WithMonitorInterval ¶
func WithResetInterval ¶
func WithSeededPersistentIDs ¶
func WithSelectiveAcks ¶
func WithVerboseDebug ¶
type Tunables ¶
type Tunables struct {
ServerHeartbeat time.Duration
ClientHeartbeat time.Duration
HeartbeatAckTO time.Duration
SelectiveAcks bool
ConnectionRetry int
BackoffBase time.Duration
ResetInterval time.Duration
MonitorInterval time.Duration
AbortOnSeqErrors int
LogWarnLimit int
VerboseDebug bool
HTTPTimeout time.Duration
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
listen
command
|
|
|
internal
|
|
|
checkin
Package checkin performs the GCM device check-in.
|
Package checkin performs the GCM device check-in. |
|
ece
Package ece decrypts Web Push payloads.
|
Package ece decrypts Web Push payloads. |
|
keys
Package keys generates and reloads the P-256 ECDH key material and the 16-byte Web Push auth secret.
|
Package keys generates and reloads the P-256 ECDH key material and the 16-byte Web Push auth secret. |
|
mcs
Package mcs implements the MCS framing, login, heartbeat and reconnect loop.
|
Package mcs implements the MCS framing, login, heartbeat and reconnect loop. |
|
pb
Package pb holds the generated MCS / GCM check-in protobuf bindings.
|
Package pb holds the generated MCS / GCM check-in protobuf bindings. |
|
register
Package register implements GCM register, Firebase Installations, and FCM web-push registration.
|
Package register implements GCM register, Firebase Installations, and FCM web-push registration. |
|
scripts
|
|
|
gohelper
command
gohelper is a thin stdin-to-stdout shim used by crossvalidate.py.
|
gohelper is a thin stdin-to-stdout shim used by crossvalidate.py. |
Click to show internal directories.
Click to hide internal directories.