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
- Variables
- func IPForAnnouncePacket() (ip net.IP, err error)
- func Initialize(configPath string) (err error)
- func LocalMulticastPacketConn() (conn *ipv4.PacketConn, err error)
- func LoopbackInterface() (lo *net.Interface, err error)
- func MakeJsonRequest(sector, action string, version int, msg *Message) (responseChan chan *Message, err error)
- func PrintStatsLoop(service *Service, timeout time.Duration, closeChan chan bool)
- func SHA1FingerPrint(cert *x509.Certificate) (hexSha1 string)
- func SetDefaultConfig(conf *Config)
- func SignSHA256(rawPayload []byte, priv *rsa.PrivateKey) (base64signature string, err error)
- func VerifySHA256(rawPayload []byte, rsaPubKey *rsa.PublicKey, encodedSignature []byte, ...) (err error)
- type ActionDescription
- type AuthorizedServiceSpec
- type AuthorizedServicesCache
- type Client
- type ClientChan
- type Config
- func (conf *Config) DiscoveryMulticastIP() (ip net.IP)
- func (conf *Config) DiscoveryMulticastPort() (port int)
- func (conf *Config) Get(key string) (value string, ok bool)
- func (conf *Config) Load(configPath string) (err error)
- func (conf *Config) ServiceCertPath(serviceName string) (certPath []byte)
- func (conf *Config) ServiceKeyPath(serviceName string) (keyPath []byte)
- func (conf *Config) Set(key string, value string)
- type Connection
- type DiscoveryAnnouncer
- type HighResTimestamp
- type IncomingMsgNo
- type Message
- func (msg *Message) Bytes() []byte
- func (msg *Message) BytesWritten() uint64
- func (msg *Message) GetError() (err string)
- func (msg *Message) GetErrorCode() (errCode string)
- func (msg *Message) GetIdentifyingToken() (token string)
- func (msg *Message) GetTicket() (ticket string)
- func (msg *Message) SetAction(action string)
- func (msg *Message) SetEnvelope(env envelopeFormat)
- func (msg *Message) SetError(err string)
- func (msg *Message) SetErrorCode(errCode string)
- func (msg *Message) SetIdentifyingToken(token string)
- func (msg *Message) SetMessageType(mtype messageType)
- func (msg *Message) SetRequestId(requestId int)
- func (msg *Message) SetTicket(ticket string)
- func (msg *Message) SetVersion(version int)
- func (msg *Message) Write(blob []byte) (n int, err error)
- func (msg *Message) WriteJson(data interface{}) (n int, err error)
- type MessageChan
- type NullWriter
- type OutgoingMsgNo
- type Packet
- type PacketHeader
- type PacketType
- type ScampDebugger
- type ScampDebuggerReader
- type Service
- func (serv *Service) Handle(client *Client)
- func (serv *Service) MarshalText() (b []byte, err error)
- func (serv *Service) Register(name string, callback ServiceActionFunc) (err error)
- func (serv *Service) RemoveClient(client *Client) (err error)
- func (serv *Service) Run()
- func (serv *Service) Stop()
- type ServiceAction
- type ServiceActionFunc
- type ServiceCache
- func (cache *ServiceCache) All() (proxies []*ServiceProxy)
- func (cache *ServiceCache) DisableRecordVerification()
- func (cache *ServiceCache) DoScan(s *bufio.Scanner) (err error)
- func (cache *ServiceCache) EnableRecordVerification()
- func (cache *ServiceCache) Refresh() (err error)
- func (cache *ServiceCache) Retrieve(ident string) (instance *ServiceProxy)
- func (cache *ServiceCache) SearchByAction(sector, action string, version int, envelope string) (instances []*ServiceProxy)
- func (cache *ServiceCache) Size() int
- func (cache *ServiceCache) Store(instance *ServiceProxy)
- type ServiceProxy
- func (sp ServiceProxy) BaseIdent() string
- func (sp *ServiceProxy) Classes() []ServiceProxyClass
- func (sp ServiceProxy) ConnSpec() string
- func (sp ServiceProxy) GetClient() (client *Client, err error)
- func (proxy *ServiceProxy) GetConnection() (client *Client, err error)
- func (sp ServiceProxy) Ident() string
- func (proxy *ServiceProxy) MarshalJSON() (b []byte, err error)
- func (sp ServiceProxy) Sector() string
- func (sp ServiceProxy) ShortHostname() string
- func (proxy *ServiceProxy) Validate() (err error)
- type ServiceProxyClass
- type ServiceProxyDiscoveryExtension
- type ServiceStats
- type Ticket
Constants ¶
const ( ENVELOPE_JSON envelopeFormat = iota ENVELOPE_JSONSTORE )
const ( MESSAGE_TYPE_REQUEST MESSAGE_TYPE_REPLY )
Variables ¶
var DefaultConfigPath = "/etc/SCAMP/soa.conf"
DefaultConfigPath is the path at which the library will, by default, look for its configuration.
var MSG_CHUNK_SIZE = 256 * 1024
Functions ¶
func IPForAnnouncePacket ¶
func Initialize ¶
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 MakeJsonRequest ¶
func PrintStatsLoop ¶
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)
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 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 ¶
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 ¶
DiscoveryMulticastIP returns the configured discovery address, or the default one if there is no configured address (discovery.multicast_address)
func (*Config) DiscoveryMulticastPort ¶
DiscoveryMulticastPort returns the configured discovery port, or the default one if there is no configured port (discovery.port)
func (*Config) Get ¶
Get returns the value of a given config option as a string, or false if it is not set.
func (*Config) ServiceCertPath ¶
ServiceCertPath uses the configuration to generate a path at which the certificate for the given service name should be found.
func (*Config) ServiceKeyPath ¶
ServiceKeyPath uses the configuration to generate a path at which the key for the given service name should be found.
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) 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) BytesWritten ¶
func (*Message) GetErrorCode ¶
func (*Message) GetIdentifyingToken ¶
func (*Message) SetEnvelope ¶
func (msg *Message) SetEnvelope(env envelopeFormat)
func (*Message) SetErrorCode ¶
func (*Message) SetIdentifyingToken ¶
func (*Message) SetMessageType ¶
func (msg *Message) SetMessageType(mtype messageType)
func (*Message) SetRequestId ¶
func (*Message) SetVersion ¶
type MessageChan ¶
type MessageChan chan *Message
type NullWriter ¶
type NullWriter int
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
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
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)
type ScampDebuggerReader ¶
type ScampDebuggerReader struct {
// contains filtered or unexported fields
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
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) MarshalText ¶
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 ¶
RemoveClient removes a client from the scamp service
type ServiceAction ¶
type ServiceAction struct {
// contains filtered or unexported fields
}
ServiceAction interface
type ServiceActionFunc ¶
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) 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)
Source Files
¶
- authorized_services_cache.go
- client.go
- config.go
- connection.go
- discovery_announce.go
- logger.go
- message.go
- packet.go
- packet_header.go
- requester.go
- scamp.go
- scamp_debugger.go
- service.go
- service_cache.go
- service_proxy.go
- service_stats.go
- ticket.go
- util_cert.go
- util_debug.go
- util_multicast.go
- util_timestamp.go
- util_verify.go