Documentation ¶
Index ¶
Constants ¶
const ( // Size64Bits specifies size for long number (int64 and uint64) Size64Bits = 8 // Size32Bits specifies size for int number (int32 and uint32) Size32Bits = 4 // Size16Bits specifies size for short number (int16 and uint16) Size16Bits = 2 // Size8Bits specifies size for byte and bool (int8 and uint8) Size8Bits = 1 )
Variables ¶
This section is empty.
Functions ¶
func InitializeStruct ¶
InitializeStruct Creates new instance from type.
func ReadNumber ¶
ReadNumber reads any number with any type, based on specified size (in bytes). For example, if size=32bits, int (4 bytes) will be read from the buffer.
func WriteNumber ¶
WriteNumber writes any number with any type, based on specified size (in bytes). For example, if size=32bits, int (4 bytes) will be written to the buffer.
Types ¶
type Config ¶
type Config struct { PacketLengthSize uint64 // How much bytes will be used to read packet length. PacketTypeSize uint64 // How much bytes will be used to read packet type. LengthIncludesSelf bool // Packet length includes payload size with PacketLengthSize. RemoteAddress net.Addr // Target address, will be used to establish connection. LocalAddress net.Addr // Local address, will be used to listen for new connection. ConnectImmediately bool // If true, will connect to the remote host right after receiving new connection from listener. // Pointer to the implementation of PacketBuffer. // example: &buffer.DefaultBuffer{ // PacketReader: &buffer.DefaultReader{Order: binary.LittleEndian}, // PacketWriter: &buffer.DefaultWriter{Order: binary.LittleEndian}, // } Buffer buffer.PacketBuffer // This functions fires twice, when packet fully received (start=true) and before sending to the destination (start=false) // Useful to cipher/decipher packets OutgoingProcess Process IncomingProcess Process }
type Conn ¶
type Conn struct { ID uint32 // Connection's unique ID LocalConn, RemoteConn net.Conn // Bidirectional streams (client <-> proxy <-> server) Done chan error // contains filtered or unexported fields }
Conn represents current connection.
func (*Conn) Buffer ¶
func (c *Conn) Buffer() buffer.PacketBuffer
Buffer returns connection's PacketBuffer. Do not use this buffer in multiple goroutines, otherwise you will get data race. If you want to pass PacketBuffer to goroutine, use Clone on buffer and use replica only.
example: buffer := conn.Buffer()
go func(buffer PacketBuffer) { Do something with replica here }(buffer.Clone())
func (*Conn) Reconnect ¶
Reconnect connects to the remote address, closes (if exists) current connection.
func (*Conn) SendPacket ¶
Writes packet data to the buffer and sends to the destination. Useful for manually sending packets. Outgoing=true, if you want to write to the server. Outgoing=false, if you want to write to the client.
type Packet ¶
type Packet interface { GetID() int64 SetID(id int64) SetSend(value bool) GetSend() bool Read(b buffer.PacketBuffer) Write(b buffer.PacketBuffer) }
type PacketHook ¶
PacketHook is a shortcut for packet hook function. Conn is a connection, which are received packet. Packet is an interface Packet, can be asserted to the actual packet type.
type Process ¶
type Process func(buffer buffer.PacketBuffer, start bool)
Process represents function to process packet data. Firstly executes on fully received packet (start=true). Next time executes right before sending to the destination (start=false).
type Proxy ¶
type Proxy struct { Connections *sync.Map // map[uint32]*Conn. Concurrency safe. Map with all current connections OutgoingPacketHooks, IncomingPacketHooks *sync.Map // map[id][]PacketHook Concurrency safe. Map with all registered packet hooks OutgoingPacketMap, IncomingPacketMap *sync.Map // map[id]reflect.Type. Concurrency safe. Config Config // Proxy configuration // contains filtered or unexported fields }
func (*Proxy) AddPacket ¶
AddPacket adds Packet to the list of available to hook packets. Pass empty Packet, example: (*SomePacket)(nil). Outgoing=true, if your packet is going from client to server. Outgoing=false, if your packet is going from server to client.
func (*Proxy) HookPacket ¶
func (p *Proxy) HookPacket(ID int64, outgoing bool, hook PacketHook)
HookPacket adds function, which will be fired for every packet with specified ID. Outgoing=true, if your packet is going from client to server. Outgoing=false, if your packet is going from server to client.