mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-04-14 04:38:28 +10:00
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
//go:build with_cloudflare_tunnel
|
|
|
|
package cloudflare
|
|
|
|
import "github.com/google/uuid"
|
|
|
|
// Credentials contains all info needed to run a tunnel.
|
|
type Credentials struct {
|
|
AccountTag string `json:"AccountTag"`
|
|
TunnelSecret []byte `json:"TunnelSecret"`
|
|
TunnelID uuid.UUID `json:"TunnelID"`
|
|
Endpoint string `json:"Endpoint,omitempty"`
|
|
}
|
|
|
|
// TunnelToken is the compact token format used in the --token flag.
|
|
// Field names match cloudflared's JSON encoding.
|
|
type TunnelToken struct {
|
|
AccountTag string `json:"a"`
|
|
TunnelSecret []byte `json:"s"`
|
|
TunnelID uuid.UUID `json:"t"`
|
|
Endpoint string `json:"e,omitempty"`
|
|
}
|
|
|
|
func (t TunnelToken) ToCredentials() Credentials {
|
|
return Credentials{
|
|
AccountTag: t.AccountTag,
|
|
TunnelSecret: t.TunnelSecret,
|
|
TunnelID: t.TunnelID,
|
|
Endpoint: t.Endpoint,
|
|
}
|
|
}
|
|
|
|
// TunnelAuth is the authentication data sent during tunnel registration.
|
|
type TunnelAuth struct {
|
|
AccountTag string
|
|
TunnelSecret []byte
|
|
}
|
|
|
|
func (c *Credentials) Auth() TunnelAuth {
|
|
return TunnelAuth{
|
|
AccountTag: c.AccountTag,
|
|
TunnelSecret: c.TunnelSecret,
|
|
}
|
|
}
|