Add initial project structure with core functionality
- Created a new Go module named 'teleport' for secure port forwarding. - Added essential files including .gitignore, LICENSE, and README.md with project details. - Implemented configuration management with YAML support in config package. - Developed core client and server functionalities for handling port forwarding. - Introduced DNS server capabilities and integrated logging with sanitization. - Established rate limiting and metrics tracking for performance monitoring. - Included comprehensive tests for core components and functionalities. - Set up CI workflows for automated testing and release management using Gitea actions.
This commit is contained in:
33
pkg/types/types.go
Normal file
33
pkg/types/types.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package types
|
||||
|
||||
import "net"
|
||||
|
||||
// PortForwardRequest represents a port forwarding request
|
||||
type PortForwardRequest struct {
|
||||
LocalPort int
|
||||
RemotePort int
|
||||
Protocol string
|
||||
TargetHost string
|
||||
}
|
||||
|
||||
// UDPPacketHeader represents the header for UDP packets
|
||||
type UDPPacketHeader struct {
|
||||
ClientID string
|
||||
PacketID uint64
|
||||
Timestamp int64
|
||||
}
|
||||
|
||||
// TaggedUDPPacket represents a UDP packet with tagging information
|
||||
type TaggedUDPPacket struct {
|
||||
Header UDPPacketHeader
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// UDPRequest represents a UDP forwarding request
|
||||
type UDPRequest struct {
|
||||
LocalPort int
|
||||
RemotePort int
|
||||
Protocol string
|
||||
Data []byte
|
||||
ClientAddr *net.UDPAddr
|
||||
}
|
||||
112
pkg/types/types_test.go
Normal file
112
pkg/types/types_test.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPortForwardRequest(t *testing.T) {
|
||||
req := PortForwardRequest{
|
||||
LocalPort: 8080,
|
||||
RemotePort: 80,
|
||||
Protocol: "tcp",
|
||||
}
|
||||
|
||||
if req.LocalPort != 8080 {
|
||||
t.Errorf("Expected LocalPort 8080, got %d", req.LocalPort)
|
||||
}
|
||||
|
||||
if req.RemotePort != 80 {
|
||||
t.Errorf("Expected RemotePort 80, got %d", req.RemotePort)
|
||||
}
|
||||
|
||||
if req.Protocol != "tcp" {
|
||||
t.Errorf("Expected Protocol 'tcp', got '%s'", req.Protocol)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUDPPacketHeader(t *testing.T) {
|
||||
header := UDPPacketHeader{
|
||||
ClientID: "test-client",
|
||||
PacketID: 12345,
|
||||
Timestamp: 1640995200,
|
||||
}
|
||||
|
||||
if header.ClientID != "test-client" {
|
||||
t.Errorf("Expected ClientID 'test-client', got '%s'", header.ClientID)
|
||||
}
|
||||
|
||||
if header.PacketID != 12345 {
|
||||
t.Errorf("Expected PacketID 12345, got %d", header.PacketID)
|
||||
}
|
||||
|
||||
if header.Timestamp != 1640995200 {
|
||||
t.Errorf("Expected Timestamp 1640995200, got %d", header.Timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaggedUDPPacket(t *testing.T) {
|
||||
header := UDPPacketHeader{
|
||||
ClientID: "test-client",
|
||||
PacketID: 12345,
|
||||
Timestamp: 1640995200,
|
||||
}
|
||||
|
||||
data := []byte("test data")
|
||||
|
||||
packet := TaggedUDPPacket{
|
||||
Header: header,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
if packet.Header.ClientID != "test-client" {
|
||||
t.Errorf("Expected ClientID 'test-client', got '%s'", packet.Header.ClientID)
|
||||
}
|
||||
|
||||
if len(packet.Data) != len(data) {
|
||||
t.Errorf("Expected data length %d, got %d", len(data), len(packet.Data))
|
||||
}
|
||||
|
||||
for i, b := range data {
|
||||
if packet.Data[i] != b {
|
||||
t.Errorf("Data mismatch at position %d", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUDPRequest(t *testing.T) {
|
||||
addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:8080")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to resolve UDP address: %v", err)
|
||||
}
|
||||
|
||||
data := []byte("test data")
|
||||
|
||||
req := UDPRequest{
|
||||
LocalPort: 8080,
|
||||
RemotePort: 80,
|
||||
Protocol: "udp",
|
||||
Data: data,
|
||||
ClientAddr: addr,
|
||||
}
|
||||
|
||||
if req.LocalPort != 8080 {
|
||||
t.Errorf("Expected LocalPort 8080, got %d", req.LocalPort)
|
||||
}
|
||||
|
||||
if req.RemotePort != 80 {
|
||||
t.Errorf("Expected RemotePort 80, got %d", req.RemotePort)
|
||||
}
|
||||
|
||||
if req.Protocol != "udp" {
|
||||
t.Errorf("Expected Protocol 'udp', got '%s'", req.Protocol)
|
||||
}
|
||||
|
||||
if len(req.Data) != len(data) {
|
||||
t.Errorf("Expected data length %d, got %d", len(data), len(req.Data))
|
||||
}
|
||||
|
||||
if req.ClientAddr.String() != "127.0.0.1:8080" {
|
||||
t.Errorf("Expected ClientAddr '127.0.0.1:8080', got '%s'", req.ClientAddr.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user