This commit is contained in:
Sudo-Ivan
2024-12-30 02:34:38 -06:00
parent 2e01fa565d
commit bfc75a2290
3 changed files with 10 additions and 11 deletions

View File

@@ -68,15 +68,15 @@ func (c *Client) Start() error {
continue continue
} }
// Convert callback type to match interface callback := common.PacketCallback(func(data []byte, iface interface{}) {
callback := func(data []byte, iface interface{}) {
c.transport.HandlePacket(data, iface) c.transport.HandlePacket(data, iface)
} })
client.SetPacketCallback(common.PacketCallback(callback)) client.SetPacketCallback(callback)
iface = client iface = client
case "udp": case "udp":
addr := fmt.Sprintf("%s:%d", ifaceConfig.Address, ifaceConfig.Port) addr := fmt.Sprintf("%s:%d", ifaceConfig.Address, ifaceConfig.Port)
udp, err := interfaces.NewUDPInterface( udp, err := interfaces.NewUDPInterface(
ifaceConfig.Name, ifaceConfig.Name,
addr, addr,
@@ -87,11 +87,10 @@ func (c *Client) Start() error {
continue continue
} }
// Convert callback type to match interface callback := common.PacketCallback(func(data []byte, iface interface{}) {
callback := func(data []byte, iface interface{}) {
c.transport.HandlePacket(data, iface) c.transport.HandlePacket(data, iface)
} })
udp.SetPacketCallback(common.PacketCallback(callback)) udp.SetPacketCallback(callback)
iface = udp iface = udp
default: default:

View File

@@ -9,7 +9,7 @@ import (
type InterfaceMode byte type InterfaceMode byte
type InterfaceType byte type InterfaceType byte
type PacketCallback func([]byte, interface{}) type PacketCallback = func([]byte, interface{})
// NetworkInterface combines both low-level and high-level interface requirements // NetworkInterface combines both low-level and high-level interface requirements
type NetworkInterface interface { type NetworkInterface interface {

View File

@@ -40,7 +40,7 @@ type TCPClientInterface struct {
maxReconnectTries int maxReconnectTries int
packetBuffer []byte packetBuffer []byte
packetType byte packetType byte
packetCallback func([]byte, interface{}) packetCallback common.PacketCallback
} }
func NewTCPClient(name string, targetAddr string, targetPort int, kissFraming bool, i2pTunneled bool) (*TCPClientInterface, error) { func NewTCPClient(name string, targetAddr string, targetPort int, kissFraming bool, i2pTunneled bool) (*TCPClientInterface, error) {
@@ -273,7 +273,7 @@ func escapeKISS(data []byte) []byte {
return escaped return escaped
} }
func (tc *TCPClientInterface) SetPacketCallback(cb func([]byte, interface{})) { func (tc *TCPClientInterface) SetPacketCallback(cb common.PacketCallback) {
tc.packetCallback = cb tc.packetCallback = cb
} }