|
| 1 | +package option |
| 2 | + |
| 3 | +import "github.com/sagernet/sing/common/json/badoption" |
| 4 | + |
| 5 | +// FirebaseTunnelUser identifies a client allowed to connect when this |
| 6 | +// endpoint acts as a server. Name is used as a traffic-accounting label |
| 7 | +// (surfaced via the SSM traffic manager). If PSK is set the server also |
| 8 | +// requires the client's chunks to decrypt successfully before accepting |
| 9 | +// the label. |
| 10 | +type FirebaseTunnelUser struct { |
| 11 | + Name string `json:"name"` |
| 12 | + // PSK authenticates this user and encrypts their relayed payload bytes |
| 13 | + // against a passive reader of the Firebase project. Optional: omit to |
| 14 | + // relay cleartext (anyone who can read the project can see the data). |
| 15 | + PSK string `json:"psk,omitempty"` |
| 16 | +} |
| 17 | + |
| 18 | +// FirebaseTunnelServerConfig holds options that are only meaningful when |
| 19 | +// this endpoint acts as a server (inbound). Its presence in |
| 20 | +// FirebaseTunnelOptions switches the endpoint into server mode; omitting |
| 21 | +// it (nil) selects client (outbound) mode. |
| 22 | +type FirebaseTunnelServerConfig struct { |
| 23 | + Users []FirebaseTunnelUser `json:"users"` |
| 24 | + PollInterval badoption.Duration `json:"poll_interval,omitempty"` |
| 25 | + SessionTimeout badoption.Duration `json:"session_timeout,omitempty"` |
| 26 | + MaxSessions int `json:"max_sessions,omitempty"` |
| 27 | + MaxSessionsPerUser int `json:"max_sessions_per_user,omitempty"` |
| 28 | + // MaxSessionsPerSecondPerUser rate-limits new session creation per user |
| 29 | + // (token bucket). Zero → built-in default (5/s). |
| 30 | + MaxSessionsPerSecondPerUser int `json:"max_sessions_per_second_per_user,omitempty"` |
| 31 | +} |
| 32 | + |
| 33 | +// FirebaseTunnelClientConfig holds options that are only meaningful when |
| 34 | +// this endpoint acts as a client (outbound). |
| 35 | +type FirebaseTunnelClientConfig struct { |
| 36 | + // User is this client's self-reported identity, verified by PSK if set. |
| 37 | + User string `json:"user"` |
| 38 | + PSK string `json:"psk,omitempty"` |
| 39 | + BatchInterval badoption.Duration `json:"batch_interval,omitempty"` |
| 40 | + BatchMaxBytes int `json:"batch_max_bytes,omitempty"` |
| 41 | + ActivationTimeout badoption.Duration `json:"activation_timeout,omitempty"` |
| 42 | +} |
| 43 | + |
| 44 | +// FirebaseTunnelOptions configures a Firebase Realtime Database relay tunnel |
| 45 | +// (adapted from github.com/Hiddify2/Firebase-Tunnel). |
| 46 | +// |
| 47 | +// Role is determined by which sub-config is present: |
| 48 | +// - Server != nil → server (inbound) mode: listens for pending sessions |
| 49 | +// written to the Firebase project and routes them through sing-box. |
| 50 | +// - Client != nil → client (outbound) mode: dials by writing a session |
| 51 | +// request to Firebase and waiting for the server to activate it. |
| 52 | +// |
| 53 | +// Exactly one of Server or Client must be set. |
| 54 | +// |
| 55 | +// firebase_secret is the legacy Firebase Database Secret, appended as |
| 56 | +// ?auth=<secret> to every REST call. Anyone holding it has full read/write |
| 57 | +// access to the entire Firebase project — prefer firebase_auth_token for |
| 58 | +// anything beyond personal/test use. |
| 59 | +type FirebaseTunnelOptions struct { |
| 60 | + FirebaseURLs badoption.Listable[string] `json:"firebase_urls"` |
| 61 | + FirebaseSecret string `json:"firebase_secret,omitempty"` |
| 62 | + FirebaseAuthToken string `json:"firebase_auth_token,omitempty"` |
| 63 | + RetryLimit uint32 `json:"retry_limit,omitempty"` |
| 64 | + |
| 65 | + // Exactly one must be non-nil. |
| 66 | + Server *FirebaseTunnelServerConfig `json:"server,omitempty"` |
| 67 | + Client *FirebaseTunnelClientConfig `json:"client,omitempty"` |
| 68 | +} |
0 commit comments