scamp

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2017 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

SCAMP provides SOA bus RPC functionality. Please see root SCAMP/README.md for details on configuring environment.

Basics

Services and requesters communicate over persistent TLS connections. First, initialize your environment according to the root README.md. You must have a valid certificate and key to present a service.

Every program must call `scamp.Initialize()` before doing anything else, to initialize the global configuration.

Index

Constants

View Source
const (
	ENVELOPE_JSON envelopeFormat = iota
	ENVELOPE_JSONSTORE
)
View Source
const (
	MESSAGE_TYPE_REQUEST
	MESSAGE_TYPE_REPLY
)

Variables

View Source
var (
	Trace   *log.Logger
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
)
View Source
var DefaultConfigPath = "/etc/SCAMP/soa.conf"

DefaultConfigPath is the path at which the library will, by default, look for its configuration.

View Source
var MSG_CHUNK_SIZE = 256 * 1024

Functions

func IPForAnnouncePacket

func IPForAnnouncePacket() (ip net.IP, err error)

func Initialize

func Initialize(configPath string) (err error)

Initialize performs package-level setup. This must be called before calling any other package functionality, as it sets up global configuration.

func LocalMulticastPacketConn

func LocalMulticastPacketConn() (conn *ipv4.PacketConn, err error)

func LoopbackInterface

func LoopbackInterface() (lo *net.Interface, err error)

func MakeJsonRequest

func MakeJsonRequest(sector, action string, version int, msg *Message) (responseChan chan *Message, err error)

func PrintStatsLoop

func PrintStatsLoop(service *Service, timeout time.Duration, closeChan chan bool)

func SHA1FingerPrint

func SHA1FingerPrint(cert *x509.Certificate) (hexSha1 string)

func SetDefaultConfig

func SetDefaultConfig(conf *Config)

SetDefaultConfig sets the global configuration manually if need be. In general, users should use Initialize instead.

func SignSHA256

func SignSHA256(rawPayload []byte, priv *rsa.PrivateKey) (base64signature string, err error)

func VerifySHA256

func VerifySHA256(rawPayload []byte, rsaPubKey *rsa.PublicKey, encodedSignature []byte, isURLEncoded bool) (err error)

Types

type ActionDescription

type ActionDescription struct {
	// contains filtered or unexported fields
}

func (ActionDescription) Name

func (ad ActionDescription) Name() string

func (ActionDescription) Version

func (ad ActionDescription) Version() int

type AuthorizedServiceSpec

type AuthorizedServiceSpec struct {
	Fingerprint []byte
	Actions     []ServiceProxyClass
}

AuthorizedServiceSpec contains service's fingerprint and registered actions

func NewAuthorizedServicesSpec

func NewAuthorizedServicesSpec(line []byte) (spec *AuthorizedServiceSpec, err error)

NewAuthorizedServicesSpec returns a pointer to an AuthorizedServiceSpec which contains the service's fingerprint and svailable actions

type AuthorizedServicesCache

type AuthorizedServicesCache struct {
	// contains filtered or unexported fields
}

AuthorizedServicesCache contains array of service's AuthorizedServiceSpec

func NewAuthorizedServicesCache

func NewAuthorizedServicesCache() (cache *AuthorizedServicesCache)

NewAuthorizedServicesCache Initializes amd returns a pointesr to a new AuthorizedServicesCache

func (*AuthorizedServicesCache) LoadAuthorizedServices

func (cache *AuthorizedServicesCache) LoadAuthorizedServices(s *bufio.Scanner) (err error)

LoadAuthorizedServices calls NewAuthorizedServicesCache() if *bufio.Scanner bytes are > 0

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Dial

func Dial(connspec string) (client *Client, err error)

func NewClient

func NewClient(conn *Connection) (client *Client)

func (*Client) Close

func (client *Client) Close()

Close unlocks a client mutex and closes the connection

func (*Client) Incoming

func (client *Client) Incoming() MessageChan

Incoming returns a client's MessageChan

func (*Client) Send

func (client *Client) Send(msg *Message) (responseChan MessageChan, err error)

TODO: would be nice to have different code path for scamp responses so that we don't need to rely on garbage collection of channels when we're replying and don't expect or need a response

func (*Client) SetService

func (client *Client) SetService(serv *Service)

type ClientChan

type ClientChan chan *Client

type Config

