alkasir: Index | Files | Directories

package shared

import ""

all things that are shared between several alkasir binaries, mostly structs.


Package Files

connection.go doc.go geo_codes.go keys.go publicip.go statustypes.go transport.go types.go urlvalidator.go utils.go


const (
    StatusSuccess = "Success"
    StatusFailure = "Failure"

Values of Status.Status

const ShareableTansportConnectionVersion = "ai"

the current version of the shareable data format, it could be any two letters possibly accepting more than one per version to avoid detection.


var (
    CountryCodes []string

    CountryCodeNames = map[string]string{ /* 257 elements not displayed */


    Continents = map[string]string{ /* 256 elements not displayed */


CountryCodes is the list of valid country codes.

var AlkasirDevGPGPublicKey = "" /* 1729 byte string literal not displayed */

AlkasirDevGPGPublicKey is a public GPG key used used to sign full downloads.

var UpgradeVerificationPublicKey = "" /* 132 byte string literal not displayed */

UpgradeVerificationPublicKey is a ED25519 public key to verify binary. upgrades.

func AcceptedHost Uses

func AcceptedHost(host string) bool

AcceptedHost return true if the supplied host:port or host is allowed to be added to alkasir.

func AcceptedIP Uses

func AcceptedIP(ip net.IP) bool

AcceptedURL returns true if the supplied IP is allowed to be added to alkasir.

func AcceptedPort Uses

func AcceptedPort(port int) bool


func AcceptedURL Uses

func AcceptedURL(u *url.URL) bool

AcceptedURL returns true if the supplied url is allowed to be added to alkasir.

func GetPublicIPAddr Uses

func GetPublicIPAddr() net.IP

func NewIDGen Uses

func NewIDGen(prefix string) (*idGen, error)

Return an atomic id generation instance, it will generate ids that looks like "prefix/n...".

func SafeClean Uses

func SafeClean(s string) string

SafeClean removes possibly sensitive information from a string which includes but might not be limited to ipv4 addresses.

func SafeCleanReplace Uses

func SafeCleanReplace(string, replace string) string

SafeCleanReplace replaces all occurrences of a string in a string.

func SecureRandomString Uses

func SecureRandomString(s int) (string, error)

GenerateRandomString returns a hex encoded securely generated random string.

type BinaryUpgradeRequest Uses

type BinaryUpgradeRequest struct {
    Artifact    string `json:"artifact"`
    FromVersion string `json:"fromVersion"`

BinaryUpgradeRequest .

type BinaryUpgradeResponse Uses

type BinaryUpgradeResponse struct {
    Artifact         string    `json:"artifact"`
    Version          string    `json:"version"`
    CreatedAt        time.Time `json:"createdAt"`
    SHA256Sum        string    `json:"sha256Sum"`
    ED25519Signature string    `json:"ed25519Sig"`

UpgradeMeta .

type BlockedContentRequest Uses

type BlockedContentRequest struct {
    IDMax int `json:"id_max"` // TODO: maybe move

BlockedContentRequest .

func (BlockedContentRequest) AddParams Uses

func (b BlockedContentRequest) AddParams(req *http.Request)

type BrowserExtensionSample Uses

type BrowserExtensionSample struct {
    Title           string              // Page title
    HTTPStatusCode  int                 // the http status code
    ResponseHeaders []map[string]string // HTTP response headers
    RelatedHosts    []string            // Hosts which has been used to requested load page.
    LinkHosts       []string            // Hosts linked to via anchor tags on the page

BrowserExtensionSample represents how the browser saw the url and related when it was submitted.

type BrowserSuggestionTokenRequest Uses

type BrowserSuggestionTokenRequest struct {
    URL string

BrowserSuggestionTokenRequest goes from browser extension to client

type CauseType Uses

type CauseType string

CauseType is a machine readable value providing more detail about what occured in a status response. An operation may have multiple causes for a status (whether Failure or Success).

const (
    // CauseTypeFieldValueNotFound is used to report failure to find a requested value
    // (e.g. looking up an ID).
    CauseTypeFieldValueNotFound CauseType = "FieldValueNotFound"
    // CauseTypeFieldValueRequired is used to report required values that are not
    // provided (e.g. empty strings, null values, or empty arrays).
    CauseTypeFieldValueRequired CauseType = "FieldValueRequired"
    // CauseTypeFieldValueDuplicate is used to report collisions of values that must be
    // unique (e.g. unique IDs).
    CauseTypeFieldValueDuplicate CauseType = "FieldValueDuplicate"
    // CauseTypeFieldValueInvalid is used to report malformed values (e.g. failed regex
    // match).
    CauseTypeFieldValueInvalid CauseType = "FieldValueInvalid"
    // CauseTypeFieldValueNotSupported is used to report valid (as per formatting rules)
    // values that can not be handled (e.g. an enumerated string).
    CauseTypeFieldValueNotSupported CauseType = "FieldValueNotSupported"
    // CauseTypeUnexpectedServerResponse is used to report when the server responded to the client
    // without the expected return type. The presence of this cause indicates the error may be
    // due to an intervening proxy or the server software malfunctioning.
    CauseTypeUnexpectedServerResponse CauseType = "UnexpectedServerResponse"

type Connection Uses

type Connection struct {
    Transport string `json:"t"`
    Secret    string `json:"s"`
    Addr      string `json:"a"`
    Disabled  bool   `json:"disabled"`
    Protected bool   `json:"protected"`
    ID        string `json:"-"` // Generated for tracking connection history across runs

func DecodeConnection Uses

func DecodeConnection(s string) (Connection, error)

func (*Connection) Decode Uses

func (c *Connection) Decode(s string) error

func (*Connection) DisplayName Uses

func (c *Connection) DisplayName() string

func (*Connection) Encode Uses

func (t *Connection) Encode() (string, error)

Encode encodes the transport as a single string for the purpose of letting a user paste it into his application configuraion.

func (*Connection) EnsureID Uses

func (c *Connection) EnsureID() error

EnsureID creates a uniqie connection configuration identifier based on hash sum and stable across runs.

type ExportSampleEntry Uses

type ExportSampleEntry struct {
    ID          string    `json:"id"`
    Host        string    `json:"host"`
    CountryCode string    `json:"country_code"`
    ASN         string    `json:"asn"`
    CreatedAt   time.Time `json:"created_at"`
    Origin      string    `json:"origin"`
    Type        string    `json:"type"`
    Token       string    `json:"token"`
    Data        string    `json:"data"`
    ExtraData   string    `json:"extra_data"`

Sample is the core data structure representing a network test.

type ExportSampleRequest Uses

type ExportSampleRequest struct {
    IDMax int `json:"id_max"` // TODO: maybe move

SampleRequest .

type ExportSimpleSampleEntry Uses

type ExportSimpleSampleEntry struct {
    ID          string    `json:"id"`
    CountryCode string    `json:"country_code"`
    ASN         string    `json:"asn"`
    CreatedAt   time.Time `json:"created_at"`
    Type        string    `json:"type"`
    OriginID    string    `json:"origin_id"`
    Data        string    `json:"data"`

Sample is the core data structure representing a network test.

type ExportSimpleSampleRequest Uses

type ExportSimpleSampleRequest struct {
    IDMax int `json:"id_max"` // TODO: maybe move

type HostsPublishLog Uses

type HostsPublishLog struct {
    ID          string    `json:"id"`
    Host        string    `json:"host"`
    CountryCode string    `json:"country_code"`
    ASN         string    `json:"asn"`
    CreatedAt   time.Time `json:"created_at"`
    Sticky      bool      `json:"sticky"`
    Action      string    `json:"action"`

type IPExtraData Uses

type IPExtraData struct {
    CityGeoNameID uint // The city genoname ID derived from the client's IP address using a geoip lookups.

IPExtraData is the default struct of the IP.

type NewClientTokenSample Uses

type NewClientTokenSample struct {
    URL         string // The url
    CountryCode string // The clients configured country code, ie. not the one derived by geoip.

NewClientTokenSample is stored when central accepts a client suggestion token request. Central is the only allowed origin for NewClientToken samples.

type Sample Uses

type Sample struct {
    Token      SuggestionToken // The Suggestion Token.
    URL        string          // The same URL as the initial submission token session.
    SampleType string          // The sample type.
    Data       string          // The payload in the form of serialized JSON.

Sample is the core data structure representing a network test.

type SampleResponse Uses

type SampleResponse struct {
    Ok    bool // True if the sample was accepted by the server.
    Error string

SampleResponse is sent to the client for any kind of samples sent to the server.

type Status Uses

type Status struct {
    TypeMeta `json:",inline"`
    // One of: "Success" or "Failure"
    Status string `json:"status,omitempty"`
    // A human-readable description of the status of this operation.
    Message string `json:"message,omitempty"`
    // A machine-readable description of why this operation is in the
    // "Failure" status. If this value is empty there
    // is no information available. A Reason clarifies an HTTP status
    // code but does not override it.
    Reason StatusReason `json:"reason,omitempty"`
    // Extended data associated with the reason.  Each reason may define its
    // own extended details. This field is optional and the data returned
    // is not guaranteed to conform to any schema except that defined by
    // the reason type.
    Details *StatusDetails `json:"details,omitempty"`
    // Suggested HTTP return code for this status, 0 if not set.
    Code int `json:"code,omitempty"`

Status is a return value for calls that don't return other objects.

type StatusCause Uses

type StatusCause struct {
    // A machine-readable description of the cause of the error. If this value is
    // empty there is no information available.
    Type CauseType `json:"reason,omitempty"`
    // A human-readable description of the cause of the error.  This field may be
    // presented as-is to a reader.
    Message string `json:"message,omitempty"`
    // The field of the resource that has caused this error, as named by its JSON
    // serialization. May include dot and postfix notation for nested attributes.
    // Arrays are zero-indexed.  Fields may appear more than once in an array of
    // causes due to fields having multiple errors.
    // Optional.
    // Examples:
    //   "name" - the field "name" on the current resource
    //   "items[0].name" - the field "name" on the first array entry in "items"
    Field string `json:"field,omitempty"`

StatusCause provides more information about an api.Status failure, including cases when multiple errors are encountered.

type StatusDetails Uses

type StatusDetails struct {
    // The name attribute of the resource associated with the status StatusReason
    // (when there is a single name which can be described).
    Name string `json:"name,omitempty"`
    // The kind attribute of the resource associated with the status StatusReason.
    // On some operations may differ from the requested resource Kind.
    Kind string `json:"kind,omitempty"`
    // The Causes array includes more details associated with the StatusReason
    // failure. Not all StatusReasons may provide detailed causes.
    Causes []StatusCause `json:"causes,omitempty"`
    // If specified, the time in seconds before the operation should be retried.
    RetryAfterSeconds int `json:"retryAfterSeconds,omitempty"`

StatusDetails is a set of additional properties that MAY be set by the server to provide additional information about a response. The Reason field of a Status object defines what attributes will be set. Clients must ignore fields that do not match the defined type of each attribute, and should assume that any attribute may be empty, invalid, or under defined.

type StatusReason Uses

type StatusReason string

StatusReason is an enumeration of possible failure causes. Each StatusReason must map to a single HTTP status code, but multiple reasons may map to the same HTTP status code.

const (
    // StatusReasonUnknown means the server has declined to indicate a specific reason.
    // The details field may contain other information about this error.
    // Status code 500.
    StatusReasonUnknown StatusReason = ""

    // StatusReasonUnauthorized means the server can be reached and understood the request, but requires
    // the user to present appropriate authorization credentials (identified by the WWW-Authenticate header)
    // in order for the action to be completed. If the user has specified credentials on the request, the
    // server considers them insufficient.
    // Status code 401
    StatusReasonUnauthorized StatusReason = "Unauthorized"

    // StatusReasonForbidden means the server can be reached and understood the request, but refuses
    // to take any further action.  It is the result of the server being configured to deny access for some reason
    // to the requested resource by the client.
    // Details (optional):
    //   "kind" string - the kind attribute of the forbidden resource
    //                   on some operations may differ from the requested
    //                   resource.
    //   "id"   string - the identifier of the forbidden resource
    // Status code 403
    StatusReasonForbidden StatusReason = "Forbidden"

    // StatusReasonNotFound means one or more resources required for this operation
    // could not be found.
    // Details (optional):
    //   "kind" string - the kind attribute of the missing resource
    //                   on some operations may differ from the requested
    //                   resource.
    //   "id"   string - the identifier of the missing resource
    // Status code 404
    StatusReasonNotFound StatusReason = "NotFound"

    // StatusReasonAlreadyExists means the resource you are creating already exists.
    // Details (optional):
    //   "kind" string - the kind attribute of the conflicting resource
    //   "id"   string - the identifier of the conflicting resource
    // Status code 409
    StatusReasonAlreadyExists StatusReason = "AlreadyExists"

    // StatusReasonConflict means the requested update operation cannot be completed
    // due to a conflict in the operation. The client may need to alter the request.
    // Each resource may define custom details that indicate the nature of the
    // conflict.
    // Status code 409
    StatusReasonConflict StatusReason = "Conflict"

    // StatusReasonInvalid means the requested create or update operation cannot be
    // completed due to invalid data provided as part of the request. The client may
    // need to alter the request. When set, the client may use the StatusDetails
    // message field as a summary of the issues encountered.
    // Details (optional):
    //   "kind" string - the kind attribute of the invalid resource
    //   "id"   string - the identifier of the invalid resource
    //   "causes"      - one or more StatusCause entries indicating the data in the
    //                   provided resource that was invalid.  The code, message, and
    //                   field attributes will be set.
    // Status code 422
    StatusReasonInvalid StatusReason = "Invalid"

    // StatusReasonServerTimeout means the server can be reached and understood the request,
    // but cannot complete the action in a reasonable time. The client should retry the request.
    // This is may be due to temporary server load or a transient communication issue with
    // another server. Status code 500 is used because the HTTP spec provides no suitable
    // server-requested client retry and the 5xx class represents actionable errors.
    // Details (optional):
    //   "kind" string - the kind attribute of the resource being acted on.
    //   "id"   string - the operation that is being attempted.
    //   "retryAfterSeconds" int - the number of seconds before the operation should be retried
    // Status code 500
    StatusReasonServerTimeout StatusReason = "ServerTimeout"

    // StatusReasonTimeout means that the request could not be completed within the given time.
    // Clients can get this response only when they specified a timeout param in the request,
    // or if the server cannot complete the operation within a reasonable amount of time.
    // The request might succeed with an increased value of timeout param. The client *should*
    // wait at least the number of seconds specified by the retryAfterSeconds field.
    // Details (optional):
    //   "retryAfterSeconds" int - the number of seconds before the operation should be retried
    // Status code 504
    StatusReasonTimeout StatusReason = "Timeout"

    // StatusReasonBadRequest means that the request itself was invalid, because the request
    // doesn't make any sense, for example deleting a read-only object.  This is different than
    // StatusReasonInvalid above which indicates that the API call could possibly succeed, but the
    // data was invalid.  API calls that return BadRequest can never succeed.
    StatusReasonBadRequest StatusReason = "BadRequest"

    // StatusReasonMethodNotAllowed means that the action the client attempted to perform on the
    // resource was not supported by the code - for instance, attempting to delete a resource that
    // can only be created. API calls that return MethodNotAllowed can never succeed.
    StatusReasonMethodNotAllowed StatusReason = "MethodNotAllowed"

    // StatusReasonInternalError indicates that an internal error occurred, it is unexpected
    // and the outcome of the call is unknown.
    // Details (optional):
    //   "causes" - The original error
    // Status code 500
    StatusReasonInternalError = "InternalError"

type StoreSampleRequest Uses

type StoreSampleRequest struct {
    ClientAddr string // the public ip address of the client

StoreSampleRequest for receiving StoreSample API requests.

type StoreSampleResponse Uses

type StoreSampleResponse struct {
    Ok    bool
    Error string

StoreSampleRequest for receiving StoreSample API requests.

type SuggestionToken Uses

type SuggestionToken string

SuggestionToken is a session ID.

type SuggestionTokenRequest Uses

type SuggestionTokenRequest struct {
    URL         string // The url in question
    ClientAddr  net.IP // the public ip address of the client
    CountryCode string // the client country code setting

SuggestionTokenRequest is sent from the client to central to initiate a url suggestion flow.

type SuggestionTokenResponse Uses

type SuggestionTokenResponse struct {
    Ok    bool            // false if the server denies the submitted url to be added.
    URL   string          // The url that was sent in the request, possibly altered.
    Token SuggestionToken // The token to send with all data sampling results for this session.
    Error string

SuggestionTokenResponse is sent back to the client after processing the SuggestionTokenRequest.

type SyncWriter Uses

type SyncWriter struct {

This type wraps a Write method and calls Sync after each Write.

func (SyncWriter) Write Uses

func (w SyncWriter) Write(p []byte) (n int, err error)

Call File.Write and then Sync. An error is returned if either operation returns an error.

type Transport Uses

type Transport struct {
    Name    string
    Bundled bool // bundled in distribution binary
    Command string
    TorPT   bool // if the transport is an tor pluggable transport

Transport holds the basic runtime configuration for a transport service.

type TransportTraffic Uses

type TransportTraffic struct {
    Opened     []string `json:"opened"`     // Target of all currently open connections
    ReadTotal  uint64   `json:"readTotal"`  // bytes
    WriteTotal uint64   `json:"writeTotal"` // bytes
    Throughput float64  `json:"throughput"` // bytes/second


TransportTraffic is sent from a transport to the client so that the client can know that the transport is active.

type TypeMeta Uses

type TypeMeta struct {
    // Kind is a string value representing the REST resource this object represents.
    // Servers may infer this from the endpoint the client submits requests to.
    Kind string `json:"kind,omitempty"`

    // APIVersion defines the versioned schema of this representation of an object.
    // Servers should convert recognized schemas to the latest internal value, and
    // may reject unrecognized values.
    APIVersion string `json:"apiVersion,omitempty"`

TypeMeta describes an individual object in an API response or request with strings representing the type of the object and its API schema version. Structures that are versioned or persisted should inline TypeMeta.

type UpdateHostlistRequest Uses

type UpdateHostlistRequest struct {
    ClientAddr    net.IP // the public ip address of the client
    UpdateID      string `json:"update_id"`  // unique installation identifer
    ClientVersion string `json:"client_ver"` // client version

UpdateHostlistRequest .

type UpdateHostlistResponse Uses

type UpdateHostlistResponse struct {
    Ok    bool
    Error string
    Hosts []string // All hosts listed as blocked in the current region

UpdateHostlistRequest .


apierrorsPackage errors provides detailed error types for api field validation.
jwtmwPackage jwt provides Json-Web-Token authentication for the go-json-rest framework
linkheaderPackage link implements parsing and serialization of Link header values as defined in RFC 5988.

Package shared imports 22 packages (graph) and is imported by 14 packages. Updated 2016-08-14. Refresh now. Tools for package owners.