From bfc75a229056449a96a50a3f08494219e051481b Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Mon, 30 Dec 2024 02:34:38 -0600 Subject: [PATCH] 0.2.1 --- cmd/client/client.go | 15 +++++++-------- pkg/common/interface.go | 2 +- pkg/interfaces/tcp.go | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/client/client.go b/cmd/client/client.go index 08e9508..2c1c3c4 100644 --- a/cmd/client/client.go +++ b/cmd/client/client.go @@ -68,15 +68,15 @@ func (c *Client) Start() error { continue } - // Convert callback type to match interface - callback := func(data []byte, iface interface{}) { + callback := common.PacketCallback(func(data []byte, iface interface{}) { c.transport.HandlePacket(data, iface) - } - client.SetPacketCallback(common.PacketCallback(callback)) + }) + client.SetPacketCallback(callback) iface = client case "udp": addr := fmt.Sprintf("%s:%d", ifaceConfig.Address, ifaceConfig.Port) + udp, err := interfaces.NewUDPInterface( ifaceConfig.Name, addr, @@ -87,11 +87,10 @@ func (c *Client) Start() error { continue } - // Convert callback type to match interface - callback := func(data []byte, iface interface{}) { + callback := common.PacketCallback(func(data []byte, iface interface{}) { c.transport.HandlePacket(data, iface) - } - udp.SetPacketCallback(common.PacketCallback(callback)) + }) + udp.SetPacketCallback(callback) iface = udp default: diff --git a/pkg/common/interface.go b/pkg/common/interface.go index 1f7ccf6..edfce0c 100644 --- a/pkg/common/interface.go +++ b/pkg/common/interface.go @@ -9,7 +9,7 @@ import ( type InterfaceMode byte type InterfaceType byte -type PacketCallback func([]byte, interface{}) +type PacketCallback = func([]byte, interface{}) // NetworkInterface combines both low-level and high-level interface requirements type NetworkInterface interface { diff --git a/pkg/interfaces/tcp.go b/pkg/interfaces/tcp.go index 45a1c85..28d282a 100644 --- a/pkg/interfaces/tcp.go +++ b/pkg/interfaces/tcp.go @@ -40,7 +40,7 @@ type TCPClientInterface struct { maxReconnectTries int packetBuffer []byte packetType byte - packetCallback func([]byte, interface{}) + packetCallback common.PacketCallback } 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 } -func (tc *TCPClientInterface) SetPacketCallback(cb func([]byte, interface{})) { +func (tc *TCPClientInterface) SetPacketCallback(cb common.PacketCallback) { tc.packetCallback = cb }