type Config struct {
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() (conf *Config)

DefaultConfig fetches the global configuration struct for use. This function panics if the global configuration is not initialized (with `Initialize()`).

func NewConfig

func NewConfig() (conf *Config)

NewConfig creates a new configuration struct with default values initialized.

func (*Config) DiscoveryMulticastIP

func (conf *Config) DiscoveryMulticastIP() (ip net.IP)

DiscoveryMulticastIP returns the configured discovery address, or the default one if there is no configured address (discovery.multicast_address)

func (*Config) DiscoveryMulticastPort

func (conf *Config) DiscoveryMulticastPort() (port int)

DiscoveryMulticastPort returns the configured discovery port, or the default one if there is no configured port (discovery.port)

func (*Config) Get

func (conf *Config) Get(key string) (value string, ok bool)

Get returns the value of a given config option as a string, or false if it is not set.

func (*Config) Load

func (conf *Config) Load(configPath string) (err error)

Load loads configuration k/v pairs from the file at the given path.

func (*Config) ServiceCertPath

func (conf *Config) ServiceCertPath(serviceName string) (certPath []byte)

ServiceCertPath uses the configuration to generate a path at which the certificate for the given service name should be found.

func (*Config) ServiceKeyPath

func (conf *Config) ServiceKeyPath(serviceName string) (keyPath []byte)

ServiceKeyPath uses the configuration to generate a path at which the key for the given service name should be found.

func (*Config) Set

func (conf *Config) Set(key string, value string)

Set sets the given key to the given value in the configuration

type Connection

type Connection struct {
	Fingerprint string
	// contains filtered or unexported fields
}

Connection a scamp connection

func DialConnection

func DialConnection(connspec string) (conn *Connection, err error)

DialConnection Used by Client to establish a secure connection to the remote service. TODO: You must use the *connection.Fingerprint to verify the remote host

func NewConnection

func NewConnection(tlsConn *tls.Conn, connType string) (conn *Connection)

NewConnection Used by Service

func (*Connection) Close

func (conn *Connection) Close()

Close closes the current *Connection

func (*Connection) Send

func (conn *Connection) Send(msg *Message) (err error)

Send sends a scamp message using the current *Connection

func (*Connection) SetClient

func (conn *Connection) SetClient(client *Client)

SetClient sets the client for a *Connection

type DiscoveryAnnouncer

type DiscoveryAnnouncer struct {
	// contains filtered or unexported fields
}

func NewDiscoveryAnnouncer

func NewDiscoveryAnnouncer() (announcer *DiscoveryAnnouncer, err error)

func (*DiscoveryAnnouncer) AnnounceLoop

func (announcer *DiscoveryAnnouncer) AnnounceLoop()

func (*DiscoveryAnnouncer) Stop

func (announcer *DiscoveryAnnouncer) Stop()

func (*DiscoveryAnnouncer) Track

func (announcer *DiscoveryAnnouncer) Track(serv *Service)

type HighResTimestamp

type HighResTimestamp float64

func Gettimeofday

func Gettimeofday() (ts HighResTimestamp, err error)

func (HighResTimestamp) MarshalJSON

func (ts HighResTimestamp) MarshalJSON() ([]byte, error)

type IncomingMsgNo

type IncomingMsgNo uint64

type Message

type Message struct {
	Action   string
	Envelope envelopeFormat
	// TODO: how do RequestId's fit in again? NOTE: from (SCAMP repo) -"Set to 18 random base64 bytes"
	RequestId   int
	Version     int
	MessageType messageType

	Ticket           string
	IdentifyingToken string
	Error            string
	ErrorCode        string
	// contains filtered or unexported fields
}

func NewMessage

func NewMessage() (msg *Message)

func NewRequestMessage

func NewRequestMessage() (msg *Message)

func NewResponseMessage

func NewResponseMessage() (msg *Message)

func (*Message) Bytes

func (msg *Message) Bytes() []byte

func (*Message) BytesWritten

func (msg *Message) BytesWritten() uint64

func (*Message) GetError

func (msg *Message) GetError() (err string)

func (*Message) GetErrorCode

func (msg *Message) GetErrorCode() (errCode string)

func (*Message) GetIdentifyingToken

func (msg *Message) GetIdentifyingToken() (token string)

func (*Message) GetTicket

func (msg *Message) GetTicket() (ticket string)

func (*Message) SetAction

func (msg *Message) SetAction(action string)

func (*Message) SetEnvelope

func (msg *Message) SetEnvelope(env envelopeFormat)

func (*Message) SetError

func (msg *Message) SetError(err string)

func (*Message) SetErrorCode

func (msg *Message) SetErrorCode(errCode string)

func (*Message) SetIdentifyingToken

func (msg *Message) SetIdentifyingToken(token string)

func (*Message) SetMessageType

func (msg *Message) SetMessageType(mtype messageType)

func (*Message) SetRequestId

func (msg *Message) SetRequestId(requestId int)

func (*Message) SetTicket

func (msg *Message) SetTicket(ticket string)

func (*Message) SetVersion

func (msg *Message) SetVersion(version int)

func (*Message) Write

func (msg *Message) Write(blob []byte) (n int, err error)

func (*Message) WriteJson

func (msg *Message) WriteJson(data interface{}) (n int, err error)

type MessageChan

type MessageChan chan *Message

type NullWriter

type NullWriter int

func (NullWriter) Write

func (NullWriter) Write([]byte) (int, error)

type OutgoingMsgNo

type OutgoingMsgNo uint64

type Packet

type Packet struct {
	// contains filtered or unexported fields
}

func ReadPacket

func ReadPacket(reader *bufio.ReadWriter) (pkt *Packet, err error)

Will parse an io stream in to a packet struct

func (*Packet) Write

func (pkt *Packet) Write(writer io.Writer) (written int, err error)

type PacketHeader

type PacketHeader struct {
	Action           string         `json:"action"`               // request
	Envelope         envelopeFormat `json:"envelope"`             // request
	Error            string         `json:"error,omitempty"`      // reply
	ErrorCode        string         `json:"error_code,omitempty"` // reply
	RequestId        int            `json:"request_id"`           // both
	Ticket           string         `json:"ticket"`               // request
	IdentifyingToken string         `json:"identifying_token"`
	MessageType      messageType    `json:"type"`    // both
	Version          int            `json:"version"` // request
}

Serialized to JSON and stuffed in the 'header' property of each packet

func (*PacketHeader) Write

func (pktHdr *PacketHeader) Write(writer io.Writer) (err error)

type PacketType

type PacketType int
const (
	HEADER PacketType = iota
	DATA
	EOF
	TXERR
	ACK
)

type ScampDebugger

type ScampDebugger struct {
	// contains filtered or unexported fields
}

func NewScampDebugger

func NewScampDebugger(conn *tls.Conn, clientType string) (handle *ScampDebugger, err error)

func (*ScampDebugger) ReadWriter

func (handle *ScampDebugger) ReadWriter(p []byte) (n int, err error)

func (*ScampDebugger) Write

func (handle *ScampDebugger) Write(p []byte) (n int, err error)

type ScampDebuggerReader

type ScampDebuggerReader struct {
	// contains filtered or unexported fields
}

func (*ScampDebuggerReader) Write

func (sdr *ScampDebuggerReader) Write(p []byte) (n int, err error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(sector string, serviceSpec string, humanName string) (*Service, error)

NewService intializes and returns pointer to a new scamp service

func NewServiceExplicitCert

func NewServiceExplicitCert(sector string, serviceSpec string, humanName string, keypair tls.Certificate, pemCert []byte) (serv *Service, err error)

NewServiceExplicitCert intializes and returns pointer to a new scamp service, with an explicitly specified certificate rather than an implicitly discovered one. keypair is a TLS certificate, and pemCert is the raw bytes of an X509 certificate.

func (*Service) Handle

func (serv *Service) Handle(client *Client)

Handle handles incoming client messages received via the cient MessageChan

func (*Service) MarshalText

func (serv *Service) MarshalText() (b []byte, err error)

MarshalText serializes a scamp service

func (*Service) Register

func (serv *Service) Register(name string, callback ServiceActionFunc) (err error)

Register registers a service handler callback

func (*Service) RemoveClient

func (serv *Service) RemoveClient(client *Client) (err error)

RemoveClient removes a client from the scamp service

func (*Service) Run

func (serv *Service) Run()

Run starts a scamp service

func (*Service) Stop

func (serv *Service) Stop()

Stop closes the service's net.Listener

type ServiceAction

type ServiceAction struct {
	// contains filtered or unexported fields
}

ServiceAction interface

type ServiceActionFunc

type ServiceActionFunc func(*Message, *Client)

ServiceActionFunc represents a service callback

type ServiceCache

type ServiceCache struct {
	// contains filtered or unexported fields
}

func NewServiceCache

func NewServiceCache(path string) (cache *ServiceCache, err error)

func (*ServiceCache) All

func (cache *ServiceCache) All() (proxies []*ServiceProxy)

func (*ServiceCache) DisableRecordVerification

func (cache *ServiceCache) DisableRecordVerification()

func (*ServiceCache) DoScan

func (cache *ServiceCache) DoScan(s *bufio.Scanner) (err error)

func (*ServiceCache) EnableRecordVerification

func (cache *ServiceCache) EnableRecordVerification()

func (*ServiceCache) Refresh

func (cache *ServiceCache) Refresh() (err error)

func (*ServiceCache) Retrieve

func (cache *ServiceCache) Retrieve(ident string) (instance *ServiceProxy)

func (*ServiceCache) SearchByAction

func (cache *ServiceCache) SearchByAction(sector, action string, version int, envelope string) (instances []*ServiceProxy)

func (*ServiceCache) Size

func (cache *ServiceCache) Size() int

func (*ServiceCache) Store

func (cache *ServiceCache) Store(instance *ServiceProxy)

type ServiceProxy

type ServiceProxy struct {
	// contains filtered or unexported fields
}

func NewServiceProxy

func NewServiceProxy(classRecordsRaw []byte, certRaw []byte, sigRaw []byte) (proxy *ServiceProxy, err error)

func ServiceAsServiceProxy

func ServiceAsServiceProxy(serv *Service) (proxy *ServiceProxy)

func (ServiceProxy) BaseIdent

func (sp ServiceProxy) BaseIdent() string

func (*ServiceProxy) Classes

func (sp *ServiceProxy) Classes() []ServiceProxyClass

func (ServiceProxy) ConnSpec

func (sp ServiceProxy) ConnSpec() string

func (ServiceProxy) GetClient

func (sp ServiceProxy) GetClient() (client *Client, err error)

func (*ServiceProxy) GetConnection

func (proxy *ServiceProxy) GetConnection() (client *Client, err error)

func (ServiceProxy) Ident

func (sp ServiceProxy) Ident() string

func (*ServiceProxy) MarshalJSON

func (proxy *ServiceProxy) MarshalJSON() (b []byte, err error)

func (ServiceProxy) Sector

func (sp ServiceProxy) Sector() string

func (ServiceProxy) ShortHostname

func (sp ServiceProxy) ShortHostname() string

func (*ServiceProxy) Validate

func (proxy *ServiceProxy) Validate() (err error)

1) Verify signature of classRecords 2) Make sure the fingerprint is in authorized_services 3) Filter announced actions against authorized actions

