Documentation ¶
Overview ¶
Route Represents the routing and listening to connections. This module takes care of the communication links to users and clients. They will forward commands to data driven modules in `/data`. The Listener module makes sure to listen to connections over TCP and HTTP (maybe Websocket too later.) We also have the parser which uses the policy directives to break apart the user payloads into understandable commands. Secure takes care of any encryption necessary over the wire.
Index ¶
- Constants
- Variables
- func NeedsSecurity(cmd policy.ClientCmd) bool
- func ParseCommand(mostSignificant byte, leastSignificant byte) (policy.ClientCmd, error)
- func SigVerification(authID string, signature string, content *[]byte) error
- func StartEncryption() (func(), error)
- func StartListener() (func(), error)
- func TestHelperGenSig(token *[]byte, content string, counter int) string
- type TCPClientConn
- type TCPRequestPrefix
Constants ¶
const CommandBytes = 3
Size of Packet Header for TCP commands Byte 1 :: Metadata/Parsing info Byte 2 :: More Significant byte for Command Byte 3 :: Lesser Significant byte for Command
const CrtLocation string = "./tlscert.crt"
TLS Certificate File Location from root of the project
const HttpHost string = "127.0.0.1"
HTTP Listening Host IP
const HttpPort string = ":80"
HTTP Host Listening Port Number
const IoDeadline time.Duration = 5 * time.Second
Time spent waiting for incomming connections before checking for control signals/shutoff/etc
const KeyLocation string = "./tlskey.key"
TLS Key File Location from root of the project
const ListeningSSLPortNumber string = ":26006"
SSL Port Number to Listen for connections on
const ListeningTCPIpAddress string = "127.0.0.1"
TCP IP Mask to listen for connections on
const ListeningTCPPortNumber string = ":26005"
TCP Port number to listen for connections on
const NumberOfSSLThreads = 5
Limit of Goroutines used for listening on SSL. 5 is a good number for testing, but a better number would be much higher.
const NumberOfTCPThreads = 10
Limit of Goroutines used for listening on TCP. 5 is a good number for testing, but a better number would be much higher.
const ShutdownDuration time.Duration = 10 * time.Second
Time for shutdown. Quitting Mid Handle is really bad. This should be longer than any duration
Variables ¶
var MalformedDataMsg []byte = []byte("{\"success\": false, \"error\": \"Data Was Malformed!\"}")
Constant byte string of JSON representing a data malformed error May be moved to Policy
var MalformedDataMsgLen int = len([]byte("{\"success\": false, \"error\": \"Data Was Malformed!\"}"))
Constant integer length of a JSON byte string representing a data malformed error May be moved to Policy
var SecureConnectionMsg []byte = []byte("{\"success\": true, \"message\": \"SECURED!\"}")
Constant byte string of JSON representing a Secured Connection May be moved to Policy
var SecureConnectionMsgLen int = len([]byte("{\"success\": true, \"message\": \"SECURED!\"}"))
Constant integer length of a JSON byte string representing a Secured Connection May be moved to Policy
Functions ¶
func NeedsSecurity ¶
returns if the given command needs an encrypted connection or not
see "secureMap"
func ParseCommand ¶
Parse Command takes a two byte code and returns the associated command or an error if it doesn't exist. Used mainly in TCP Request Parsing
func SigVerification ¶
Typical Verification of users for authentication. Used in most other endpoints as SigVerify in RequestBodyFactories
Takes the authID, Signature (hash of token and content), and content to see if the user can indeed make the request (they are who they say they are).
returns an error if they are not who they say they are.
func StartEncryption ¶
func StartEncryption() (func(), error)
ServerTask Startup Function for Encryption. Takes care of initialization. Loads Certificates and Keys from files and configures TLS.
func StartListener ¶
func StartListener() (func(), error)
ServerTask Startup Function for Conneciton Listening. Takes care of initialization.
Types ¶
type TCPClientConn ¶
type TCPClientConn struct {
// contains filtered or unexported fields
}
Wrapper Structure with boolean fields for a TCP Connection. used to easily differentiate between secure and insecure connections. It also helps in deciding if the TCP connection needs to parse more requests (HTTP requests close connections after one requests, but TCP connections do not.)
type TCPRequestPrefix ¶
type TCPRequestPrefix struct { IsBase64Enc bool // First Most Sig Bit IsJSON bool // Second Most Sig Bit }
First byte of a TCP request. This is a struct of booleans about how the request is structured over TCP.