Documentation
¶
Index ¶
- type Config
- type Instance
- func (i *Instance) AttemptReconnect()
- func (i *Instance) Bind(opcode string, handler func(*Peer, *RxPacket), required_features ...string)
- func (i *Instance) Broadcast(packet *TxPacket, peers PeerSlice)
- func (i *Instance) Connect(id string) *Peer
- func (i *Instance) GetPeerState() PeerState
- func (i *Instance) PeerHandler(conn *Peer)
- func (i *Instance) Remap(opcode string, handler func(*Peer, *RxPacket), required_features ...string)
- func (i *Instance) Run()
- func (i *Instance) SpawnTicker(conn *Peer)
- func (i *Instance) Unbind(opcode string)
- func (i *Instance) Unmap(opcode string)
- type Listener
- type NegotiationArgs
- type OpcodeMatcher
- type Packet
- type Peer
- func (c *Peer) GiveName() string
- func (conn *Peer) HandleNegotiate(reader *RxPacket)
- func (conn *Peer) HandlePacket(r *RxPacket)
- func (c *Peer) IsClient() bool
- func (c *Peer) Read(data any) *RxPacket
- func (conn *Peer) SendAndWaitForReply(request *TxPacket) *RxPacket
- func (conn *Peer) SendNegotiate(r *RxPacket)
- func (conn *Peer) WaitForMatchedPacket(opcodes ...string) *RxPacket
- func (c *Peer) Write(packet *TxPacket)
- func (c *Peer) WriteBlocking(packet *TxPacket)
- type PeerSlice
- type PeerState
- type Peers
- type RxPacket
- type TxPacket
- type VersionArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct {
Name string
Pinger bool
PingInterval time.Duration
Handler *peer.Peer
Close chan bool
Done chan bool
RetryCounter int
MaxRetries int
Peers Peers
OnCreate func()
AfterNegotiation func(*Peer)
OnOpen func(*Peer)
OnClose func(*Peer)
CustomHandlersRequiredFeatures map[string][]string
CustomHandlers map[string]func(*Peer, *RxPacket)
RemappedHandlersRequiredFeatures map[string][]string
RemappedHandlers map[string]func(*Peer, *RxPacket)
IsBridge bool
IsRelay bool
IsDiscovery bool
OnBridgeConnected func(*Peer)
OnRelayConnected func(*Peer)
OnDiscoveryConnected func(*Peer)
Logger *zerolog.Logger
// contains filtered or unexported fields
}
Instance is a representation of a duplex instance.
func (*Instance) AttemptReconnect ¶
func (i *Instance) AttemptReconnect()
func (*Instance) GetPeerState ¶
func (*Instance) PeerHandler ¶
func (*Instance) SpawnTicker ¶
type NegotiationArgs ¶
type OpcodeMatcher ¶
type Peer ¶
type Peer struct {
Parent *Instance // Pointer to the parent instance that created this peer
Lock *sync.Mutex // Lock for thread safety
KeyStore map[string]any // Map of key-value pairs of any type
KeyLock *sync.Mutex
OpcodeMatchers map[*Peer]*OpcodeMatcher // Map of key-value pairs to listen to specific opcodes from specific peers.
Listeners map[string]Listener // Map of key-value pairs to listeners.
Features []string // List of features advertised by this peer
IsInitiator bool // True if this peer initiated the connection
IsBridge bool // True if this peer is a bridge
IsRelay bool // True if this peer is a relay
IsDiscovery bool // True if this peer is a discovery
Done chan bool // Channel to signal connection closure
RTT int64 // Round-trip time (in milliseconds)
GiveNameRemapper func() string
Logger zerolog.Logger
*peer.DataConnection // Pointer to the peer data connection
}
Peer is a representation of a peer connection for a duplex instance.
func (*Peer) HandleNegotiate ¶
func (*Peer) HandlePacket ¶
func (*Peer) SendAndWaitForReply ¶
SendAndWaitForReply sends a packet and waits for a response with the given opcode. The packet needs to be tagged with a listener string. The function will return a channel that will receive the response packet when it is received. If the opcode of the received packet does not match the reply opcode, the function will return nil. The function will also return nil if the packet is not tagged with a listener string. The function will block until the response is received or the underlying connection is closed. The function is safe for concurrent use.
func (*Peer) SendNegotiate ¶
SendNegotiate sends a NEGOTIATE packet to a newly connected peer.
func (*Peer) WaitForMatchedPacket ¶
Creates a callback that fires whenever a specific connection receives a specific packet opcode.
func (*Peer) WriteBlocking ¶
WriteBlocking is a variant of Write that has a blocking mode that exits when it has finished sending the entire message to the recipient.
type RxPacket ¶
type RxPacket struct {
Packet
Payload json.RawMessage `json:"payload,omitempty"`
}