Documentation
¶
Overview ¶
Package amp implements an AMP client for communicating with an AMP broker.
Index ¶
- func NewAMPClientConn(conn net.Conn, brokerURL, cacheURL *url.URL, front string) (net.Conn, error)
- func NewCryptClientConn(conn net.Conn, serverPublicKey *rsa.PublicKey) (*cryptClientConn, error)
- type AMPRequest
- type Broker
- type BrokerResponse
- type Client
- type ClientRequest
- type Config
- type HTTPResponse
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAMPClientConn ¶
NewAMPClientConn creates a new AMP client connection that implements net.Conn. This connection is not encrypted!
func NewCryptClientConn ¶
NewCryptClientConn creates a new cryptConn that implements net.Conn. This connection is encrypted using a hybrid encryption scheme: a symmetric key is generated for encrypting the data with ChaCha20-Poly1305, and this key is then encrypted with the server's RSA public key. This connector should be used to wrap the ampClientConn to provide encryption.
Types ¶
type AMPRequest ¶
type AMPRequest struct {
ClientRequestEncoded string `json:"p"`
Key string `json:"k"`
Nonce string `json:"n"`
ClientRequest ClientRequest `json:"-"`
// contains filtered or unexported fields
}
type BrokerResponse ¶
BrokerResponse is a struct that represents an HTTP response.
type Client ¶
type Client interface {
Exchange([]byte) (io.ReadCloser, error)
RoundTripper() (http.RoundTripper, error)
}
func NewClient ¶
func NewClient(brokerURL, cacheURL *url.URL, fronts []string, transport http.RoundTripper, serverPublicKey *rsa.PublicKey, dialer dialFunc) (Client, error)
NewClient creates a new AMP client that can communicate with an AMP broker. If cacheURL is non-nil, the client will use the AMP cache at that URL. If fronts is non-empty, the client will use domain fronting by randomly selecting one of the provided front domains. transport is a optional parameter since it's only used by the Exchange method (for AMP cache support but be aware! Exchange func doesn't encrypt your data!). The server public key must be provided for the RoundTripper method to work. The dialer parameter is optional and can be nil, in which case the default net.Dialer will be used.
func NewClientWithOptions ¶
NewClientWithOptions builds a new amp client with the provided options. It supports options for retrieving the latest configuration given a poll interval, http client and config url address until context is canceled. If the config storage path option is provided and the file exists, the client will load the config and use it; the config updater will also store the latest changes in the provided path.
type ClientRequest ¶
type ClientRequest struct {
Method string `json:"method"`
Host string `json:"host"`
URL string `json:"url,omitempty"`
Body []byte `json:"body"`
Headers http.Header `json:"headers"`
}
ClientRequest is a struct that represents an HTTP request so it can be encoded into JSON, encrypted with the RSA public key by the client and decryptod/decoded by the broker
type Config ¶
type Config struct {
BrokerURL string `yaml:"brokerURL"`
CacheURL string `yaml:"cacheURL"`
Fronts []string `yaml:"fronts"`
PublicKey string `yaml:"publicKey"`
}
Config contains the parameters required for sending requests with the amp client
type HTTPResponse ¶
type Option ¶
type Option func(*client) error
Option is a function type used to configure the amp client instance.
func WithConfig ¶
WithConfig set the initial configuration for the amp client
func WithConfigStoragePath ¶
WithConfigStoragePath sets the filepath to store the retrieved config locally.
func WithConfigURL ¶
WithConfigURL sets the URL to retrieve the latest configuration
func WithDialer ¶
func WithDialer(dial dialFunc) Option
WithDialer sets the network dialer function used for creating connections.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client used during the configuration synchronization.
func WithPollInterval ¶
WithPollInterval sets the poll interval for fetching new configurations. By default it's set as 12h