Documentation ¶
Overview ¶
Package gerte provides an api for the GERT system. More info: https://github.com/GlobalEmpire/GERT
Index ¶
Constants ¶
const ( // CommandState is used by relays to indicate result of a command to a gateway and by gateways to request the state. CommandState GertCommand = 0 // CommandRegister claims an address for this gateway using a key. CommandRegister GertCommand = 1 // CommandData transmits data from a GERTi address to a GERTc address. CommandData GertCommand = 2 // CommandClose gracefully closes a connection to a relay. CommandClose GertCommand = 3 // StateFailure is the initial gateway state. // Should be changed upon negotiation. // Also a response to failed commands with an error StateFailure GertStatus = 0 // StateConnected indicates that the Gateway is connected to a relay, no other action has been taken StateConnected GertStatus = 1 // StateAssigned indicates that the Gateway has successfully claimed an address. // Used as a response to the REGISTER command. StateAssigned GertStatus = 2 // StateClosed indicates that the Gateway has closed the connection. // Used as a response to the CLOSE command. StateClosed GertStatus = 3 // StateSent indicates that the Data has been successfully sent. // Used as a response to the DATA command. // This is not a guarantee for data that has to be sent to another peer, although it's unlikely to be incorrect. StateSent GertStatus = 4 // ErrorVersion indicates that an incompatible version was used during negotiation. ErrorVersion GertError = 0 // ErrorBadKey indicates that the Key did not match that used for the requested address. // Requested address may not exist ErrorBadKey GertError = 1 // ErrorAlreadyRegistered indicates that Registration has already been performed successfully ErrorAlreadyRegistered GertError = 2 // ErrorNotRegistered indicates that the Gateway hasn't been registered yet. // The gateway cannot send data before claiming an address ErrorNotRegistered GertError = 3 // ErrorNoRoute indicates that Data failed to send because the remote gateway couldn't be found ErrorNoRoute GertError = 4 // ErrorAddressTaken indicates that the Address request has already been claimed ErrorAddressTaken GertError = 5 )
Variables ¶
This section is empty.
Functions ¶
func PrettyPrint ¶ added in v0.5.0
PrettyPrint prints a GERT Message into a human readable string
Types ¶
type Api ¶
type Api struct { Registered bool Address GertAddress Version Version // contains filtered or unexported fields }
Api is used to perform GERTe API Operations
func (*Api) Parse ¶
Parse reads data from the GERTe socket and parses it. It returns the received Command and any errors encountered. The official API only checks the connection for data when requested. This includes connection closures from the relay. If the connection is closed, the API will call the error function instead of returning anything.
func (*Api) Register ¶
func (api *Api) Register(addr GertAddress, key string) (bool, error)
Register registers the GERTe client on the GERTe address with the associated 20 byte key. It returns a bool whether the registration was successful and any encountered errors. All gateways must register themselves with a valid GERTe address and key before sending data. The API does not track if it is registered nor what address it has registered, it instead relies on the relay it is connected to.
func (*Api) Shutdown ¶
Shutdown Gracefully closes the GERTe Socket. It returns any errors encountered. The official API prefers using a safe shutdown procedure, although the GEDS servers should be more than stable enough to survive any number of unclean shutdowns.
func (*Api) Startup ¶
Startup initializes the API. It returns any encountered errors. Initializing the API is incredibly simple. The API should be initialized for every program when it decides to use it (although it is potentially already initialized, the API will ensure it's safe to initialize.)
func (*Api) Transmit ¶
Transmit sends data to the target Address. It returns a bool whether the operation was successful and any encountered errors. The official API only allows transmissions from GERTi to GERTi via GERTe. his means that a GERTi address must be provided for each endpoint in a message.
type Command ¶
type Command struct { Command GertCommand Packet Packet Status Status }
Command is the Parsed Data returned from Api.Parse
func CommandFromBytes ¶ added in v0.5.0
CommandFromBytes parses bytes to a GERT Command
func (Command) PrintCommand ¶ added in v0.4.0
PrintCommand prints a GERT Command to a Human-readable string
type GERTc ¶
type GERTc struct { GERTe GertAddress GERTi GertAddress }
GERTc is a 6 byte GERTc Address
func GertCFromBytes ¶ added in v0.5.0
GertCFromBytes parses bytes to a GERTc Address
func (GERTc) PrintGERTc ¶ added in v0.3.1
PrintGERTc prints a GERTc Address as a string
type GertAddress ¶
GertAddress is a 3 byte address used as a GERTe/i Address
func AddressFromBytes ¶ added in v0.5.0
func AddressFromBytes(data []byte) GertAddress
AddressFromBytes parses bytes to a GERT Address
func AddressFromString ¶
func AddressFromString(addr string) (GertAddress, error)
AddressFromString converts a string with an address in the format "XXXX.YYYY" into the corresponding GertAddress. It returns the GertAddress and any encountered errors.
func (GertAddress) PrintAddress ¶ added in v0.3.1
func (addr GertAddress) PrintAddress() string
PrintAddress prints a GertAddress as a string
func (GertAddress) ToBytes ¶ added in v0.5.0
func (addr GertAddress) ToBytes() []byte
ToBytes converts a GERT Address to bytes for sending
type GertError ¶
type GertError byte
GertError is the Error Code in a "Failed" Status
func (GertError) PrintError ¶ added in v0.5.0
PrintError prints a GERT Error to a Human-readable string
type Packet ¶
Packet is the Parsed Data returned from Api.Parse for a Data Command
func PacketFromBytes ¶ added in v0.5.0
PacketFromBytes parses bytes to a GERT Packet
func (Packet) PrintPacket ¶ added in v0.5.0
PrintPacket prints a GERT Packet to a Human-readable string
type Status ¶
type Status struct { Status GertStatus Size byte Error GertError Version Version }
Status is the Parsed Status returned from Api.Parse for a Status Command
func StatusFromBytes ¶ added in v0.5.0
StatusFromBytes parses bytes to a GERT Status
func (Status) PrintStatus ¶ added in v0.5.0
PrintStatus prints a GERT Status to a Human-readable string
type Version ¶
Version is the Version used by the Connected Status
func VersionFromBytes ¶ added in v0.5.0
VersionFromBytes parses bytes to a GERT Version
func (Version) PrintVersion ¶ added in v0.5.0
PrintVersion prints a GERT Version to a Human-readable string