| 1 | package types |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "fmt" |
| 6 | |
| 7 | "github.com/pelletier/go-toml/v2" |
| 8 | |
| 9 | portaltunnel "github.com/gosuda/portal-tunnel/v2" |
| 10 | ) |
| 11 | |
| 12 | const ( |
| 13 | HeaderAccessToken = "X-Portal-Access-Token" |
| 14 | HeaderXPayment = "X-PAYMENT" |
| 15 | HeaderPaymentSignature = "PAYMENT-SIGNATURE" |
| 16 | HeaderPaymentRequired = "PAYMENT-REQUIRED" |
| 17 | HeaderXPaymentRequired = "X-PAYMENT-REQUIRED" |
| 18 | HeaderPaymentResponse = "PAYMENT-RESPONSE" |
| 19 | HeaderXPaymentResponse = "X-PAYMENT-RESPONSE" |
| 20 | MarkerKeepalive = byte(0x00) |
| 21 | MarkerRawStart = byte(0x01) |
| 22 | MarkerTLSStart = byte(0x02) |
| 23 | ) |
| 24 | |
| 25 | var ( |
| 26 | ReleaseVersion string |
| 27 | SDKVersion string |
| 28 | DiscoveryVersion string |
| 29 | OfficialReleaseBaseURL string |
| 30 | BootstrapRelays []string |
| 31 | ) |
| 32 | |
| 33 | func init() { |
| 34 | var m struct { |
| 35 | Release struct { |
| 36 | Version string `toml:"version"` |
| 37 | BaseURL string `toml:"base_url"` |
| 38 | } `toml:"release"` |
| 39 | Protocol struct { |
| 40 | Tunnel string `toml:"tunnel"` |
| 41 | Discovery string `toml:"discovery"` |
| 42 | } `toml:"protocol"` |
| 43 | } |
| 44 | if err := toml.Unmarshal(portaltunnel.ConfigTOML, &m); err != nil { |
| 45 | panic(fmt.Errorf("unmarshal config TOML: %w", err)) |
| 46 | } |
| 47 | var registry struct { |
| 48 | Relays []string `json:"relays"` |
| 49 | } |
| 50 | if err := json.Unmarshal(portaltunnel.RegistryJSON, ®istry); err != nil { |
| 51 | panic(fmt.Errorf("unmarshal registry JSON: %w", err)) |
| 52 | } |
| 53 | ReleaseVersion = m.Release.Version |
| 54 | OfficialReleaseBaseURL = m.Release.BaseURL |
| 55 | SDKVersion = m.Protocol.Tunnel |
| 56 | DiscoveryVersion = m.Protocol.Discovery |
| 57 | BootstrapRelays = registry.Relays |
| 58 | } |