Documentation
¶
Index ¶
- func PacketBoundary(offset int, data []byte) (int, string)
- func RandomXorKey() uint16
- func ReadBinary(data []byte, nc interface{}) error
- func WriteBinary(nc interface{}) ([]byte, error)
- func XorCipher(data []byte, xorPos *uint16)
- type Command
- type CommandBase
- type CommandHandlers
- type ContextKey
- type Department
- type ExportedPcb
- type HandleWarden
- type PCList
- type RawPCList
- type Session
- type SessionFactory
- type Settings
- type ShineService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PacketBoundary ¶
PacketBoundary of a packet in a data segment Shine packets can be small or big small packets specify the length in the first byte big packets ignore the first byte (that is, is 0 value), and set the length in the next 2 bytes the data segment is usually a local variable in a goroutine
func RandomXorKey ¶
func RandomXorKey() uint16
RandomXorKey generate a random number between 0 and the defined xorLimit
func ReadBinary ¶
ReadBinary data into a given struct if struct size is bigger than available data, fill with zeros
func WriteBinary ¶
WriteBinary data into a given struct and return bytes
Types ¶
type Command ¶
type Command struct {
Base CommandBase // common data in every command, like operation code and length
//NcStruct interface{} // any kind of structure that is the representation in bytes of the network packet
NcStruct structs.NC // any kind of structure that is the representation in bytes of the network packet
}
Command type used to unmarshal data from the protocol commands file
func DecodePacket ¶
DecodePacket data into a struct
type CommandBase ¶
type CommandBase struct {
PacketType string
Length int
Department uint16
Command uint16
OperationCode uint16
ClientStructName string
Data []byte
}
CommandBase type used to store decoded data from a packet
func (*CommandBase) JSON ¶
func (pcb *CommandBase) JSON() ExportedPcb
JSON representation of a processed network command
func (*CommandBase) PacketLength ¶
func (pcb *CommandBase) PacketLength() int
PacketLength of a packet, which includes de operation code bytes
func (*CommandBase) RawData ¶
func (pcb *CommandBase) RawData() []byte
RawData of a packet that contains the length, operation code and packet data
func (*CommandBase) String ¶
func (pcb *CommandBase) String() string
type CommandHandlers ¶
CommandHandlers is a map of known operation codes linked to a caller
type ContextKey ¶
type ContextKey int
ContextKey identifier for values of common use within the Context
const ( // XorOffset indicates what offset in the xor hex table to use to start decrypting client data XorOffset ContextKey = iota // ShineSession if used, shine service can access session data within their handler's context ShineSession // ConnectionWriter is a utility struct which contains the tcp connection object and a mutex // it is used to write data to the client from any shine service handler ConnectionWriter )
type Department ¶
type Department struct {
HexID string `yaml:"hexId"`
Name string `yaml:"name"`
RawCommands string `yaml:"commands"`
ProcessedCommands map[string]string
}
Department type used to unmarshal data from the protocol commands file
type ExportedPcb ¶
type ExportedPcb struct {
PacketType string `json:"packetType"`
Length int `json:"length"`
Department uint16 `json:"department"`
Command string `json:"command"`
OperationCode uint16 `json:"opCode"`
Data string `json:"data"`
RawData string `json:"rawData"`
FriendlyName string `json:"friendlyName"`
}
ExportedPcb is a utility struct for logging network packets
type HandleWarden ¶
type HandleWarden struct {
// contains filtered or unexported fields
}
HandleWarden utility struct for triggering functions implemented by the calling shine service
func NewHandlerWarden ¶
func NewHandlerWarden(ch *CommandHandlers) *HandleWarden
NewHandlerWarden handlers are callbacks to be called when an operationCode is detected in a packet.
type PCList ¶
type PCList struct {
Departments map[uint8]Department
// contains filtered or unexported fields
}
PCList protocol command list friendly names for each Department and Commands within a Department
func InitCommandList ¶
InitCommandList from protocol commands file
type RawPCList ¶
type RawPCList struct {
Departments []Department `yaml:"departments,flow"`
}
RawPCList struct used to unmarshal the protocol commands file
type Session ¶
type Session interface {
Identifier() string
}
Session type for the shine service to implement if it needs session data
type SessionFactory ¶
type SessionFactory interface {
New() Session
}
SessionFactory type for the shine service to implement if it needs session data
type Settings ¶
type Settings struct {
// xor hex table used to encrypt data on the client side, we use it here to decrypt data sent by the client
XorKey []byte
// xor hex table has a limit, when that limit is reached, while decrypting, we start from offset 0 of the xor hex table
XorLimit uint16
// operation codes are the result of bit operation on the Department (category) and Command (category item) values on the client side
// each Department has a DN and each Command has a a FQDN
// the FQDN of a Command is used to give useful info about a detected packet
CommandsFilePath string
}
Settings for decoding the packets detected by this library
type ShineService ¶
type ShineService struct {
// contains filtered or unexported fields
}
ShineService to be used by the calling shine service to:
- configure the settings for TCP socket
- assign the handlers for the operation codes handled by the shine service
- use session factory specific to the shine service to create a session object in the context of each TCP connection
func NewShineService ¶
func NewShineService(s *Settings, hw *HandleWarden) *ShineService
NewShineService create new, the calling shine service must configure Settings and a HandlerWarden
func (*ShineService) Listen ¶
func (ss *ShineService) Listen(ctx context.Context, port string)
Listen on TPC socket for connection on given port
func (*ShineService) UseSessionFactory ¶
func (ss *ShineService) UseSessionFactory(sf SessionFactory)
UseSessionFactory given by the shine service