type ServiceProxyClass

type ServiceProxyClass struct {
	// contains filtered or unexported fields
}

func (ServiceProxyClass) Actions

func (spc ServiceProxyClass) Actions() []ActionDescription

func (ServiceProxyClass) Name

func (spc ServiceProxyClass) Name() string

type ServiceProxyDiscoveryExtension

type ServiceProxyDiscoveryExtension struct {
	Vmin   int           `json:"vmin"`
	Vmaj   int           `json:"vmaj"`
	AcSec  []interface{} `json:"acsec"`
	AcName []string      `json:"acname"`
	AcVer  []interface{} `json:"acver"`
	AcEnv  []interface{} `json:"acenv"`
	AcFlag []interface{} `json:"acflag"`
	AcNs   []interface{} `json:"acns"`
}

Example: {"vmin":0,"vmaj":4,"acsec":[[7,"background"]],"acname":["_evaluate","_execute","_evaluate","_execute","_munge","_evaluate","_execute"],"acver":[[7,1]],"acenv":[[7,"json,jsonstore,extdirect"]],"acflag":[[7,""]],"acns":[[2,"Channel.Amazon.FeedInterchange"],[3,"Channel.Amazon.InvPush"],[2,"Channel.Amazon.OrderImport"]]}

type ServiceStats

type ServiceStats struct {
	ClientsAccepted uint64 `json:"total_clients_accepted"`
	OpenConnections uint64 `json:"open_connections"`
}

func GatherStats

func GatherStats(service *Service) (stats ServiceStats)

type Ticket

type Ticket struct {
	Version       int64
	UserId        int64
	ClientId      int64
	ValidityStart int64
	ValidityEnd   int64

	Ttl     int
	Expired bool
}

func ReadTicket

func ReadTicket(incoming []byte, signingPubKey []byte) (ticket Ticket, err error)

func ReadTicketNoVerify

func ReadTicketNoVerify(incoming []byte) (ticket Ticket, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL