Go: Packets¶
Functions¶
RegisterPacketHook¶
| Go | |
|---|---|
RegisterPacketHook calls fn for every packet in the directions of dirMask, the PIER_PKT_MASK_* bits of abi.h: 1 for inbound, 2 for outbound. fn runs where the host pumps the connection or sends the packet, which is usually the server thread and not always, since a flush can be asynchronous; fn keeps to its own state and reaches the world through Schedule.
- Parameters:
- dirMask :
int32 - fn :
func(*PacketCall) PacketVerdict
- dirMask :
- Return type:
(*PacketHook, error) - Slots:
packet_hook_register
RegisterPacketHookIDs¶
| Go | |
|---|---|
RegisterPacketHookIDs is RegisterPacketHook for the listed packet ids only: a packet whose id no hook listed is passed on before fn runs or any lock is taken.
- Parameters:
- dirMask :
int32 - ids :
[]int32 - fn :
func(*PacketCall) PacketVerdict
- dirMask :
- Return type:
(*PacketHook, error) - Slots:
packet_hook_register_ids
RegisterConnHook¶
| Go | |
|---|---|
RegisterConnHook calls fn when a connection opens and when it closes, with the threading RegisterPacketHook describes.
- Parameters:
- fn :
func(connID uint64, address string, opened bool)
- fn :
- Return type:
(*PacketHook, error) - Slots:
packet_conn_hook_register
PacketCall¶
PacketCall is one packet inside a hook, with the ways to change it.
PacketCall.SetPacketID¶
| Go | |
|---|---|
SetPacketID makes the forwarded packet carry another id.
- Parameters:
- id :
int32
- id :
PacketCall.SetSubIDs¶
| Go | |
|---|---|
SetSubIDs changes the sender and target sub-client ids of the forwarded packet.
- Parameters:
- sender :
uint8 - target :
uint8
- sender :
PacketCall.Replace¶
| Go | |
|---|---|
Replace hands over the body to forward; it takes effect when the hook returns PacketReplace.
- Parameters:
- body :
[]byte
- body :
PacketHook¶
PacketHook is a registered packet or connection hook, kept to remove it.
PacketHook.Unregister¶
| Go | |
|---|---|
Unregister removes the hook. Calling it twice is harmless.
- Return type:
error - Slots:
packet_conn_hook_unregister,packet_hook_unregister
PacketHookHandle¶
| Go | |
|---|---|
PacketHookHandle is a registered packet hook.
PacketHookHandle.IsZero¶
| Go | |
|---|---|
IsZero reports whether the handle names nothing.
- Return type:
bool
PacketVerdict¶
| Go | |
|---|---|
PacketVerdict is what a packet hook decides about one packet.
| Name | Value | Description |
|---|---|---|
PacketPass |
0 |
|
PacketReplace |
1 |
|
PacketDrop |
2 |
PacketEvent¶
| Go | |
|---|---|
PacketEvent is one packet a hook sees. Body is a copy.